From 41ee7b0c99067693097c9ebf467f668337e79692 Mon Sep 17 00:00:00 2001 From: Saxon Douglass Date: Wed, 4 Dec 2013 12:33:37 +1030 Subject: [PATCH] Added Profile model one-to-one with User --- accounts/admin.py | 16 ++++++++++++++++ accounts/models.py | 21 +++++++++++++++++++++ accounts/urls.py | 10 +++++----- jamalaide/urls.py | 4 ++-- templates/about.html | 11 ----------- templates/accounts/login.html | 2 +- templates/accounts/profile.html | 2 +- templates/base.html | 6 +++--- 8 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 accounts/admin.py create mode 100644 accounts/models.py delete mode 100644 templates/about.html diff --git a/accounts/admin.py b/accounts/admin.py new file mode 100644 index 0000000..306915a --- /dev/null +++ b/accounts/admin.py @@ -0,0 +1,16 @@ +from django.contrib import admin +from django.contrib.auth.admin import UserAdmin +from django.contrib.auth.models import User + +from accounts.models import Profile + +class ProfileInline(admin.TabularInline): + model = Profile + can_delete = False + verbose_name_plural = 'profile' + +class UserAdmin(admin.ModelAdmin): + inlines = (ProfileInline, ) + +admin.site.unregister(User) +admin.site.register(User, UserAdmin) diff --git a/accounts/models.py b/accounts/models.py new file mode 100644 index 0000000..8f02aca --- /dev/null +++ b/accounts/models.py @@ -0,0 +1,21 @@ +from django.conf import settings +from django.contrib.auth.models import User +from django.db import models +from django.db.models.signals import post_save +from django.dispatch import receiver + +class Profile(models.Model): + user = models.OneToOneField(settings.AUTH_USER_MODEL) + bio = models.TextField(blank=True) + def __unicode__(self): + return self.user.get_full_name() + +# Signal handlers +@receiver(post_save, sender=User) +def user_post_save_callback(sender, **kwargs): + created = kwargs['created'] + instance = kwargs['instance'] + if created: + profile = Profile(); + profile.user = instance + profile.save() diff --git a/accounts/urls.py b/accounts/urls.py index 664f55b..c37b503 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -3,9 +3,9 @@ from accounts.views import * urlpatterns = patterns('', - url(r'^profile/?$', profile, {}, "accounts-profile"), - (r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.html'}, "accounts-login"), - (r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.html'}, "accounts-logout"), - (r'^change-password/$', 'django.contrib.auth.views.password_change', {'template_name': 'accounts/password-change.html'}, "accounts-password-change"), - (r'^password-changed/$', 'django.contrib.auth.views.password_change_done', {'template_name': 'accounts/password-change-done.html'}, "accounts-password-change-done"), + url(r'^profile/?$', profile, {}, "profile"), + (r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.html'}, "login"), + (r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.html'}, "logout"), + (r'^password-change/$', 'django.contrib.auth.views.password_change', {'template_name': 'accounts/password-change.html'}, "password_change"), + (r'^password-change-done/$', 'django.contrib.auth.views.password_change_done', {'template_name': 'accounts/password-change-done.html'}, "password_change_done"), ) diff --git a/jamalaide/urls.py b/jamalaide/urls.py index e2278d8..c9e154c 100644 --- a/jamalaide/urls.py +++ b/jamalaide/urls.py @@ -5,14 +5,14 @@ admin.autodiscover() urlpatterns = patterns('', + url(r'^$', include('news.urls')), + url(r'^accounts/', include('accounts.urls')), url(r'^jams/', include('jams.urls')), url(r'^games/?$', 'jams.views.games'), url(r'^admin/', include(admin.site.urls)), url(r'^media/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, }), - url(r'^$', include('news.urls')), - url(r'^accounts/', include('accounts.urls')), ) # Flatpages diff --git a/templates/about.html b/templates/about.html deleted file mode 100644 index 866ff6f..0000000 --- a/templates/about.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends "base.html" %} - -{% block title %}About{% endblock %} - -{% block content %} -

About

-

Jamalaide is a club at the University of Adelaide that aims to increase interest and activity in game design and - development by running game jams and other social events.

-

From this we hope to foster Adelaide's indie games development community and encourage students to become engaged in - extra-curricula creative design activities.

-{% endblock %} diff --git a/templates/accounts/login.html b/templates/accounts/login.html index a2c39ea..17254f0 100644 --- a/templates/accounts/login.html +++ b/templates/accounts/login.html @@ -4,7 +4,7 @@ {{ form.non_field_errors }} -
+ {% csrf_token %}
{{ form.username.label_tag }}
diff --git a/templates/accounts/profile.html b/templates/accounts/profile.html index 773846c..cf8e9f9 100644 --- a/templates/accounts/profile.html +++ b/templates/accounts/profile.html @@ -4,6 +4,6 @@

Profile

-Would you like to change your password? +Would you like to change your password? {% endblock %} diff --git a/templates/base.html b/templates/base.html index 4a57ac0..c1e1c53 100644 --- a/templates/base.html +++ b/templates/base.html @@ -14,10 +14,10 @@
{% if user.is_authenticated %}

Welcome, {{ user.username }}.
- Profile - - Logout

+ Profile - + Logout

{% else %} -

Login

+

Login

{% endif %}