diff --git a/core/models.py b/core/models.py index 13f8005a..bf737d8d 100644 --- a/core/models.py +++ b/core/models.py @@ -74,6 +74,15 @@ class User(AbstractBaseUser, PermissionsMixin): "Returns the short name for the user." return self.first_name + def get_display_name(self): + """ + Returns the display name of the user. + A nickname if possible, otherwise, the full name + """ + if self.nick_name != "": + return self.nick_name + return self.get_full_name() + def email_user(self, subject, message, from_email=None, **kwargs): """ Sends an email to this User. diff --git a/core/templates/core/index.html b/core/templates/core/index.html index e5249eb1..639fc4a7 100644 --- a/core/templates/core/index.html +++ b/core/templates/core/index.html @@ -1 +1,7 @@ -{% extends "sith/base.html" %} +{% extends "core/base.html" %} + +{% block title %}{{ title }}{% endblock %} + +{% block content %} +Hello, world. You're at the core index. +{% endblock %} diff --git a/core/templates/core/user.html b/core/templates/core/user.html new file mode 100644 index 00000000..60ac7c8e --- /dev/null +++ b/core/templates/core/user.html @@ -0,0 +1,28 @@ +{% extends "core/base.html" %} + +{% block title %} +{% if profile %} + {{ profile.get_display_name }}'s profile +{% endif %} +{% if user_list %} +User list +{% endif %} +{% endblock %} + +{% block content %} +{% if profile %} +

User Profile

+

Back to list

+

You're seeing the profile of {{ profile.get_display_name }}

+{% endif %} + +{% if user_list %} +

User list

+ +{% endif %} +{% endblock %} + diff --git a/core/urls.py b/core/urls.py index 36856df9..ae5a2b7a 100644 --- a/core/urls.py +++ b/core/urls.py @@ -7,5 +7,8 @@ urlpatterns = [ url(r'^login$', views.login, name='login'), url(r'^logout$', views.logout, name='logout'), url(r'^register$', views.register, name='register'), + url(r'^user/$', views.user, name='user_list'), + url(r'^user/(?P[0-9]+)/$', views.user, name='user_profile'), + url(r'^user/(?P[0-9]+)/edit$', views.user_edit, name='user_edit'), ] diff --git a/core/views.py b/core/views.py index cc863ad9..85986675 100644 --- a/core/views.py +++ b/core/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render, redirect +from django.shortcuts import render, redirect, get_object_or_404 from django.http import HttpResponse from django.contrib.auth import logout as auth_logout @@ -10,7 +10,7 @@ import logging logging.basicConfig(level=logging.DEBUG) def index(request): - return HttpResponse("Hello, world. You're at the core index.") + return render(request, "core/index.html", {'title': 'Bienvenue!'}) def register(request): if request.method == 'POST': @@ -39,3 +39,13 @@ def login(request): def logout(request): auth_logout(request) return redirect('core:index') + +def user(request, user_id=None): + if user_id == None: + return render(request, "core/user.html", {'user_list': User.objects.all}) + user = get_object_or_404(User, pk=user_id) + return render(request, "core/user.html", {'profile': user}) + +def user_edit(request, user_id): + pass +