def profile(request,page): page = string.lower(page) user = request.user form = None points_logs = user.pointstransaction_set.order_by("-submission_date").all() if request.method == "POST": user = request.user form = ProfileForm(request.POST) if form.is_valid(): profile = user.get_profile() profile.name = form.cleaned_data["display_name"].strip() profile.contact_email = form.cleaned_data["contact_email"] profile.contact_text = form.cleaned_data["contact_text"] profile.contact_carrier = form.cleaned_data["contact_carrier"] # profile.enable_help = form.cleaned_data["enable_help"] try: profile.save() form.message = "Your changes have been saved" except IntegrityError: form.message = "Please correct the errors below." form.errors.update({"display_name": "'%s' is taken, please enter another name." % profile.name}) else: form.message = "Please correct the errors below." # If this is a new request, initialize the form. if not form: form = ProfileForm(initial={ "enable_help": user.get_profile().enable_help, "display_name": user.get_profile().name, "contact_email": user.get_profile().contact_email or user.email, "contact_text": user.get_profile().contact_text, "contact_carrier": user.get_profile().contact_carrier, }) return render_to_response("mobile/profile/"+page+".html", { "profile": user.get_profile(), "user": user, "form": form, "points_logs": points_logs, "in_progress_members": get_in_progress_members(user), "commitment_members": get_current_commitment_members(user), "completed_members": get_completed_members(user), "notifications": user.usernotification_set.order_by("-created_at"), "help_info": { "prefix": "profile_index", "count": range(0, 3), } }, context_instance=RequestContext(request))
def index(request): user = request.user form = None if request.method == "POST": user = request.user form = ProfileForm(request.POST, user=request.user) if form.is_valid(): profile = user.get_profile() name = form.cleaned_data["display_name"].strip() if name != profile.name: profile.name = name profile.contact_email = form.cleaned_data["contact_email"] profile.contact_text = form.cleaned_data["contact_text"] profile.contact_carrier = form.cleaned_data["contact_carrier"] # profile.enable_help = form.cleaned_data["enable_help"] profile.save() form.message = "Your changes have been saved" else: form.message = "Please correct the errors below." # If this is a new request, initialize the form. if not form: profile = user.get_profile() form = ProfileForm(initial={ # "enable_help": user.get_profile().enable_help, "display_name": profile.name, "contact_email": profile.contact_email or user.email, "contact_text": profile.contact_text, "contact_carrier": profile.contact_carrier, }) if request.GET.has_key("changed_avatar"): form.message = "Your avatar has been updated." points_logs = user.pointstransaction_set.order_by("-submission_date").all() return render_to_response("view_profile/index.html", { "form": form, "in_progress_members": get_in_progress_members(user), "commitment_members": get_current_commitment_members(user), "points_logs": points_logs, # "notifications": user.usernotification_set.order_by("-created_at"), }, context_instance=RequestContext(request))
def index(request): user = request.user form = None if request.method == "POST": user = request.user form = ProfileForm(request.POST) if form.is_valid(): profile = user.get_profile() profile.name = form.cleaned_data["display_name"] profile.contact_email = form.cleaned_data["contact_email"] profile.contact_text = form.cleaned_data["contact_text"] profile.contact_carrier = form.cleaned_data["contact_carrier"] # profile.enable_help = form.cleaned_data["enable_help"] profile.save() form.message = "Your changes have been saved" else: form.message = "Please correct the errors below." # If this is a new request, initialize the form. if not form: form = ProfileForm(initial={ "enable_help": user.get_profile().enable_help, "display_name": user.get_profile().name, "contact_email": user.get_profile().contact_email or user.email, "contact_text": user.get_profile().contact_text, "contact_carrier": user.get_profile().contact_carrier, }) if request.GET.has_key("changed_avatar"): form.message = "Your avatar has been updated." # Check for a rejected activity member. rejected_member = None if request.session.has_key("rejected_id"): rejected_member = ActivityMember.objects.get(id=request.session["rejected_id"]) del request.session["rejected_id"] return render_to_response("view_profile/index.html", { "form": form, "in_progress_members": get_in_progress_members(user), "completed_members": get_completed_members(user), "rejected_member": rejected_member, "notifications": user.usernotification_set.order_by("-created_at"), "help_info": { "prefix": "profile_index", "count": range(0, 3), } }, context_instance=RequestContext(request))