def send_event(actor, type, path, **context): """ Log an event performed by actor, of the type, on the path, and any other context arguments needed to render notification templates. """ # Todo, make sure notifications aren't sent too quickly one after another. if isinstance(path, models.Model): object = path path = model_sig(path) else: object = get_instance_from_sig(path) # Build a context to render templates context = context.copy() context['actor'] = actor context['path'] = path context['type'] = type context['object'] = object context['settings'] = settings context['DOMAIN'] = settings.DOMAIN # Find users to be notified subscriptions = Subscription.objects.filter(path=path, toggle=True) users = set([s.user for s in subscriptions]) users.discard( actor ) logger.info("Event: %s %s %s", actor, type, path) # Create the event, yo e = Event( actor = actor, type = type, path = path ) streams = set([actor]) # Trigger event signal # Receivers are expected to alter notify or context. for reciever, response in event.send(sender=e, notify=users, streams=streams, **context): if isinstance(response, dict): context.update(response) e.save() for stream in streams: e.add_to_stream(stream) # Notify all the ya'lls messages = [] for user in users: notice = Notice.objects.create(user=user) notice.events = [e] try: msg = render_mail(user.email, type, context) messages.append(msg) except Exception, x: print "Error sending email:", x
def redirect(request, path): """ Redirects to the object found on the path. """ if (path.startswith('url:')): return HttpResponseRedirect(path[4:]) instance = get_instance_from_sig(path) if not instance: raise Http404 return HttpResponseRedirect(instance.get_absolute_url())
def property(request, path): """ Updates the property on an object given the path. """ property = request.POST['property'] value = request.POST['value'] instance = get_instance_from_sig(path) if not instance: raise Http404 setattr(instance, property, value) instance.save() return HttpResponse(json.dumps( getattr(instance, property, value) ), content_type="application/json")