here is some working code from a site that maintains profile information (address, phone number, etc) for users ("Partners").
this snippet handles the submitted form (after validation) and checks to see if any fields have been changed by the partner. if so, it shoots off an email to the admin showing the current profile information with changed fields marked with asterisks.
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
- Stuff by NixonDash 1 month ago
- Add custom fields to the built-in Group model by jmoppel 3 months, 1 week ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 6 months, 3 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 7 months, 1 week ago
- Browser-native date input field by kytta 8 months, 3 weeks ago
Comments
Please login first before commenting.