Ticket #1132: current_user_field_patch.diff
File current_user_field_patch.diff, 3.5 KB (added by , 19 years ago) |
---|
-
django/contrib/admin/views/main.py
405 405 manipulator.do_html2python(new_data) 406 406 407 407 if not errors and not request.POST.has_key("_preview"): 408 new_object = manipulator.save(new_data )408 new_object = manipulator.save(new_data, current_user=request.user.id) 409 409 log_add_message(request.user, opts,manipulator,new_object) 410 410 msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name':opts.verbose_name, 'obj':new_object} 411 411 pk_value = getattr(new_object,opts.pk.attname) … … 484 484 485 485 manipulator.do_html2python(new_data) 486 486 if not errors and not request.POST.has_key("_preview"): 487 new_object = manipulator.save(new_data )487 new_object = manipulator.save(new_data, current_user=request.user.id) 488 488 log_change_message(request.user,opts,manipulator,new_object) 489 489 msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': opts.verbose_name, 'obj':new_object} 490 490 pk_value = getattr(new_object,opts.pk.attname) -
django/core/meta/fields.py
741 741 return {self.attname: choice_list[1][0]} 742 742 return Field.flatten_data(self, follow, obj) 743 743 744 class CurrentUserField(ForeignKey): 745 def __init__(self, to=None, update_on_edit=True, **kwargs): 746 self.update_on_edit = update_on_edit 747 if to is None: 748 from django.models.auth.users import User 749 to = User 750 # TODO: should these be overridable? I can't think of a reason why 751 # it would be necessary to do so. 752 kwargs['blank'] = True 753 kwargs['null'] = True 754 kwargs['editable'] = False 755 ForeignKey.__init__(self, to, **kwargs) 756 744 757 class ManyToManyField(Field): 745 758 def __init__(self, to, **kwargs): 746 759 kwargs['verbose_name'] = kwargs.get('verbose_name', to._meta.verbose_name_plural) -
django/core/meta/__init__.py
1750 1750 if change and opts.get_ordered_objects(): 1751 1751 self.fields.append(formfields.CommaSeparatedIntegerField(field_name="order_")) 1752 1752 1753 def manipulator_save(opts, klass, add, change, self, new_data ):1753 def manipulator_save(opts, klass, add, change, self, new_data, current_user=None): 1754 1754 # TODO: big cleanup when core fields go -> use recursive manipulators. 1755 1755 from django.utils.datastructures import DotExpandedDict 1756 1756 params = {} … … 1759 1759 auto_now_add = change and getattr(f, 'auto_now_add', False) 1760 1760 if self.follow.get(f.name, None) and not auto_now_add: 1761 1761 param = f.get_manipulator_new_data(new_data) 1762 # CurrentUserFields need to be set to the current user 1763 elif isinstance(f, CurrentUserField): 1764 # Only update this field if f.update_on_edit is True or we are in add_stage. 1765 if f.update_on_edit or add: 1766 param = current_user 1767 else: 1768 param = getattr(self.original_object, f.attname) 1762 1769 else: 1763 1770 if change: 1764 1771 param = getattr(self.original_object, f.attname)