Wiki is working quit well

This commit is contained in:
Skia 2015-11-23 17:32:31 +01:00
parent d2005ff997
commit 8753e020a1
3 changed files with 18 additions and 26 deletions

View File

@ -2,10 +2,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import migrations, models from django.db import migrations, models
import django.contrib.auth.models
import django.db.models.deletion import django.db.models.deletion
import django.utils.timezone import django.contrib.auth.models
import django.core.validators import django.core.validators
import django.utils.timezone
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -18,21 +18,21 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='User', name='User',
fields=[ fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('password', models.CharField(verbose_name='password', max_length=128)), ('password', models.CharField(verbose_name='password', max_length=128)),
('last_login', models.DateTimeField(blank=True, verbose_name='last login', null=True)), ('last_login', models.DateTimeField(verbose_name='last login', blank=True, null=True)),
('is_superuser', models.BooleanField(verbose_name='superuser status', help_text='Designates that this user has all permissions without explicitly assigning them.', default=False)), ('is_superuser', models.BooleanField(verbose_name='superuser status', help_text='Designates that this user has all permissions without explicitly assigning them.', default=False)),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, max_length=254, verbose_name='username', validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.')], unique=True, help_text='Required. 254 characters or fewer. Letters, digits and @/./+/-/_ only.')), ('username', models.CharField(help_text='Required. 254 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, verbose_name='username', error_messages={'unique': 'A user with that username already exists.'}, validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username. This value may contain only letters, numbers and @/./+/-/_ characters.')], max_length=254)),
('first_name', models.CharField(verbose_name='first name', max_length=30)), ('first_name', models.CharField(verbose_name='first name', max_length=30)),
('last_name', models.CharField(verbose_name='last name', max_length=30)), ('last_name', models.CharField(verbose_name='last name', max_length=30)),
('email', models.EmailField(verbose_name='email address', unique=True, max_length=254)), ('email', models.EmailField(verbose_name='email address', max_length=254, unique=True)),
('date_of_birth', models.DateTimeField(verbose_name='date of birth')), ('date_of_birth', models.DateTimeField(verbose_name='date of birth')),
('nick_name', models.CharField(blank=True, max_length=30)), ('nick_name', models.CharField(blank=True, max_length=30)),
('is_staff', models.BooleanField(verbose_name='staff status', help_text='Designates whether the user can log into this admin site.', default=False)), ('is_staff', models.BooleanField(verbose_name='staff status', help_text='Designates whether the user can log into this admin site.', default=False)),
('is_active', models.BooleanField(verbose_name='active', help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', default=True)), ('is_active', models.BooleanField(verbose_name='active', help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', default=True)),
('date_joined', models.DateTimeField(verbose_name='date joined', default=django.utils.timezone.now)), ('date_joined', models.DateTimeField(verbose_name='date joined', default=django.utils.timezone.now)),
('groups', models.ManyToManyField(related_name='user_set', to='auth.Group', blank=True, verbose_name='groups', related_query_name='user', help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.')), ('groups', models.ManyToManyField(related_name='user_set', related_query_name='user', help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', verbose_name='groups', blank=True, to='auth.Group')),
('user_permissions', models.ManyToManyField(related_name='user_set', to='auth.Permission', blank=True, verbose_name='user permissions', related_query_name='user', help_text='Specific permissions for this user.')), ('user_permissions', models.ManyToManyField(related_name='user_set', related_query_name='user', help_text='Specific permissions for this user.', verbose_name='user permissions', blank=True, to='auth.Permission')),
], ],
options={ options={
'verbose_name': 'user', 'verbose_name': 'user',
@ -45,13 +45,13 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='Page', name='Page',
fields=[ fields=[
('full_name', models.CharField(serialize=False, verbose_name='page full name', primary_key=True, max_length=30)), ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('name', models.CharField(verbose_name='page name', max_length=30)), ('name', models.CharField(verbose_name='page name', max_length=30)),
('title', models.CharField(blank=True, verbose_name='page title', max_length=255)), ('title', models.CharField(verbose_name='page title', blank=True, max_length=255)),
('content', models.TextField(blank=True, verbose_name='page content')), ('content', models.TextField(verbose_name='page content', blank=True)),
('revision', models.PositiveIntegerField(verbose_name='current revision', default=1)), ('revision', models.PositiveIntegerField(verbose_name='current revision', default=1)),
('is_locked', models.BooleanField(verbose_name='page mutex', default=False)), ('is_locked', models.BooleanField(verbose_name='page mutex', default=False)),
('parent', models.ForeignKey(related_name='children', blank=True, null=True, to='core.Page', on_delete=django.db.models.deletion.SET_NULL)), ('parent', models.ForeignKey(related_name='children', to='core.Page', blank=True, on_delete=django.db.models.deletion.SET_NULL, null=True)),
], ],
options={ options={
'permissions': (('can_edit', 'Can edit the page'), ('can_view', 'Can view the page')), 'permissions': (('can_edit', 'Can edit the page'), ('can_view', 'Can view the page')),

View File

@ -109,7 +109,6 @@ class User(AbstractBaseUser, PermissionsMixin):
class Page(models.Model): class Page(models.Model):
full_name = models.CharField(_('page full name'), max_length=30, blank=False, primary_key=True)
name = models.CharField(_('page name'), max_length=30, blank=False) name = models.CharField(_('page name'), max_length=30, blank=False)
title = models.CharField(_("page title"), max_length=255, blank=True) title = models.CharField(_("page title"), max_length=255, blank=True)
content = models.TextField(_("page content"), blank=True) content = models.TextField(_("page content"), blank=True)
@ -147,18 +146,7 @@ class Page(models.Model):
""" """
if '/' in self.name: if '/' in self.name:
self.name = self.name.split('/')[-1] self.name = self.name.split('/')[-1]
if self.full_name is None or self.full_name == "":
if self.parent is None:
self.full_name = self.name
else:
self.full_name = self.parent.get_full_name()+'/'+self.name
self.full_name.strip('/')
if self.full_name.split('/')[-1] != self.name:
self.full_name = '/'.join(['/'.join(self.full_name.split('/')[:-1]), self.name])
#if Page.objects.filter(name=self.name, parent=self.parent).exists():
# raise ValidationError("Duplicate Page")
super(Page, self).clean() super(Page, self).clean()
print("fullname: "+self.full_name)
print("name: "+self.name) print("name: "+self.name)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
@ -169,8 +157,10 @@ class Page(models.Model):
return self.get_full_name() return self.get_full_name()
def get_full_name(self): def get_full_name(self):
return self.full_name if self.parent is None:
return self.name
return '/'.join([self.parent.get_full_name(), self.name])
def get_display_name(self): def get_display_name(self):
return self.full_name return self.get_full_name()

View File

@ -108,6 +108,8 @@ def page_edit(request, page_name=None):
'page_name': page_name} 'page_name': page_name}
p = Page.get_page_by_full_name(page_name) p = Page.get_page_by_full_name(page_name)
if p == None: if p == None:
# TODO: guess page name by splitting on '/'
# Same for the parent, try to guess
p = Page(name=page_name) p = Page(name=page_name)
if request.method == 'POST': if request.method == 'POST':
f = PageForm(request.POST, instance=p) f = PageForm(request.POST, instance=p)