コード例 #1
0
ファイル: dropdown.py プロジェクト: jpic/django-social
def dropdown_more(request, push_states=None, backend=DEFAULT_BACKEND,
    template_name='social/list.html', 
    extra_context=None):
    
    if push_states is None:
        push_states = {}

    queues = request.GET.getlist('q')

    b = social.get_backends()[backend]()

    notifications = []
    for queue in queues:
        notifications += b.get_notifications(queue)

        for old_state, new_state in push_states.items():
            b.move_queue(queue, queue.replace(old_state, new_state))

    notifications = sorted(notifications, key=lambda n: n.timestamp)

    context = {
        'notification_list': notifications,
        'today': datetime.date.today()
    }

    context.update(extra_context or {})
    return shortcuts.render(request, template_name, context)
コード例 #2
0
ファイル: dropdown_tags.py プロジェクト: jpic/django-social
def social_dropdown(request, dropdown, states, count, limit=15):
    if not request.user.is_authenticated():
        return {}

    b = social.get_backends()['storage']()

    notifications = []
    queues = []
    for state in states.split(','):
        q = 'dropdown=%s,user=%s,%s' % (dropdown, request.user.pk, state)
        queues.append(q)
        notifications += b.get_notifications(q, limit-len(notifications))

    counter = 0
    for state in count.split(','):
        q = 'dropdown=%s,user=%s,%s' % (dropdown, request.user.pk, state)
        counter += b.count_notifications(q)
    
    return {
        'notifications': notifications,
        'counter': counter,
        'dropdown': dropdown,
        'request': request,
        'queues': queues,
    }
コード例 #3
0
ファイル: dropdown_tags.py プロジェクト: crass/django-social
def social_dropdown(request, dropdown, states, count, limit=15):
    if not request.user.is_authenticated():
        return {}

    b = social.get_backends()["storage"]()

    notifications = []
    queues = []
    for state in states.split(","):
        q = "dropdown=%s,user=%s,%s" % (dropdown, request.user.pk, state)
        queues.append(q)
        notifications += b.get_notifications(q, limit - len(notifications))

    counter = 0
    for state in count.split(","):
        q = "dropdown=%s,user=%s,%s" % (dropdown, request.user.pk, state)
        counter += b.count_notifications(q)

    return {
        "notifications": notifications,
        "counter": counter,
        "dropdown": dropdown,
        "request": request,
        "queues": queues,
    }
コード例 #4
0
ファイル: dropdown.py プロジェクト: jpic/django-social
def dropdown_open(request, push_states=None, backend='storage'):
    dropdown = request.GET['dropdown']
    b = social.get_backends()[backend]()

    for old_state, new_state in push_states.items():
        q = 'dropdown=%s,user=%s,%s' % (dropdown, request.user.pk, old_state)
        b.move_queue(q, q.replace(old_state, new_state))
    
    return http.HttpResponse('OK')
コード例 #5
0
ファイル: notification.py プロジェクト: jpic/django-social
    def emit(self, queues=None):
        """
        This is one of the most important methods. It is responsible for
        deciding what backends should it emit to and with what arguments - from
        meta data to subscribers whom should recieve the notification.

        If it should emit to multiqueue backends, then it's also responsible
        for deciding which queues it should emit to.
        """
        local_queues = getattr(self, 'queues', None)
        if queues is None and local_queues:
            queues = self.queues

        if queues:
            for backend_module in social.get_backends().values():
                backend_module().emit(self, queues)
コード例 #6
0
ファイル: dropdown.py プロジェクト: jpic/django-social
def dropdown_ajax(request, dropdowns=None, states=None, counter_state=None, 
    new_state=None, push_states=None, limit=15, backend=DEFAULT_BACKEND,
    template_name='social/dropdown.html'):

    if not request.user.is_authenticated():
        return http.HttpResponseForbidden()

    remote_counts = {}
    for k, v in request.GET.items():
        if k == 'x':
            continue
        remote_counts[k] = int(v)

    b = social.get_backends()[backend]()

    context = {}
    for dropdown in dropdowns:
        # would be better to do that after the count <= remote_counts check ..
        for old_state, new_state in push_states.items():
            q = 'dropdown=%s,user=%s,%s' % (dropdown, request.user.pk, old_state)
            b.move_queue(q, q.replace(old_state, new_state))

        q = 'dropdown=%s,user=%s,%s' % (dropdown, request.user.pk, counter_state)
        count = b.count_notifications(q)
        if dropdown not in remote_counts.keys():
            continue
        if count <= remote_counts[dropdown]:
            continue

        notifications = []
        queues = []
        for state in states:
            q = 'dropdown=%s,user=%s,%s' % (dropdown, request.user.pk, state)
            notifications += b.get_notifications(queue=q, 
                limit=limit-len(notifications))
            queues.append(q)

        context[dropdown] = template.loader.render_to_string(template_name, {
            'notifications': notifications,
            'counter': count,
            'dropdown': dropdown,
            'request': request,
            'queues': queues,
        })

    return http.HttpResponse(simplejson.dumps(context), mimetype='application/javascript')
コード例 #7
0
ファイル: notification.py プロジェクト: jpic/django-social
def list(request, keys=None, states=None, push_states=None,
    backend=DEFAULT_BACKEND, extra_context=None,
    template_name='social/list.html'):

    if not request.user.is_authenticated():
        return http.HttpResponseForbidden()

    b = social.get_backends()[backend]()
    context = {
        'today': datetime.date.today(),
    }
    notifications = context['notification_list'] = []
    for key in keys:
        for state in states:
            queue = '%s,user=%s,%s' % (key, request.user.pk, state)
            context['notification_list'] += b.get_notifications(queue)

        for old_state, new_state in push_states.items():
            b.move_queue(queue, queue.replace(old_state, new_state))

    notifications = sorted(notifications, key=lambda n: n.timestamp)

    context.update(extra_context or {})
    return shortcuts.render(request, template_name, context)