测试gitnore

This commit is contained in:
ladeng07
2022-05-06 15:45:57 +08:00
parent 12f390949b
commit 51552904f9
2347 changed files with 120102 additions and 53549 deletions
@@ -8,15 +8,12 @@ from django.utils.translation import gettext_lazy as _
class FlatPageAdmin(admin.ModelAdmin):
form = FlatpageForm
fieldsets = (
(None, {"fields": ("url", "title", "content", "sites")}),
(
_("Advanced options"),
{
"classes": ("collapse",),
"fields": ("registration_required", "template_name"),
},
),
(None, {'fields': ('url', 'title', 'content', 'sites')}),
(_('Advanced options'), {
'classes': ('collapse',),
'fields': ('registration_required', 'template_name'),
}),
)
list_display = ("url", "title")
list_filter = ("sites", "registration_required")
search_fields = ("url", "title")
list_display = ('url', 'title')
list_filter = ('sites', 'registration_required')
search_fields = ('url', 'title')
@@ -3,6 +3,6 @@ from django.utils.translation import gettext_lazy as _
class FlatPagesConfig(AppConfig):
default_auto_field = "django.db.models.AutoField"
name = "django.contrib.flatpages"
default_auto_field = 'django.db.models.AutoField'
name = 'django.contrib.flatpages'
verbose_name = _("Flat Pages")
@@ -2,19 +2,15 @@ from django import forms
from django.conf import settings
from django.contrib.flatpages.models import FlatPage
from django.core.exceptions import ValidationError
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext, gettext_lazy as _
class FlatpageForm(forms.ModelForm):
url = forms.RegexField(
label=_("URL"),
max_length=100,
regex=r"^[-\w/\.~]+$",
help_text=_(
"Example: “/about/contact/”. Make sure to have leading and trailing "
"slashes."
),
regex=r'^[-\w/\.~]+$',
help_text=_('Example: “/about/contact/”. Make sure to have leading and trailing slashes.'),
error_messages={
"invalid": _(
"This value must contain only letters, numbers, dots, "
@@ -25,38 +21,38 @@ class FlatpageForm(forms.ModelForm):
class Meta:
model = FlatPage
fields = "__all__"
fields = '__all__'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not self._trailing_slash_required():
self.fields["url"].help_text = _(
"Example: “/about/contact”. Make sure to have a leading slash."
self.fields['url'].help_text = _(
'Example: “/about/contact”. Make sure to have a leading slash.'
)
def _trailing_slash_required(self):
return (
settings.APPEND_SLASH
and "django.middleware.common.CommonMiddleware" in settings.MIDDLEWARE
settings.APPEND_SLASH and
'django.middleware.common.CommonMiddleware' in settings.MIDDLEWARE
)
def clean_url(self):
url = self.cleaned_data["url"]
if not url.startswith("/"):
url = self.cleaned_data['url']
if not url.startswith('/'):
raise ValidationError(
gettext("URL is missing a leading slash."),
code="missing_leading_slash",
code='missing_leading_slash',
)
if self._trailing_slash_required() and not url.endswith("/"):
if self._trailing_slash_required() and not url.endswith('/'):
raise ValidationError(
gettext("URL is missing a trailing slash."),
code="missing_trailing_slash",
code='missing_trailing_slash',
)
return url
def clean(self):
url = self.cleaned_data.get("url")
sites = self.cleaned_data.get("sites")
url = self.cleaned_data.get('url')
sites = self.cleaned_data.get('sites')
same_url = FlatPage.objects.filter(url=url)
if self.instance.pk:
@@ -66,9 +62,9 @@ class FlatpageForm(forms.ModelForm):
for site in sites:
if same_url.filter(sites=site).exists():
raise ValidationError(
_("Flatpage with url %(url)s already exists for site %(site)s"),
code="duplicate_url",
params={"url": url, "site": site},
_('Flatpage with url %(url)s already exists for site %(site)s'),
code='duplicate_url',
params={'url': url, 'site': site},
)
return super().clean()
@@ -1,7 +1,6 @@
# This file is distributed under the same license as the Django package.
#
# Translators:
# arneatec <arneatec@gmail.com>, 2022
# Jannis Leidel <jannis@leidel.info>, 2011
# Venelin Stoykov <vkstoykov@gmail.com>, 2016
# vestimir <vestimir@gmail.com>, 2014
@@ -9,9 +8,9 @@ msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-08 17:27+0200\n"
"PO-Revision-Date: 2022-01-14 11:31+0000\n"
"Last-Translator: arneatec <arneatec@gmail.com>\n"
"POT-Creation-Date: 2015-10-09 17:42+0200\n"
"PO-Revision-Date: 2017-09-19 16:40+0000\n"
"Last-Translator: Venelin Stoykov <vkstoykov@gmail.com>\n"
"Language-Team: Bulgarian (http://www.transifex.com/django/django/language/"
"bg/)\n"
"MIME-Version: 1.0\n"
@@ -30,31 +29,27 @@ msgid "URL"
msgstr "URL"
msgid ""
"Example: /about/contact/. Make sure to have leading and trailing slashes."
"Example: '/about/contact/'. Make sure to have leading and trailing slashes."
msgstr ""
"Пример: \"/about/contact/\". Началната и крайната наклонена чертичка са "
"задължителни."
"Пример: '/about/contact/'. Началната и крайната наклонена чертичка са "
"задължителни. "
msgid ""
"This value must contain only letters, numbers, dots, underscores, dashes, "
"slashes or tildes."
msgstr ""
"Тази стойност трябва да съдържа само букви, цифри, точки, долни тирета, "
"тирета, наклонени черти или тилди."
msgid "Example: “/about/contact”. Make sure to have a leading slash."
msgstr ""
"Пример: \"/about/contact/\". Началната наклонена чертичка е задължителна. "
"наклонени черти или tildes."
msgid "URL is missing a leading slash."
msgstr "В URL липсва начална наклонена черта."
msgstr "URL липсва водеща черта."
msgid "URL is missing a trailing slash."
msgstr "В URL липсва завършваща наклонена черта."
msgstr "URL липсва наклонена черта."
#, python-format
msgid "Flatpage with url %(url)s already exists for site %(site)s"
msgstr "Flatpage с url %(url)s вече съществува за сайт %(site)s"
msgstr "Flatpage с url %(url)s вече съществува за site %(site)s"
msgid "title"
msgstr "заглавие"
@@ -69,11 +64,11 @@ msgid "template name"
msgstr "име на шаблон"
msgid ""
"Example: flatpages/contact_page.html. If this isnt provided, the system "
"will use flatpages/default.html."
"Example: 'flatpages/contact_page.html'. If this isn't provided, the system "
"will use 'flatpages/default.html'."
msgstr ""
"Пример: \"flatpages/contact_page.html\". Ако това не е указано, системата "
"ще използва \"flatpages/default.html\". "
"Пример: 'flatpages/contact_page.html'. Ако това не е указано, системата ще "
"използва 'flatpages/default.html'. "
msgid "registration required"
msgstr "изисква се регистрация"
@@ -2,7 +2,6 @@
#
# Translators:
# Dimitris Glezos <glezos@transifex.com>, 2011
# Fotis Athineos <fotis@transifex.com>, 2021
# Jannis Leidel <jannis@leidel.info>, 2011
# Pãnoș <panos.laganakos@gmail.com>, 2014
# Pãnoș <panos.laganakos@gmail.com>, 2016,2019
@@ -10,9 +9,9 @@ msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-08 17:27+0200\n"
"PO-Revision-Date: 2021-08-04 06:27+0000\n"
"Last-Translator: Fotis Athineos <fotis@transifex.com>\n"
"POT-Creation-Date: 2019-01-16 20:42+0100\n"
"PO-Revision-Date: 2019-01-25 19:37+0000\n"
"Last-Translator: Pãnoș <panos.laganakos@gmail.com>\n"
"Language-Team: Greek (http://www.transifex.com/django/django/language/el/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -30,9 +29,9 @@ msgid "URL"
msgstr "URL"
msgid ""
"Example: /about/contact/. Make sure to have leading and trailing slashes."
"Example: '/about/contact/'. Make sure to have leading and trailing slashes."
msgstr ""
"Παράδειγμα: /about/contact/. Βεβαιωθείτε ότι περιέχει καθέτους στην αρχή "
"Παράδειγμα: '/about/contact/'. Βεβαιωθείτε ότι περιέχει καθέτους στην αρχή "
"και το τέλος."
msgid ""
@@ -42,9 +41,9 @@ msgstr ""
"Η τιμή αυτή πρέπει να περιέχει μόνο γράμματα, αριθμούς, τελείες, παύλες, "
"κάτω παύλες, καθέτους ή περισπωμένες."
msgid "Example: /about/contact. Make sure to have a leading slash."
msgid "Example: '/about/contact'. Make sure to have a leading slash."
msgstr ""
"Παράδειγμα: /about/contact/. Βεβαιωθείτε ότι περιέχει κάθετο στην αρχή."
"Παράδειγμα: '/about/contact/'. Βεβαιωθείτε ότι περιέχει κάθετο στην αρχή."
msgid "URL is missing a leading slash."
msgstr "Λείπει μια αρχική κάθετος από την διεύθυνση."
@@ -70,11 +69,11 @@ msgid "template name"
msgstr "όνομα περιγράμματος"
msgid ""
"Example: flatpages/contact_page.html. If this isnt provided, the system "
"will use flatpages/default.html."
"Example: 'flatpages/contact_page.html'. If this isn't provided, the system "
"will use 'flatpages/default.html'."
msgstr ""
"Παράδειγμα: flatpages/contact_page.html. Αν δεν δηλωθεί, το σύστημα θα "
"χρησιμοποιήσει το flatpages/default.html."
"Παράδειγμα: 'flatpages/contact_page.html'. Αν δεν δηλωθεί, το σύστημα θα "
"χρησιμοποιήσει το 'flatpages/default.html'."
msgid "registration required"
msgstr "απαιτείται εγγραφή"
@@ -1,17 +1,15 @@
# This file is distributed under the same license as the Django package.
#
# Translators:
# Katie McLaughlin <katie@glasnt.com>, 2021
# Tom Fifield <tom@tomfifield.net>, 2021
msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-08 17:27+0200\n"
"PO-Revision-Date: 2021-06-23 07:20+0000\n"
"Last-Translator: Katie McLaughlin <katie@glasnt.com>\n"
"Language-Team: English (Australia) (http://www.transifex.com/django/django/"
"language/en_AU/)\n"
"POT-Creation-Date: 2015-03-18 09:16+0100\n"
"PO-Revision-Date: 2015-03-18 08:34+0000\n"
"Last-Translator: Jannis Leidel <jannis@leidel.info>\n"
"Language-Team: English (Australia) (http://www.transifex.com/projects/p/"
"django/language/en_AU/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
@@ -19,70 +17,58 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
msgid "Advanced options"
msgstr "Advanced options"
msgstr ""
msgid "Flat Pages"
msgstr "Flat Pages"
msgstr ""
msgid "URL"
msgstr "URL"
msgstr ""
msgid ""
"Example: /about/contact/. Make sure to have leading and trailing slashes."
"Example: '/about/contact/'. Make sure to have leading and trailing slashes."
msgstr ""
"Example: “/about/contact/”. Make sure to have leading and trailing slashes."
msgid ""
"This value must contain only letters, numbers, dots, underscores, dashes, "
"slashes or tildes."
msgstr ""
"This value must contain only letters, numbers, dots, underscores, dashes, "
"slashes or tildes."
msgid "Example: “/about/contact”. Make sure to have a leading slash."
msgstr "Example: “/about/contact”. Make sure to have a leading slash."
msgid "URL is missing a leading slash."
msgstr "URL is missing a leading slash."
msgstr ""
msgid "URL is missing a trailing slash."
msgstr "URL is missing a trailing slash."
msgstr ""
#, python-format
msgid "Flatpage with url %(url)s already exists for site %(site)s"
msgstr "Flatpage with url %(url)s already exists for site %(site)s"
msgstr ""
msgid "title"
msgstr "title"
msgstr ""
msgid "content"
msgstr "content"
msgstr ""
msgid "enable comments"
msgstr "enable comments"
msgstr ""
msgid "template name"
msgstr "template name"
msgstr ""
msgid ""
"Example: flatpages/contact_page.html. If this isnt provided, the system "
"will use flatpages/default.html."
"Example: 'flatpages/contact_page.html'. If this isn't provided, the system "
"will use 'flatpages/default.html'."
msgstr ""
"Example: “flatpages/contact_page.html”. If this isnt provided, the system "
"will use “flatpages/default.html”."
msgid "registration required"
msgstr "registration required"
msgstr ""
msgid "If this is checked, only logged-in users will be able to view the page."
msgstr ""
"If this is checked, only logged-in users will be able to view the page."
msgid "sites"
msgstr "sites"
msgid "flat page"
msgstr "flat page"
msgstr ""
msgid "flat pages"
msgstr "flat pages"
msgstr ""
@@ -17,7 +17,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ka\n"
"Plural-Forms: nplurals=2; plural=(n!=1);\n"
"Plural-Forms: nplurals=1; plural=0;\n"
msgid "Advanced options"
msgstr "დამატებითი პარამეტრები"
@@ -15,7 +15,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: kn\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"Plural-Forms: nplurals=1; plural=0;\n"
msgid "Advanced options"
msgstr ""
@@ -1,87 +0,0 @@
# This file is distributed under the same license as the Django package.
#
# Translators:
# Jafry Hisham, 2021
msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-08 17:27+0200\n"
"PO-Revision-Date: 2021-11-16 12:59+0000\n"
"Last-Translator: Jafry Hisham\n"
"Language-Team: Malay (http://www.transifex.com/django/django/language/ms/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: ms\n"
"Plural-Forms: nplurals=1; plural=0;\n"
msgid "Advanced options"
msgstr "Pilihan lanjut"
msgid "Flat Pages"
msgstr "Muka rata"
msgid "URL"
msgstr "URL"
msgid ""
"Example: “/about/contact/”. Make sure to have leading and trailing slashes."
msgstr ""
"Contoh: \"/berkenaan/hubungi/\". Pastikan ada sempang awalan dan akhiran."
msgid ""
"This value must contain only letters, numbers, dots, underscores, dashes, "
"slashes or tildes."
msgstr ""
"Niali ini hanya boleh mengandugi huruf, nombor, titik, garis-bawah, "
"sengkang, sempang atau tilde."
msgid "Example: “/about/contact”. Make sure to have a leading slash."
msgstr "Contoh: \"/berkenaan/hubungi\". Pastikan ada sempang awalan."
msgid "URL is missing a leading slash."
msgstr "URL tidak mempunyai sempang awalan."
msgid "URL is missing a trailing slash."
msgstr "URL tidak mempunyai sempang akhiran."
#, python-format
msgid "Flatpage with url %(url)s already exists for site %(site)s"
msgstr "Mukarata dengan url %(url)s sudah wujud bagi laman %(site)s"
msgid "title"
msgstr "tajuk"
msgid "content"
msgstr "kandungan"
msgid "enable comments"
msgstr "hidupkan komen"
msgid "template name"
msgstr "nama templat"
msgid ""
"Example: “flatpages/contact_page.html”. If this isnt provided, the system "
"will use “flatpages/default.html”."
msgstr ""
"Contoh: \"mukarata/ruangan_hubungi.html\". Sekiranya ini tidak diberikam, "
"sistem akan menggunakan \"flatpages/defulat.html\"."
msgid "registration required"
msgstr "Pendaftaran diperlukan"
msgid "If this is checked, only logged-in users will be able to view the page."
msgstr ""
"Sekiranya ini ditanda, hanya pengguna yang log-masuk sahaja akan dapat "
"melihat ruangan ini."
msgid "sites"
msgstr "laman-laman"
msgid "flat page"
msgstr "muka rata"
msgid "flat pages"
msgstr "muka rata"
@@ -3,14 +3,13 @@
# Translators:
# hgrimelid <havard@grimelid.com>, 2011
# Jannis Leidel <jannis@leidel.info>, 2011
# Sivert Olstad, 2021
msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-08 17:27+0200\n"
"PO-Revision-Date: 2021-11-12 08:48+0000\n"
"Last-Translator: Sivert Olstad\n"
"POT-Creation-Date: 2015-10-09 17:42+0200\n"
"PO-Revision-Date: 2017-09-19 16:40+0000\n"
"Last-Translator: Jannis Leidel <jannis@leidel.info>\n"
"Language-Team: Norwegian Nynorsk (http://www.transifex.com/django/django/"
"language/nn/)\n"
"MIME-Version: 1.0\n"
@@ -23,16 +22,15 @@ msgid "Advanced options"
msgstr "Avanserte innstillingar"
msgid "Flat Pages"
msgstr "Flatsider"
msgstr ""
msgid "URL"
msgstr "Nettadresse"
msgid ""
"Example: /about/contact/. Make sure to have leading and trailing slashes."
"Example: '/about/contact/'. Make sure to have leading and trailing slashes."
msgstr ""
"Eksempel: /om/kontakt/. Kontroller at det er ein skråstrek framanfor og "
"bak."
"Eksempel: '/om/kontakt/'. Kontroller at det er ein skråstrek framfor og bak."
msgid ""
"This value must contain only letters, numbers, dots, underscores, dashes, "
@@ -41,19 +39,15 @@ msgstr ""
"Dette feltet kan berre innehalde bokstavar, nummer, skilleteikn, "
"understrekar, bindestrekar, skråstrekar eller tilder."
msgid "Example: “/about/contact”. Make sure to have a leading slash."
msgstr ""
"Eksempel: “/om/kontakt/”. Kontroller at det er ein skråstrek framanfor."
msgid "URL is missing a leading slash."
msgstr "Nettadressa manglar ein skråstrek framanfor."
msgstr ""
msgid "URL is missing a trailing slash."
msgstr "Nettadressa manglar ein skråstrek bak."
msgstr ""
#, python-format
msgid "Flatpage with url %(url)s already exists for site %(site)s"
msgstr "Flatside med nettadresse %(url)s eksisterer allereie for sida %(site)s"
msgstr ""
msgid "title"
msgstr "tittel"
@@ -68,11 +62,11 @@ msgid "template name"
msgstr "malnamn"
msgid ""
"Example: flatpages/contact_page.html. If this isnt provided, the system "
"will use flatpages/default.html."
"Example: 'flatpages/contact_page.html'. If this isn't provided, the system "
"will use 'flatpages/default.html'."
msgstr ""
"Døme: flatpages/contact_page.html. Dersom denne ikkje er oppgjeve vert "
"flatpages/default.html brukt."
"Døme: 'flatpages/kontakt_side.html'. Dersom denne ikkje er gjeve, vil "
"'flatpages/default.html' bli brukt."
msgid "registration required"
msgstr "krevar registrering"
@@ -81,7 +75,7 @@ msgid "If this is checked, only logged-in users will be able to view the page."
msgstr "Dersom denne er kryssa av, kan berre innlogga brukarar sjå sida."
msgid "sites"
msgstr "nettstadar"
msgstr ""
msgid "flat page"
msgstr "flatside"
@@ -4,14 +4,13 @@
# Jannis Leidel <jannis@leidel.info>, 2011
# Marian Andre <marian@andre.sk>, 2011-2012,2014
# Martin Tóth <ezimir@gmail.com>, 2017
# Peter Kuma, 2021
msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-09-08 17:27+0200\n"
"PO-Revision-Date: 2021-07-24 21:01+0000\n"
"Last-Translator: Peter Kuma\n"
"POT-Creation-Date: 2019-01-16 20:42+0100\n"
"PO-Revision-Date: 2019-01-18 00:18+0000\n"
"Last-Translator: Ramiro Morales\n"
"Language-Team: Slovak (http://www.transifex.com/django/django/language/sk/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -30,10 +29,9 @@ msgid "URL"
msgstr "URL"
msgid ""
"Example: /about/contact/. Make sure to have leading and trailing slashes."
"Example: '/about/contact/'. Make sure to have leading and trailing slashes."
msgstr ""
"Príklad: /about/contact/. Zabezpečte, aby boli lomky na začiatku a na "
"konci."
"Príklad: '/about/contact/'. Uistite sa, že máte lomky na začiatku a na konci."
msgid ""
"This value must contain only letters, numbers, dots, underscores, dashes, "
@@ -42,8 +40,8 @@ msgstr ""
"Táto hodnota musí obsahovať len písmená, číslice, bodky, podčiarovníky, "
"pomlčky, lomky alebo vlnovky."
msgid "Example: /about/contact. Make sure to have a leading slash."
msgstr "Príklad: “/about/contact”. Zabezpečte, aby bola lomka na začiatku."
msgid "Example: '/about/contact'. Make sure to have a leading slash."
msgstr ""
msgid "URL is missing a leading slash."
msgstr "V URL chýba úvodná lomka."
@@ -68,11 +66,11 @@ msgid "template name"
msgstr "názov šablóny"
msgid ""
"Example: flatpages/contact_page.html. If this isnt provided, the system "
"will use flatpages/default.html."
"Example: 'flatpages/contact_page.html'. If this isn't provided, the system "
"will use 'flatpages/default.html'."
msgstr ""
"Príklad: flatpages/contact_page.html. Ak nie je uvedené, systém použije "
"flatpages/default.html."
"Príklad: 'flatpages/contact_page.html'. Ak nič nenapíšete, systém použije "
"'flatpages/default.html'."
msgid "registration required"
msgstr "nutná registrácia"
@@ -4,65 +4,35 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("sites", "0001_initial"),
('sites', '0001_initial'),
]
operations = [
migrations.CreateModel(
name="FlatPage",
name='FlatPage',
fields=[
(
"id",
models.AutoField(
verbose_name="ID",
serialize=False,
auto_created=True,
primary_key=True,
),
),
(
"url",
models.CharField(max_length=100, verbose_name="URL", db_index=True),
),
("title", models.CharField(max_length=200, verbose_name="title")),
("content", models.TextField(verbose_name="content", blank=True)),
(
"enable_comments",
models.BooleanField(default=False, verbose_name="enable comments"),
),
(
"template_name",
models.CharField(
help_text=(
"Example: “flatpages/contact_page.html”. If this isnt "
"provided, the system will use “flatpages/default.html”."
),
max_length=70,
verbose_name="template name",
blank=True,
),
),
(
"registration_required",
models.BooleanField(
default=False,
help_text=(
"If this is checked, only logged-in users will be able to "
"view the page."
),
verbose_name="registration required",
),
),
(
"sites",
models.ManyToManyField(to="sites.Site", verbose_name="sites"),
),
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('url', models.CharField(max_length=100, verbose_name='URL', db_index=True)),
('title', models.CharField(max_length=200, verbose_name='title')),
('content', models.TextField(verbose_name='content', blank=True)),
('enable_comments', models.BooleanField(default=False, verbose_name='enable comments')),
('template_name', models.CharField(
help_text=(
'Example: “flatpages/contact_page.html”. If this isnt provided, the system will use '
'“flatpages/default.html”.'
), max_length=70, verbose_name='template name', blank=True
)),
('registration_required', models.BooleanField(
default=False, help_text='If this is checked, only logged-in users will be able to view the page.',
verbose_name='registration required'
)),
('sites', models.ManyToManyField(to='sites.Site', verbose_name='sites')),
],
options={
"ordering": ["url"],
"db_table": "django_flatpage",
"verbose_name": "flat page",
"verbose_name_plural": "flat pages",
'ordering': ['url'],
'db_table': 'django_flatpage',
'verbose_name': 'flat page',
'verbose_name_plural': 'flat pages',
},
bases=(models.Model,),
),
@@ -6,33 +6,31 @@ from django.utils.translation import gettext_lazy as _
class FlatPage(models.Model):
url = models.CharField(_("URL"), max_length=100, db_index=True)
title = models.CharField(_("title"), max_length=200)
content = models.TextField(_("content"), blank=True)
enable_comments = models.BooleanField(_("enable comments"), default=False)
url = models.CharField(_('URL'), max_length=100, db_index=True)
title = models.CharField(_('title'), max_length=200)
content = models.TextField(_('content'), blank=True)
enable_comments = models.BooleanField(_('enable comments'), default=False)
template_name = models.CharField(
_("template name"),
_('template name'),
max_length=70,
blank=True,
help_text=_(
"Example: “flatpages/contact_page.html”. If this isnt provided, "
"the system will use “flatpages/default.html”."
'Example: “flatpages/contact_page.html”. If this isnt provided, '
'the system will use “flatpages/default.html”.'
),
)
registration_required = models.BooleanField(
_("registration required"),
help_text=_(
"If this is checked, only logged-in users will be able to view the page."
),
_('registration required'),
help_text=_("If this is checked, only logged-in users will be able to view the page."),
default=False,
)
sites = models.ManyToManyField(Site, verbose_name=_("sites"))
sites = models.ManyToManyField(Site, verbose_name=_('sites'))
class Meta:
db_table = "django_flatpage"
verbose_name = _("flat page")
verbose_name_plural = _("flat pages")
ordering = ["url"]
db_table = 'django_flatpage'
verbose_name = _('flat page')
verbose_name_plural = _('flat pages')
ordering = ['url']
def __str__(self):
return "%s -- %s" % (self.url, self.title)
@@ -40,10 +38,10 @@ class FlatPage(models.Model):
def get_absolute_url(self):
from .views import flatpage
for url in (self.url.lstrip("/"), self.url):
for url in (self.url.lstrip('/'), self.url):
try:
return reverse(flatpage, kwargs={"url": url})
return reverse(flatpage, kwargs={'url': url})
except NoReverseMatch:
pass
# Handle script prefix manually because we bypass reverse()
return iri_to_uri(get_script_prefix().rstrip("/") + self.url)
return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
@@ -5,10 +5,8 @@ from django.core.exceptions import ImproperlyConfigured
class FlatPageSitemap(Sitemap):
def items(self):
if not django_apps.is_installed("django.contrib.sites"):
raise ImproperlyConfigured(
"FlatPageSitemap requires django.contrib.sites, which isn't installed."
)
Site = django_apps.get_model("sites.Site")
if not django_apps.is_installed('django.contrib.sites'):
raise ImproperlyConfigured("FlatPageSitemap requires django.contrib.sites, which isn't installed.")
Site = django_apps.get_model('sites.Site')
current_site = Site.objects.get_current()
return current_site.flatpage_set.filter(registration_required=False)
@@ -19,16 +19,15 @@ class FlatpageNode(template.Node):
self.user = None
def render(self, context):
if "request" in context:
site_pk = get_current_site(context["request"]).pk
if 'request' in context:
site_pk = get_current_site(context['request']).pk
else:
site_pk = settings.SITE_ID
flatpages = FlatPage.objects.filter(sites__id=site_pk)
# If a prefix was specified, add a filter
if self.starts_with:
flatpages = flatpages.filter(
url__startswith=self.starts_with.resolve(context)
)
url__startswith=self.starts_with.resolve(context))
# If the provided user is not authenticated, or no user
# was provided, filter the list to only public flatpages.
@@ -40,7 +39,7 @@ class FlatpageNode(template.Node):
flatpages = flatpages.filter(registration_required=False)
context[self.context_name] = flatpages
return ""
return ''
@register.tag
@@ -71,10 +70,9 @@ def get_flatpages(parser, token):
{% get_flatpages '/about/' for someuser as about_pages %}
"""
bits = token.split_contents()
syntax_message = (
"%(tag_name)s expects a syntax of %(tag_name)s "
"['url_starts_with'] [for user] as context_name" % {"tag_name": bits[0]}
)
syntax_message = ("%(tag_name)s expects a syntax of %(tag_name)s "
"['url_starts_with'] [for user] as context_name" %
{'tag_name': bits[0]})
# Must have at 3-6 bits in the tag
if 3 <= len(bits) <= 6:
# If there's an even number of bits, there's no prefix
@@ -84,13 +82,13 @@ def get_flatpages(parser, token):
prefix = None
# The very last bit must be the context name
if bits[-2] != "as":
if bits[-2] != 'as':
raise template.TemplateSyntaxError(syntax_message)
context_name = bits[-1]
# If there are 5 or 6 bits, there is a user defined
if len(bits) >= 5:
if bits[-4] != "for":
if bits[-4] != 'for':
raise template.TemplateSyntaxError(syntax_message)
user = bits[-3]
else:
@@ -2,5 +2,5 @@ from django.contrib.flatpages import views
from django.urls import path
urlpatterns = [
path("<path:url>", views.flatpage, name="django.contrib.flatpages.views.flatpage"),
path('<path:url>', views.flatpage, name='django.contrib.flatpages.views.flatpage'),
]
@@ -7,7 +7,7 @@ from django.template import loader
from django.utils.safestring import mark_safe
from django.views.decorators.csrf import csrf_protect
DEFAULT_TEMPLATE = "flatpages/default.html"
DEFAULT_TEMPLATE = 'flatpages/default.html'
# This view is called from FlatpageFallbackMiddleware.process_response
# when a 404 is raised, which often means CsrfViewMiddleware.process_view
@@ -30,16 +30,16 @@ def flatpage(request, url):
flatpage
`flatpages.flatpages` object
"""
if not url.startswith("/"):
url = "/" + url
if not url.startswith('/'):
url = '/' + url
site_id = get_current_site(request).id
try:
f = get_object_or_404(FlatPage, url=url, sites=site_id)
except Http404:
if not url.endswith("/") and settings.APPEND_SLASH:
url += "/"
if not url.endswith('/') and settings.APPEND_SLASH:
url += '/'
f = get_object_or_404(FlatPage, url=url, sites=site_id)
return HttpResponsePermanentRedirect("%s/" % request.path)
return HttpResponsePermanentRedirect('%s/' % request.path)
else:
raise
return render_flatpage(request, f)
@@ -54,7 +54,6 @@ def render_flatpage(request, f):
# logged in, redirect to the login page.
if f.registration_required and not request.user.is_authenticated:
from django.contrib.auth.views import redirect_to_login
return redirect_to_login(request.path)
if f.template_name:
template = loader.select_template((f.template_name, DEFAULT_TEMPLATE))
@@ -67,4 +66,4 @@ def render_flatpage(request, f):
f.title = mark_safe(f.title)
f.content = mark_safe(f.content)
return HttpResponse(template.render({"flatpage": f}, request))
return HttpResponse(template.render({'flatpage': f}, request))