Esempio n. 1
0
    def form_valid(self, *args, **kwargs):
        # let the processing happen
        print self.object.pk
        created = self.object.pk == None
        rslt = super(AuditedModelFormMixin,self).form_valid(*args,**kwargs)

        # get the object id
        instance = self.object
        info = {
            'instance':instance.__repr__(),
        }

        if not self.request.user.is_anonymous(): 
            info['user_pk']= self.request.user.id
            info['username']= self.request.user.username

        info['updated_fields'] = instance.get_dirty_fields()


        # save the audit
        seria = simplejson.dumps(info, cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=4)
        log = AuditLog(content_object=instance, log=seria)
        log.save()

        return rslt
Esempio n. 2
0
def post_delete_receiver(sender, **kwargs):
    instance = kwargs["instance"]

    info = {"instance": instance.__repr__(), "action": "delete"}

    user = get_request_user()
    if user:
        info["user_pk"] = user.id
        info["username"] = user.username

    seria = simplejson.dumps(info, cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=4)
    log = AuditLog(content_object=instance, log=seria)
    log.save()
Esempio n. 3
0
def post_save_receiver(sender, **kwargs):
    instance = kwargs["instance"]
    print

    info = {"instance": instance.__repr__()}

    user = get_request_user()
    if user:
        info["user_pk"] = user.id
        info["username"] = user.username

    if kwargs["created"]:
        info["action"] = "create"
        info["fields"] = instance.get_dirty_fields()
    else:
        info["action"] = "edit"
        info["updated_fields"] = instance.get_dirty_fields()

    seria = simplejson.dumps(info, cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=4)
    log = AuditLog(content_object=instance, log=seria)
    log.save()