Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Sith
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AE
Sith
Commits
6253c062
Commit
6253c062
authored
Nov 20, 2015
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add very basic and not safe pages
parent
c6b35071
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
190 additions
and
6 deletions
+190
-6
core/admin.py
core/admin.py
+2
-1
core/forms.py
core/forms.py
+12
-1
core/migrations/0004_page_children.py
core/migrations/0004_page_children.py
+19
-0
core/migrations/0005_page_title.py
core/migrations/0005_page_title.py
+19
-0
core/migrations/0006_auto_20151120_0958.py
core/migrations/0006_auto_20151120_0958.py
+23
-0
core/migrations/0007_auto_20151120_1347.py
core/migrations/0007_auto_20151120_1347.py
+24
-0
core/models.py
core/models.py
+9
-2
core/templates/core/base.html
core/templates/core/base.html
+1
-0
core/templates/core/page.html
core/templates/core/page.html
+45
-0
core/urls.py
core/urls.py
+3
-0
core/views.py
core/views.py
+32
-2
users.json
users.json
+1
-0
No files found.
core/admin.py
View file @
6253c062
from
django.contrib
import
admin
from
.models
import
User
from
.models
import
User
,
Page
admin
.
site
.
register
(
User
)
admin
.
site
.
register
(
Page
)
core/forms.py
View file @
6253c062
...
...
@@ -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
core/migrations/0004_page_children.py
0 → 100644
View file @
6253c062
# -*- 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
),
),
]
core/migrations/0005_page_title.py
0 → 100644
View file @
6253c062
# -*- 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'
),
),
]
core/migrations/0006_auto_20151120_0958.py
0 → 100644
View file @
6253c062
# -*- 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'
),
),
]
core/migrations/0007_auto_20151120_1347.py
0 → 100644
View file @
6253c062
# -*- 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
,
),
]
core/models.py
View file @
6253c062
...
...
@@ -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
=
Fals
e
)
title
=
models
.
CharField
(
_
(
"page title"
),
max_length
=
255
,
blank
=
Tru
e
)
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__
core/templates/core/base.html
View file @
6253c062
...
...
@@ -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>
...
...
core/templates/core/page.html
0 → 100644
View file @
6253c062
{% 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 %}
core/urls.py
View file @
6253c062
...
...
@@ -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'
),
]
core/views.py
View file @
6253c062
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
)
users.json
0 → 100644
View file @
6253c062
[{
"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"
:
[]}}]
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment