Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
ace66bba
Commit
ace66bba
authored
Nov 23, 2015
by
Skia
Browse files
Almost working wiki before refactoring
parent
e9c18748
Changes
10
Hide whitespace changes
Inline
Side-by-side
core/forms.py
View file @
ace66bba
...
...
@@ -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
...
...
core/migrations/0009_auto_20151123_0902.py
0 → 100644
View file @
ace66bba
# -*- 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
),
),
]
core/migrations/0010_auto_20151123_0948.py
0 → 100644
View file @
ace66bba
# -*- 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'
,
),
]
core/migrations/0011_page_name.py
0 → 100644
View file @
ace66bba
# -*- 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
,
),
]
core/migrations/0012_auto_20151123_1002.py
0 → 100644
View file @
ace66bba
# -*- 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'
),
),
]
core/migrations/0013_auto_20151123_1033.py
0 → 100644
View file @
ace66bba
# -*- 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
),
),
]
core/models.py
View file @
ace66bba
...
...
@@ -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
)
child
ren
=
models
.
ForeignKey
(
'self'
,
related_name
=
"
pa
ren
t
"
,
null
=
True
)
pa
ren
t
=
models
.
ForeignKey
(
'self'
,
related_name
=
"
child
ren"
,
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__
core/templates/core/page.html
View file @
ace66bba
...
...
@@ -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>
...
...
core/urls.py
View file @
ace66bba
...
...
@@ -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'
),
]
core/views.py
View file @
ace66bba
...
...
@@ -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
)
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