diff --git a/core/migrations/0002_auto_20151119_1533.py b/core/migrations/0002_auto_20151119_1533.py new file mode 100644 index 00000000..ce1396bb --- /dev/null +++ b/core/migrations/0002_auto_20151119_1533.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Page', + fields=[ + ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), + ('name', models.CharField(max_length=30, verbose_name='page name')), + ('full_name', models.CharField(max_length=255, verbose_name='full name')), + ('content', models.TextField(blank=True, verbose_name='page content')), + ('revision', models.PositiveIntegerField(default=1, verbose_name='current revision')), + ('is_locked', models.BooleanField(default=False, verbose_name='page mutex')), + ], + options={ + 'permissions': (('can_edit', 'Can edit the page'), ('can_view', 'Can view the page')), + }, + ), + migrations.AlterField( + model_name='user', + name='date_of_birth', + field=models.DateTimeField(default='1970-01-01T00:00:00+01:00', verbose_name='date of birth'), + ), + ] diff --git a/core/models.py b/core/models.py index 9a1e5d0f..ae40e1df 100644 --- a/core/models.py +++ b/core/models.py @@ -105,7 +105,19 @@ class User(AbstractBaseUser, PermissionsMixin): self.username = user_name return user_name -class Page: - pass +class Page(models.Model): + name = models.CharField(_('page name'), max_length=30, blank=False) + full_name = models.CharField(_("full name"), max_length=255, blank=False) + content = models.TextField(_("page content"), blank=True) + revision = models.PositiveIntegerField(_("current revision"), default=1) + is_locked = models.BooleanField(_("page mutex"), default=False) + class Meta: + permissions = ( + ("can_edit", "Can edit the page"), + ("can_view", "Can view the page"), + ) + + def __str__(self): + return self.full_name diff --git a/core/templates/core/base.html b/core/templates/core/base.html index f0213010..e763dc8d 100644 --- a/core/templates/core/base.html +++ b/core/templates/core/base.html @@ -8,11 +8,12 @@
{% block header %} - {% if user %}Hello, {{ user.username }}!{% endif %} + {% if user.is_authenticated %}Hello, {{ user.username }}!{% endif %} {% endblock %}
diff --git a/core/templates/core/edit_user.html b/core/templates/core/edit_user.html new file mode 100644 index 00000000..99790740 --- /dev/null +++ b/core/templates/core/edit_user.html @@ -0,0 +1,15 @@ +{% extends "core/base.html" %} + +{% block title %} +{% if profile %} +Edit {{ profile.get_display_name }} +{% endif %} +{% endblock %} + +{% block content %} +{% if profile %} +

Edit user

+

Back to profile

+

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

+{% endif %} +{% endblock %} diff --git a/core/templates/core/user.html b/core/templates/core/user.html index 60ac7c8e..b808b2c4 100644 --- a/core/templates/core/user.html +++ b/core/templates/core/user.html @@ -13,6 +13,9 @@ User list {% if profile %}

User Profile

Back to list

+{% if user.is_superuser or user.id == profile.id %} +

Edit

+{% endif %}

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

{% endif %} diff --git a/core/views.py b/core/views.py index efca786f..26a14947 100644 --- a/core/views.py +++ b/core/views.py @@ -40,6 +40,11 @@ def register(request): return render(request, "core/register.html", context) def login(request): + """ + The login view + + Needs to be improve with correct handling of form exceptions + """ context = {'title': 'Login'} if request.method == 'POST': try: @@ -57,15 +62,27 @@ def login(request): return render(request, "core/login.html", context) def logout(request): + """ + The logout view:w + """ auth_logout(request) return redirect('core:index') def user(request, user_id=None): + context = {'title': 'View a user'} 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}) + context['user_list'] = User.objects.all + return render(request, "core/user.html", context) + context['profile'] = get_object_or_404(User, pk=user_id) + return render(request, "core/user.html", context) -def user_edit(request, user_id): - pass +def user_edit(request, user_id=None): + user_id = int(user_id) + context = {'title': 'Edit a user'} + if user_id is not None: + user_id = int(user_id) + if request.user.is_authenticated() and (request.user.pk == user_id or request.user.is_superuser): + context['profile'] = get_object_or_404(User, pk=user_id) + return render(request, "core/edit_user.html", context) + return user(request, user_id)