# Path: phylocommons/forms.py
# class ProfileForm(forms.ModelForm):
#     def __init__(self, *args, **kwargs):
#         super(ProfileForm, self).__init__(*args, **kwargs)
#         try:
#             self.fields['email'].initial = self.instance.user.email
#             # self.fields['first_name'].initial = self.instance.user.first_name
#             # self.fields['last_name'].initial = self.instance.user.last_name
#         except User.DoesNotExist:
#             pass
#  
#     email = forms.EmailField(label="E-mail (not shown)", help_text='')
#  
#     class Meta:
#       model = UserProfile
#       exclude = ('user',)
#  
#     def save(self, *args, **kwargs):
#         """
#         Update the primary email address on the related User object as well.
#         """
#         u = self.instance.user
#         u.email = self.cleaned_data['email']
#         u.save()
#         profile = super(ProfileForm, self).save(*args,**kwargs)
#         return profile


from django.conf.urls import patterns, include, url
from phylocommons.forms import ProfileForm
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'phylocommons.views.home', name='home'),
    
    url(r'^contributors/$', 'phylocommons.views.contributors', name='contributors'),
    url(r'^contact/$', 'phylocommons.views.contact', name='contact'),
    url(r'^help/$', 'phylocommons.views.help', name='help'),
    
    # accounts
    url(r'^accounts/', include('registration.urls')),
    
    # profiles
    url(r'^user/edit', 'profiles.views.edit_profile', 
        {

# Path: phylocommons/forms.py
# class ProfileForm(forms.ModelForm):
#     def __init__(self, *args, **kwargs):
#         super(ProfileForm, self).__init__(*args, **kwargs)
#         try:
#             self.fields['email'].initial = self.instance.user.email
#             # self.fields['first_name'].initial = self.instance.user.first_name
#             # self.fields['last_name'].initial = self.instance.user.last_name
#         except User.DoesNotExist:
#             pass
#  
#     email = forms.EmailField(label="E-mail (not shown)", help_text='')
#  
#     class Meta:
#       model = UserProfile
#       exclude = ('user',)
#  
#     def save(self, *args, **kwargs):
#         """
#         Update the primary email address on the related User object as well.
#         """
#         u = self.instance.user
#         u.email = self.cleaned_data['email']
#         u.save()
#         profile = super(ProfileForm, self).save(*args,**kwargs)
#         return profile


# Path: phylocommons/urls.py
from django.conf.urls import patterns, include, url
from phylocommons.forms import ProfileForm
from django.contrib import admin


admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'phylocommons.views.home', name='home'),
    
    url(r'^contributors/$', 'phylocommons.views.contributors', name='contributors'),
    url(r'^contact/$', 'phylocommons.views.contact', name='contact'),
    url(r'^help/$', 'phylocommons.views.help', name='help'),
    
    # accounts
    url(r'^accounts/', include('registration.urls')),
    
    # profiles
    url(r'^user/edit', 'profiles.views.edit_profile', 
        {

         'form_class': ProfileForm,