freehg / accountviews.py

from freehg.repos.models import Repo
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django import forms

@login_required
def profile(request):
    user = request.user
    if request.method == 'POST':
        form = ChangeProfileForm(request.POST)
        if form.is_valid():
            form.update_user(user)
            user.save()
            user.message_set.create(message="Profile updated.")
            return HttpResponseRedirect("/accounts/profile/")
    else:
        form = ChangeProfileForm(dict(
                first_name=user.first_name,
                last_name=user.last_name,
                email=user.email))
    disk_usage = Repo.objects.get_user_disk_usage(user)
    return render_to_response('profile.html',
            dict(form=form, disk_usage=disk_usage),
            context_instance=RequestContext(request))



class ChangeProfileForm(forms.Form):
    first_name = forms.CharField(max_length=30, required=False)
    last_name = forms.CharField(max_length=30, required=False)
    email = forms.EmailField(required=False)

    def update_user(self, user):
        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']
        user.email = self.cleaned_data['email']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.