Skip to content

Commit 701e423

Browse files
committed
add new code examples
1 parent 209b22f commit 701e423

File tree

4 files changed

+166
-4
lines changed

4 files changed

+166
-4
lines changed

content/pages/examples/django/django-conf-urls-url.markdown

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: django.conf.urls.url Examples
22
category: page
33
slug: django-conf-urls-url-examples
4-
sortorder: 5001
4+
sortorder: 50001
55
toc: False
66
sidebartitle: django.conf.urls.url Examples
77
meta: Python code examples for the url function within the django.conf.urls module of the Django project.
@@ -54,7 +54,7 @@ urlpatterns = [
5454
```
5555

5656

57-
## Example 2 from ORGAN-IZE/register
57+
## Example 2 from register
5858
[register](https://github.com/ORGAN-IZE/register) is a [Django](/django.html),
5959
[Bootstrap](/bootstrap.html), [PostgreSQL](/postgresql.html) project that is
6060
open source under the
@@ -147,3 +147,44 @@ urlpatterns = [
147147
]
148148
```
149149

150+
151+
## Example 4 from django-cms
152+
[django-cms](https://github.com/divio/django-cms)
153+
([project website](https://www.django-cms.org/en/)) is a Python-based
154+
content management system (CMS) [library](https://pypi.org/project/django-cms/)
155+
for use with Django web apps that is open sourced under the
156+
[BSD 3-Clause "New" License](https://github.com/divio/django-cms/blob/develop/LICENSE).
157+
158+
[**django-cms/cms/urls.py**](https://github.com/divio/django-cms/blob/develop/cms/urls.py)
159+
160+
```python
161+
# -*- coding: utf-8 -*-
162+
from django.conf import settings
163+
~~from django.conf.urls import include, url
164+
165+
from cms import views
166+
from cms.apphook_pool import apphook_pool
167+
from cms.appresolver import get_app_patterns
168+
from cms.constants import SLUG_REGEXP
169+
170+
171+
if settings.APPEND_SLASH:
172+
regexp = r'^(?P<slug>%s)/$' % SLUG_REGEXP
173+
else:
174+
regexp = r'^(?P<slug>%s)$' % SLUG_REGEXP
175+
176+
if apphook_pool.get_apphooks():
177+
# If there are some application urls, use special resolver,
178+
# so we will have standard reverse support.
179+
urlpatterns = get_app_patterns()
180+
else:
181+
urlpatterns = []
182+
183+
184+
urlpatterns.extend([
185+
~~ url(r'^cms_login/$', views.login, name='cms_login'),
186+
~~ url(r'^cms_wizard/', include('cms.wizards.urls')),
187+
~~ url(regexp, views.details, name='pages-details-by-slug'),
188+
~~ url(r'^$', views.details, {'slug': ''}, name='pages-root'),
189+
])
190+
```
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
title: django.db.models.Model Examples
2+
category: page
3+
slug: django-db-models-model-examples
4+
sortorder: 50002
5+
toc: False
6+
sidebartitle: django.db.models.Model Examples
7+
meta: Python code examples for the Model class within the django.db.models module of the Django project.
8+
9+
10+
# django.db.models.Model Examples
11+
The
12+
[Model](https://github.com/django/django/blob/master/django/db/models/base.py)
13+
class is the superclass for all data stored in [Django](/django.html)
14+
applications.
15+
16+
17+
18+
## Example 2 from django-cms
19+
[django-cms](https://github.com/divio/django-cms)
20+
([project website](https://www.django-cms.org/en/)) is a Python-based
21+
content management system (CMS)
22+
[code library](https://pypi.org/project/django-cms/)
23+
for use with Django web apps that is open sourced under the
24+
[BSD 3-Clause "New" License](https://github.com/divio/django-cms/blob/develop/LICENSE).
25+
26+
```python
27+
@python_2_unicode_compatible
28+
class Page(models.Model):
29+
"""
30+
A simple hierarchical page model
31+
"""
32+
LIMIT_VISIBILITY_IN_MENU_CHOICES = (
33+
(constants.VISIBILITY_USERS, _('for logged in users only')),
34+
(constants.VISIBILITY_ANONYMOUS, _('for anonymous users only')),
35+
)
36+
TEMPLATE_DEFAULT = TEMPLATE_INHERITANCE_MAGIC if get_cms_setting('TEMPLATE_INHERITANCE') else get_cms_setting('TEMPLATES')[0][0]
37+
38+
X_FRAME_OPTIONS_INHERIT = constants.X_FRAME_OPTIONS_INHERIT
39+
X_FRAME_OPTIONS_DENY = constants.X_FRAME_OPTIONS_DENY
40+
X_FRAME_OPTIONS_SAMEORIGIN = constants.X_FRAME_OPTIONS_SAMEORIGIN
41+
X_FRAME_OPTIONS_ALLOW = constants.X_FRAME_OPTIONS_ALLOW
42+
X_FRAME_OPTIONS_CHOICES = (
43+
(constants.X_FRAME_OPTIONS_INHERIT, _('Inherit from parent page')),
44+
(constants.X_FRAME_OPTIONS_DENY, _('Deny')),
45+
(constants.X_FRAME_OPTIONS_SAMEORIGIN, _('Only this website')),
46+
(constants.X_FRAME_OPTIONS_ALLOW, _('Allow'))
47+
)
48+
49+
template_choices = [(x, _(y)) for x, y in get_cms_setting('TEMPLATES')]
50+
51+
created_by = models.CharField(
52+
_("created by"), max_length=constants.PAGE_USERNAME_MAX_LENGTH,
53+
editable=False)
54+
changed_by = models.CharField(
55+
_("changed by"), max_length=constants.PAGE_USERNAME_MAX_LENGTH,
56+
editable=False)
57+
creation_date = models.DateTimeField(auto_now_add=True)
58+
changed_date = models.DateTimeField(auto_now=True)
59+
60+
publication_date = models.DateTimeField(_("publication date"), null=True, blank=True, help_text=_(
61+
'When the page should go live. Status must be "Published" for page to go live.'), db_index=True)
62+
publication_end_date = models.DateTimeField(_("publication end date"), null=True, blank=True,
63+
help_text=_('When to expire the page. Leave empty to never expire.'),
64+
db_index=True)
65+
#
66+
# Please use toggle_in_navigation() instead of affecting this property
67+
# directly so that the cms page cache can be invalidated as appropriate.
68+
#
69+
in_navigation = models.BooleanField(_("in navigation"), default=True, db_index=True)
70+
soft_root = models.BooleanField(_("soft root"), db_index=True, default=False,
71+
help_text=_("All ancestors will not be displayed in the navigation"))
72+
reverse_id = models.CharField(_("id"), max_length=40, db_index=True, blank=True, null=True, help_text=_(
73+
"A unique identifier that is used with the page_url templatetag for linking to this page"))
74+
navigation_extenders = models.CharField(_("attached menu"), max_length=80, db_index=True, blank=True, null=True)
75+
template = models.CharField(_("template"), max_length=100, choices=template_choices,
76+
help_text=_('The template used to render the content.'),
77+
default=TEMPLATE_DEFAULT)
78+
79+
login_required = models.BooleanField(_("login required"), default=False)
80+
limit_visibility_in_menu = models.SmallIntegerField(_("menu visibility"), default=None, null=True, blank=True,
81+
choices=LIMIT_VISIBILITY_IN_MENU_CHOICES, db_index=True,
82+
help_text=_("limit when this page is visible in the menu"))
83+
is_home = models.BooleanField(editable=False, db_index=True, default=False)
84+
application_urls = models.CharField(_('application'), max_length=200, blank=True, null=True, db_index=True)
85+
application_namespace = models.CharField(_('application instance name'), max_length=200, blank=True, null=True)
86+
87+
# Placeholders (plugins)
88+
placeholders = models.ManyToManyField('cms.Placeholder', editable=False)
89+
90+
# Publisher fields
91+
publisher_is_draft = models.BooleanField(default=True, editable=False, db_index=True)
92+
# This is misnamed - the one-to-one relation is populated on both ends
93+
publisher_public = models.OneToOneField(
94+
'self',
95+
on_delete=models.CASCADE,
96+
related_name='publisher_draft',
97+
null=True,
98+
editable=False,
99+
)
100+
languages = models.CharField(max_length=255, editable=False, blank=True, null=True)
101+
102+
# X Frame Options for clickjacking protection
103+
xframe_options = models.IntegerField(
104+
choices=X_FRAME_OPTIONS_CHOICES,
105+
default=get_cms_setting('DEFAULT_X_FRAME_OPTIONS'),
106+
)
107+
108+
# Flag that marks a page as page-type
109+
is_page_type = models.BooleanField(default=False)
110+
111+
node = models.ForeignKey(
112+
TreeNode,
113+
related_name='cms_pages',
114+
on_delete=models.CASCADE,
115+
)
116+
```

content/pages/examples/django/django-urls-path.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: django.urls.path Examples
22
category: page
33
slug: django-urls-path-examples
4-
sortorder: 5000
4+
sortorder: 50000
55
toc: False
66
sidebartitle: django.urls.path Examples
77
meta: Python code examples for the path function within the django.urls module of the Django project.

theme/templates/table-of-contents.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,12 @@ <h2><a href="/blog.html">Blog Post Tutorials</a></h2>
213213
{% for a in articles %}<h4 class="bp"><a href="/blog/{{ a.slug }}.html">{{ a.title }}</a></h4>{% endfor %}
214214
</div>
215215
<div class="c3">
216-
<h2>Books &amp; Videos</h2>
216+
<h2>Example Code</h2>
217+
<h4 class="bp"><a href="/django-conf-urls-url-examples.html">django.conf.urls.url</a></h4>
218+
219+
<br>
220+
221+
<h2><a href="https://www.deploypython.com/">Books &amp; Videos</a></h2>
217222
<h4 class="bp"><a href="https://training.talkpython.fm/courses/explore_ansible/introduction-to-ansible-with-python">Introduction to Ansible</a></h4>
218223
<h4 class="bp"><a href="https://training.talkpython.fm/courses/explore_entrepreneurs/python-for-entrepreneurs-build-and-launch-your-online-business">Python for Entrepreneurs</a></h4>
219224
<h4 class="bp"><a href="https://www.deploypython.com/">Deploying Flask Web Apps</a></h4>

0 commit comments

Comments
 (0)