def emit(self,*args,**kwargs): backend = kwargs.pop('backend',None) or None if backend: return subscription.get_backends()[backend] for backend_module in subscription.get_backends().values(): backend_module(*args,**kwargs)
def emit(self, *args, **kwargs): backend = kwargs.pop("backend", None) or None notification_cls = kwargs.pop("notification_cls", None) or None backends = subscription.get_backends().values() if backend: backend_module = subscription.get_backends()[backend]() backends = [backend_module] for backend in backends: if notification_cls: notification_cls()(backend, *args, **kwargs) continue backend.emit(*args, **kwargs)
def push(request): queue = request.GET['queue'] b = subscription.get_backends()['site']() b.push_state(request.user, NOTIFICATION_STATES[1], queue) return http.HttpResponse('OK')
def subscription_yourlabs_dropdown(request, dropdown, states, count, limit=15): if not request.user.is_authenticated(): return {} b = subscription.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, }
def dropdown_more(request, push_states=None, backend='storage', template_name='subscription/list.html', extra_context=None): if push_states is None: push_states = {} queues = request.GET.getlist('q') b = subscription.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)
def json(request, queue_limit=15): if not request.user.is_authenticated(): return http.HttpResponseForbidden() b = subscription.get_backends()['site']() notification_list = b.get_last_notifications(request.user, queue_limit=queue_limit, minimal=True, reverse=True) return http.HttpResponse(simplejson.dumps(notification_list))
def dropdown_open(request, push_states=None, backend='storage'): dropdown = request.GET['dropdown'] b = subscription.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')
def subscription_yourlabs_widget(request, queue_limit=15): if not request.user.is_authenticated(): return {} b = subscription.get_backends()['site']() notification_list = b.get_last_notifications(request.user, states=NOTIFICATION_STATES, queue_limit=queue_limit) return { 'notification_list': notification_list, 'queue_limit': queue_limit, }
def list(request, template_name='subscription/examples/yourlabs/list.html', extra_context=None): b = subscription.get_backends()['site']() notification_list = b.get_all_notifications(request.user) context = { 'notification_list': notification_list, 'today': datetime.date.today() } context.update(extra_context or {}) return shortcuts.render(request, template_name, context)
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 subscription.get_backends().values(): backend_module().emit(self, queues)
def dropdown_ajax(request, dropdowns=None, states=None, counter_state=None, new_state=None, push_states=None, limit=15, backend='storage', template_name='subscription/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 = subscription.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')
def list(request, keys=None, states=None, push_states=None, backend='storage', extra_context=None, template_name='subscription/list.html'): if not request.user.is_authenticated(): return http.HttpResponseForbidden() b = subscription.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)