Commit ace66bba authored by Skia's avatar Skia

Almost working wiki before refactoring

parent e9c18748
...@@ -43,12 +43,21 @@ class LoginForm(AuthenticationForm): ...@@ -43,12 +43,21 @@ class LoginForm(AuthenticationForm):
) )
class PageForm(forms.ModelForm): class PageForm(forms.ModelForm):
#parent = forms.ModelChoiceField(queryset=Page.objects.all())
#def __init__(self, *args, **kwargs):
# super(PageForm, self).__init__(*args, **kwargs)
class Meta: class Meta:
model = Page model = Page
fields = ['name', 'title', 'content', ] fields = ['parent', 'name', 'title', 'content', ]
def save(self, commit=True): def save(self, commit=True):
page = super(PageForm, self).save(commit=False) page = super(PageForm, self).save(commit=False)
if self.cleaned_data['parent'] is not None:
page.full_name = '/'.join([self.cleaned_data['parent'].full_name, self.cleaned_data['name']])
else:
page.full_name = self.cleaned_data['name']
page.name = self.cleaned_data['name'].split('/')[-1]
if commit: if commit:
page.save() page.save()
return page return page
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0008_auto_20151122_1717'),
]
operations = [
migrations.RemoveField(
model_name='page',
name='id',
),
migrations.AlterField(
model_name='page',
name='name',
field=models.CharField(verbose_name='page name', max_length=30, serialize=False, primary_key=True),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0009_auto_20151123_0902'),
]
operations = [
migrations.RenameField(
model_name='page',
old_name='name',
new_name='full_name',
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0010_auto_20151123_0948'),
]
operations = [
migrations.AddField(
model_name='page',
name='name',
field=models.CharField(verbose_name='page name', default='guy', max_length=30),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0011_page_name'),
]
operations = [
migrations.RemoveField(
model_name='page',
name='children',
),
migrations.AddField(
model_name='page',
name='parent',
field=models.ForeignKey(null=True, related_name='children', to='core.Page'),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0012_auto_20151123_1002'),
]
operations = [
migrations.AlterField(
model_name='page',
name='full_name',
field=models.CharField(verbose_name='page full name', primary_key=True, serialize=False, max_length=30),
),
migrations.AlterField(
model_name='page',
name='parent',
field=models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, blank=True, to='core.Page', related_name='children', null=True),
),
]
...@@ -108,12 +108,13 @@ class User(AbstractBaseUser, PermissionsMixin): ...@@ -108,12 +108,13 @@ 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)
revision = models.PositiveIntegerField(_("current revision"), default=1) revision = models.PositiveIntegerField(_("current revision"), default=1)
is_locked = models.BooleanField(_("page mutex"), default=False) is_locked = models.BooleanField(_("page mutex"), default=False)
children = models.ForeignKey('self', related_name="parent", null=True) parent = models.ForeignKey('self', related_name="children", null=True, blank=True, on_delete=models.SET_NULL)
class Meta: class Meta:
permissions = ( permissions = (
...@@ -122,10 +123,8 @@ class Page(models.Model): ...@@ -122,10 +123,8 @@ class Page(models.Model):
) )
def __str__(self): def __str__(self):
return self.name return self.full_name
def get_display_name(self): def get_display_name(self):
return self.name return self.full_name
#def get(self, *args):
# return self.__dict__
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% if page %} {% if view_page %}
<h3>Page</h3> <h3>Page</h3>
<p><a href="{% url 'core:page_list' %}">Back to list</a></p> <p><a href="{% url 'core:page_list' %}">Back to list</a></p>
{% if user.is_superuser %} {% if user.is_superuser %}
<p><a href="{% url 'core:page_edit' page.name %}">Edit</a></p> <p><a href="{% url 'core:page_edit' page.full_name %}">Edit</a></p>
{% endif %} {% endif %}
<p>You're seeing the page <strong>{{ page.get_display_name }}</strong></p> <p>You're seeing the page <strong>{{ page.get_display_name }}</strong></p>
<h3>{{ page.title }}</h3> <h3>{{ page.title }}</h3>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<h3>Page list</h3> <h3>Page list</h3>
<ul> <ul>
{% for p in page_list %} {% for p in page_list %}
<li><a href="{% url 'core:page' p.name %}">{{ p.get_display_name }}</a></li> <li><a href="{% url 'core:page' p.full_name %}">{{ p.get_display_name }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% elif new_page %} {% elif new_page %}
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<p><a href="{% url 'core:page_edit' new_page %}">Create it?</a></p> <p><a href="{% url 'core:page_edit' new_page %}">Create it?</a></p>
{% elif page_form %} {% elif page_form %}
<h2>Edit page</h2> <h2>Edit page</h2>
<form action="{% url 'core:page_edit' page_name=page_name %}" method="post"> <form action="{% url 'core:page_edit' page_name=page.full_name %}" method="post">
{% csrf_token %} {% csrf_token %}
{{ page_form }} {{ page_form }}
<p><input type="submit" value="Save!" /></p> <p><input type="submit" value="Save!" /></p>
......
...@@ -11,7 +11,7 @@ urlpatterns = [ ...@@ -11,7 +11,7 @@ urlpatterns = [
url(r'^user/(?P<user_id>[0-9]+)/$', views.user, name='user_profile'), url(r'^user/(?P<user_id>[0-9]+)/$', views.user, name='user_profile'),
url(r'^user/(?P<user_id>[0-9]+)/edit$', views.user_edit, name='user_edit'), url(r'^user/(?P<user_id>[0-9]+)/edit$', views.user_edit, name='user_edit'),
url(r'^page/$', views.page, name='page_list'), url(r'^page/$', views.page, name='page_list'),
url(r'^page/(?P<page_name>[a-z0-9]*)/$', views.page, name='page'), url(r'^page/(?P<page_name>[a-z0-9/]*)/$', views.page, name='page'),
url(r'^page/(?P<page_name>[a-z0-9]*)/edit$', views.page_edit, name='page_edit'), url(r'^page/(?P<page_name>[a-z0-9/]*)/edit$', views.page_edit, name='page_edit'),
] ]
...@@ -93,7 +93,8 @@ def page(request, page_name=None): ...@@ -93,7 +93,8 @@ def page(request, page_name=None):
context['page_list'] = Page.objects.all context['page_list'] = Page.objects.all
return render(request, "core/page.html", context) return render(request, "core/page.html", context)
try: try:
context['page'] = Page.objects.filter(name=page_name).get() context['view_page'] = True
context['page'] = Page.objects.filter(full_name=page_name).get()
context['title'] = context['page'].title context['title'] = context['page'].title
context['test'] = "PAGE_FOUND" context['test'] = "PAGE_FOUND"
except Page.DoesNotExist: except Page.DoesNotExist:
...@@ -111,8 +112,14 @@ def page_edit(request, page_name=None): ...@@ -111,8 +112,14 @@ def page_edit(request, page_name=None):
if request.method == 'POST': if request.method == 'POST':
f = PageForm(request.POST, instance=p) f = PageForm(request.POST, instance=p)
if f.is_valid(): if f.is_valid():
print("TROLL")
f.save() f.save()
context['test'] = "PAGE_SAVED" context['test'] = "PAGE_SAVED"
else:
context['test'] = "PAGE_NOT_SAVED"
else:
context['test'] = "POST_NOT_RECEIVED"
context['page'] = p
context['page_form'] = PageForm(instance=p).as_p() context['page_form'] = PageForm(instance=p).as_p()
return render(request, 'core/page.html', context) return render(request, 'core/page.html', context)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment