notify admin what fields have changed in form submission

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
updated_fields = []
changed_fields = form.changed_data
for field_name, field in form.fields.items():
    space = 30 - len(field.label)
    if field_name in changed_fields:
        updated_fields.append("**%s: %s".rjust(space,' ') % (field.label, form.cleaned_data[field_name]))
    else:
        updated_fields.append("%s: %s".rjust(space,' ') % (field.label, form.cleaned_data[field_name]))

# save the updated data
form.save()

# send an email to admin
subject  = "Partner updated profile information"
message  = "Partner: " + partner.__unicode__() + " "
message += "modified information in their profile.\n\n"
message += "Here is the current information (** = changed):\n\n"

for line in updated_fields:
    message += line + '\n'

mail_managers(subject, message)

# message user
request.user.message_set.create(message="Your Profile information has been updated.")

# go back to home page
return HttpResponseRedirect('/reports')

More like this

  1. User post_save signal to auto create 'admin' profile by marinho 6 years, 4 months ago
  2. Custom admin widgets by field type by dgouldin 5 years, 1 month ago
  3. change a widget attribute in ModelForm without define the field by jedie 5 years, 9 months ago
  4. Combine ProfileForm an UserForm in one. by sarg 3 years, 10 months ago
  5. Selectively change fields, widgets or labels in forms created from models by danjak 7 years, 1 month ago

Comments

(Forgotten your password?)