示例#1
0
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
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
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
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
    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
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
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)