mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 07:41:14 +00:00
Almost working wiki before refactoring
This commit is contained in:
parent
e9c18748b0
commit
ace66bba0a
@ -43,12 +43,21 @@ class LoginForm(AuthenticationForm):
|
||||
)
|
||||
|
||||
class PageForm(forms.ModelForm):
|
||||
#parent = forms.ModelChoiceField(queryset=Page.objects.all())
|
||||
#def __init__(self, *args, **kwargs):
|
||||
# super(PageForm, self).__init__(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
model = Page
|
||||
fields = ['name', 'title', 'content', ]
|
||||
fields = ['parent', 'name', 'title', 'content', ]
|
||||
|
||||
def save(self, commit=True):
|
||||
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:
|
||||
page.save()
|
||||
return page
|
||||
|
23
core/migrations/0009_auto_20151123_0902.py
Normal file
23
core/migrations/0009_auto_20151123_0902.py
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- 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),
|
||||
),
|
||||
]
|
19
core/migrations/0010_auto_20151123_0948.py
Normal file
19
core/migrations/0010_auto_20151123_0948.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- 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',
|
||||
),
|
||||
]
|
20
core/migrations/0011_page_name.py
Normal file
20
core/migrations/0011_page_name.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -*- 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,
|
||||
),
|
||||
]
|
23
core/migrations/0012_auto_20151123_1002.py
Normal file
23
core/migrations/0012_auto_20151123_1002.py
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- 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'),
|
||||
),
|
||||
]
|
25
core/migrations/0013_auto_20151123_1033.py
Normal file
25
core/migrations/0013_auto_20151123_1033.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- 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):
|
||||
|
||||
|
||||
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)
|
||||
title = models.CharField(_("page title"), max_length=255, blank=True)
|
||||
content = models.TextField(_("page content"), blank=True)
|
||||
revision = models.PositiveIntegerField(_("current revision"), default=1)
|
||||
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:
|
||||
permissions = (
|
||||
@ -122,10 +123,8 @@ class Page(models.Model):
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
return self.full_name
|
||||
|
||||
def get_display_name(self):
|
||||
return self.name
|
||||
return self.full_name
|
||||
|
||||
#def get(self, *args):
|
||||
# return self.__dict__
|
||||
|
@ -11,11 +11,11 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if page %}
|
||||
{% if view_page %}
|
||||
<h3>Page</h3>
|
||||
<p><a href="{% url 'core:page_list' %}">Back to list</a></p>
|
||||
{% 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 %}
|
||||
<p>You're seeing the page <strong>{{ page.get_display_name }}</strong></p>
|
||||
<h3>{{ page.title }}</h3>
|
||||
@ -24,7 +24,7 @@
|
||||
<h3>Page list</h3>
|
||||
<ul>
|
||||
{% 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 %}
|
||||
</ul>
|
||||
{% elif new_page %}
|
||||
@ -32,7 +32,7 @@
|
||||
<p><a href="{% url 'core:page_edit' new_page %}">Create it?</a></p>
|
||||
{% elif page_form %}
|
||||
<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 %}
|
||||
{{ page_form }}
|
||||
<p><input type="submit" value="Save!" /></p>
|
||||
|
@ -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]+)/edit$', views.user_edit, name='user_edit'),
|
||||
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]*)/edit$', views.page_edit, name='page_edit'),
|
||||
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'),
|
||||
]
|
||||
|
||||
|
@ -93,7 +93,8 @@ def page(request, page_name=None):
|
||||
context['page_list'] = Page.objects.all
|
||||
return render(request, "core/page.html", context)
|
||||
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['test'] = "PAGE_FOUND"
|
||||
except Page.DoesNotExist:
|
||||
@ -111,8 +112,14 @@ def page_edit(request, page_name=None):
|
||||
if request.method == 'POST':
|
||||
f = PageForm(request.POST, instance=p)
|
||||
if f.is_valid():
|
||||
print("TROLL")
|
||||
f.save()
|
||||
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()
|
||||
return render(request, 'core/page.html', context)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user