mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Add very basic and not safe pages
This commit is contained in:
parent
c6b35071db
commit
6253c06235
@ -1,6 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from .models import User
|
||||
from .models import User, Page
|
||||
|
||||
|
||||
admin.site.register(User)
|
||||
admin.site.register(Page)
|
||||
|
||||
|
@ -3,7 +3,7 @@ from django import forms
|
||||
from django.contrib.auth import logout, login, authenticate
|
||||
import logging
|
||||
|
||||
from .models import User
|
||||
from .models import User, Page
|
||||
|
||||
class RegisteringForm(UserCreationForm):
|
||||
error_css_class = 'error'
|
||||
@ -42,4 +42,15 @@ class LoginForm(AuthenticationForm):
|
||||
params={'username': self.username_field.verbose_name},
|
||||
)
|
||||
|
||||
class PageForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Page
|
||||
fields = ['name', 'title', 'content', ]
|
||||
|
||||
def save(self, commit=True):
|
||||
page = super(PageForm, self).save(commit=False)
|
||||
if commit:
|
||||
page.save()
|
||||
return page
|
||||
|
||||
|
||||
|
19
core/migrations/0004_page_children.py
Normal file
19
core/migrations/0004_page_children.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', '0003_auto_20151119_1635'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='page',
|
||||
name='children',
|
||||
field=models.ForeignKey(to='core.Page', related_name='parent', null=True),
|
||||
),
|
||||
]
|
19
core/migrations/0005_page_title.py
Normal file
19
core/migrations/0005_page_title.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', '0004_page_children'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='page',
|
||||
name='title',
|
||||
field=models.CharField(blank=True, max_length=255, verbose_name='page title'),
|
||||
),
|
||||
]
|
23
core/migrations/0006_auto_20151120_0958.py
Normal file
23
core/migrations/0006_auto_20151120_0958.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', '0005_page_title'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='page',
|
||||
name='id',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='page',
|
||||
name='full_name',
|
||||
field=models.CharField(primary_key=True, max_length=255, serialize=False, verbose_name='full name'),
|
||||
),
|
||||
]
|
24
core/migrations/0007_auto_20151120_1347.py
Normal file
24
core/migrations/0007_auto_20151120_1347.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0006_auto_20151120_0958'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='page',
|
||||
name='full_name',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='page',
|
||||
name='id',
|
||||
field=models.AutoField(default=0, auto_created=True, verbose_name='ID', primary_key=True, serialize=False),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -106,12 +106,14 @@ class User(AbstractBaseUser, PermissionsMixin):
|
||||
self.username = user_name
|
||||
return user_name
|
||||
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
@ -120,5 +122,10 @@ class Page(models.Model):
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.full_name
|
||||
return self.name
|
||||
|
||||
def get_display_name(self):
|
||||
return self.name
|
||||
|
||||
#def get(self, *args):
|
||||
# return self.__dict__
|
||||
|
@ -14,6 +14,7 @@
|
||||
<li><a href="{% url 'core:login' %}">Login</a></li>
|
||||
<li><a href="{% url 'core:logout' %}">Logout</a></li>
|
||||
<li><a href="{% url 'core:user_list' %}">Users</a></li>
|
||||
<li><a href="{% url 'core:page_list' %}">Pages</a></li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
</header>
|
||||
|
45
core/templates/core/page.html
Normal file
45
core/templates/core/page.html
Normal file
@ -0,0 +1,45 @@
|
||||
{% extends "core/base.html" %}
|
||||
|
||||
{% block title %}
|
||||
{% if page %}
|
||||
{{ page.get_display_name }}
|
||||
{% elif page_list %}
|
||||
Page list
|
||||
{% else %}
|
||||
{{ title }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% if 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>
|
||||
{% endif %}
|
||||
<p>You're seeing the page <strong>{{ page.get_display_name }}</strong></p>
|
||||
<h3>{{ page.title }}</h3>
|
||||
<p>{{ page.content }}</p>
|
||||
{% elif page_list %}
|
||||
<h3>Page list</h3>
|
||||
<ul>
|
||||
{% for p in page_list %}
|
||||
<li><a href="{% url 'core:page' p.name %}">{{ p.get_display_name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% elif new_page %}
|
||||
<h2>{{ title }}</h2>
|
||||
<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">
|
||||
{% csrf_token %}
|
||||
{{ page_form }}
|
||||
<p><input type="submit" value="Save!" /></p>
|
||||
</form>
|
||||
{% else %}
|
||||
There is no page in this website.
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -10,5 +10,8 @@ urlpatterns = [
|
||||
url(r'^user/$', views.user, name='user_list'),
|
||||
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'),
|
||||
]
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from django.http import HttpResponse
|
||||
from django.contrib.auth import logout as auth_logout
|
||||
from django.db import models
|
||||
|
||||
from .models import User
|
||||
from .forms import RegisteringForm, LoginForm
|
||||
from .models import User, Page
|
||||
from .forms import RegisteringForm, LoginForm, PageForm
|
||||
|
||||
import logging
|
||||
|
||||
@ -86,3 +87,32 @@ def user_edit(request, user_id=None):
|
||||
return render(request, "core/edit_user.html", context)
|
||||
return user(request, user_id)
|
||||
|
||||
def page(request, page_name=None):
|
||||
context = {'title': 'View a Page'}
|
||||
if 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['title'] = context['page'].title
|
||||
context['test'] = "PAGE_FOUND"
|
||||
except Page.DoesNotExist:
|
||||
context['title'] = "This page does not exist"
|
||||
context['new_page'] = page_name
|
||||
context['test'] = "PAGE_NOT_FOUND"
|
||||
return render(request, "core/page.html", context)
|
||||
|
||||
def page_edit(request, page_name=None):
|
||||
context = {'title': 'Edit a page',
|
||||
'page_name': page_name}
|
||||
p = Page.objects.filter(name=page_name).first()
|
||||
if p == None:
|
||||
p = Page(name=page_name)
|
||||
if request.method == 'POST':
|
||||
f = PageForm(request.POST, instance=p)
|
||||
if f.is_valid():
|
||||
f.save()
|
||||
context['test'] = "PAGE_SAVED"
|
||||
context['page_form'] = PageForm(instance=p).as_p()
|
||||
return render(request, 'core/page.html', context)
|
||||
|
||||
|
1
users.json
Normal file
1
users.json
Normal file
@ -0,0 +1 @@
|
||||
[{"model": "core.user", "pk": 1, "fields": {"is_staff": true, "password": "pbkdf2_sha256$20000$MDukCN5X8Bof$rYdhppKiusj+W/1Rxpy0yuYsEyWocESEjtRsopkOc5c=", "first_name": "Ro", "is_active": true, "date_of_birth": "1969-12-31T23:00:00Z", "date_joined": "2015-11-19T16:05:51.764Z", "nick_name": "", "is_superuser": true, "username": "root", "email": "bibou@git.an", "last_login": "2015-11-19T16:16:59.539Z", "last_name": "Ot", "user_permissions": [], "groups": []}}, {"model": "core.user", "pk": 2, "fields": {"is_staff": false, "password": "pbkdf2_sha256$20000$UK9a29p5bBEh$Jzv7xs0W9njJZiXfIdYXDydim/3YHs6awKwDmN7gSAc=", "first_name": "Skia", "is_active": true, "date_of_birth": "1969-12-31T23:00:00Z", "date_joined": "2015-11-19T16:06:29.556Z", "nick_name": "", "is_superuser": false, "username": "skia", "email": "plop@libskia.so", "last_login": "2015-11-19T16:16:49.606Z", "last_name": "Kia", "user_permissions": [], "groups": []}}]
|
Loading…
Reference in New Issue
Block a user