Example #1
0
def group_update(request, group_id):
    """
    Update group method

    :param request: request
    :param group_id: group id
    :return: if you succeed, redirect groups page
    """
    if not Group.objects.filter(id=group_id).exists():
        latest_group_list = Group.objects.order_by('name')
        error = 'Does not exist group.'
        return render(request, 'archive/group/list.html', {'latest_group_list': latest_group_list, 'error': error})

    if tasks.update_group_feed.delay(group_id, get_feed_query(), True, True):
        return HttpResponseRedirect(reverse('archive:groups'))
Example #2
0
def group_comments_check(request, group_id):
    """
    Check group comments for super user

    :param request: request
    :param group_id: group id
    :return: if you succeed, redirect groups page
    """
    if not Group.objects.filter(id=group_id).exists():
        latest_group_list = Group.objects.order_by('name')
        error = 'Does not exist group.'
        return render(request, 'archive/group/list_admin.html',
                      {'latest_group_list': latest_group_list, 'error': error})

    tasks.check_group_comments.delay(group_id, get_feed_query(), settings.ARCHIVE_USE_CELERY, True)
    return HttpResponseRedirect(reverse('archive:groups_admin'))
Example #3
0
def groups(request):
    """
    Get a group list by HTTP GET Method and enter a group by HTTP POST METHOD

    :param request: request
    :return: render
    """
    if request.method == "GET":
        return render(request, 'archive/group/list.html', {})
    elif request.method == "POST":
        # Get a url and validate the url
        fb_url = request.POST.get("fb_url", None)
        if fb_url is None:
            error = 'Did not exist a url.'
            return JsonResponse({'error': error})

        # Get a group id from the url and validate the group id
        group_id = lookup_id(fb_url)
        if group_id is None:
            error = 'Did not exist the group or enroll the wrong url.'
            return JsonResponse({'error': error})

        # Get group data from graph api and validate the group data
        group_data = fb_request.group(group_id)
        if group_data is None:
            error = 'Did not exist group or privacy group.'
            return JsonResponse({'error': error})

        # Check the group exist
        if Group.objects.filter(id=group_data.get('id')).exists():
            error = 'This group is already exist.'
            return JsonResponse({'error': error})

        # Store the group
        _group = tasks.store_group(group_data)

        if settings.ARCHIVE_GROUP_AUTO_SAVE:
            tasks.store_group_feed.delay(_group.id, get_feed_query(), settings.ARCHIVE_USE_CELERY, True)

        return JsonResponse({'success': 'Success to enroll ' + _group.id})
Example #4
0
BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Seoul'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'

from datetime import timedelta
from archive.fb.fb_query import get_feed_query

CELERYBEAT_SCHEDULE = {
    'add-every-120-seconds': {
        'task': 'archive.tasks.update_groups_feed',
        'schedule': timedelta(seconds=120),
        'args': (get_feed_query(), True, True)
    },
}

####################
# LOGGING SETTINGS #
####################

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt': "%d/%b/%Y %H:%M:%S"
        },