Ejemplo n.º 1
0
def update_users(sender, instance, **kwargs):
    # if instance is not created, return
    #if instance.pk is not None:
    #    return
    registry = registration.FieldRegistry()
    if sender in registry:
        for field in registry.get_fields(sender):
            if instance.pk is None or field.editable:
                setattr(instance, field.name, get_current_user())
Ejemplo n.º 2
0
 def update_users(self, user, sender, instance, **kwargs):
     registry = registration.FieldRegistry()
     if sender in registry:
         for field in registry.get_fields(sender):
             # need to only set owner id if it hasn't already been set
             if instance.id and field.name == 'owner':
                 owner_id = sender.objects.get(id=instance.id).owner_id
                 if owner_id:
                     #pdb.set_trace()
                     instance.owner_id = owner_id
                 else:
                     setattr(instance, field.name, user)
             else:
                 setattr(instance, field.name, user)
Ejemplo n.º 3
0
 def contribute_to_class(self, cls, name):
     super(CurrentUserField, self).contribute_to_class(cls, name)
     registry = registration.FieldRegistry()
     registry.add_field(cls, self)