add flatpages
This commit is contained in:
0
fet2020/core/__init__.py
Normal file
0
fet2020/core/__init__.py
Normal file
29
fet2020/core/admin.py
Normal file
29
fet2020/core/admin.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.flatpages.admin import FlatPageAdmin
|
||||
from django.contrib.flatpages.models import FlatPage
|
||||
from django.contrib.sites.models import Site
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .forms import FlatPageForm
|
||||
from .models import CustomFlatPage
|
||||
|
||||
|
||||
# Define a new FlatPageAdmin
|
||||
class CustomFlatPageAdmin(FlatPageAdmin):
|
||||
form = FlatPageForm
|
||||
fieldsets = (
|
||||
(None, {'fields': ('url', 'title', 'content',)}),
|
||||
(_('Advanced options'), {
|
||||
'classes': ('collapse',),
|
||||
'fields': ('registration_required', 'template_name'),
|
||||
}),
|
||||
)
|
||||
list_display = ["url", "title", "registration_required"]
|
||||
list_filter = ('registration_required',)
|
||||
|
||||
|
||||
# Re-register FlatPageAdmin
|
||||
admin.site.unregister(FlatPage)
|
||||
admin.site.register(CustomFlatPage, CustomFlatPageAdmin)
|
||||
|
||||
admin.site.unregister(Site)
|
||||
19
fet2020/core/apps.py
Normal file
19
fet2020/core/apps.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from django.apps import AppConfig
|
||||
from django.conf import settings
|
||||
from django.db.models.signals import post_migrate
|
||||
|
||||
|
||||
def update_default_site(sender, **kwargs):
|
||||
from django.contrib.sites.models import Site
|
||||
|
||||
site = Site.objects.get_current()
|
||||
site.domain = settings.HOST_NAME
|
||||
site.name = 'FET'
|
||||
site.save()
|
||||
|
||||
|
||||
class CoreConfig(AppConfig):
|
||||
name = 'core'
|
||||
|
||||
def ready(self):
|
||||
post_migrate.connect(update_default_site, sender=self)
|
||||
11
fet2020/core/forms.py
Normal file
11
fet2020/core/forms.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from ckeditor_uploader.widgets import CKEditorUploadingWidget
|
||||
from django import forms
|
||||
from .models import CustomFlatPage
|
||||
|
||||
|
||||
class FlatPageForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = CustomFlatPage
|
||||
fields = '__all__'
|
||||
|
||||
widgets = {"content": CKEditorUploadingWidget(config_name="default")}
|
||||
27
fet2020/core/migrations/0001_initial.py
Normal file
27
fet2020/core/migrations/0001_initial.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 3.1.5 on 2021-05-13 13:53
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('flatpages', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CustomFlatPage',
|
||||
fields=[
|
||||
('flatpage_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='flatpages.flatpage')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Statische Webseite',
|
||||
'verbose_name_plural': 'Statische Webseiten',
|
||||
},
|
||||
bases=('flatpages.flatpage',),
|
||||
),
|
||||
]
|
||||
0
fet2020/core/migrations/__init__.py
Normal file
0
fet2020/core/migrations/__init__.py
Normal file
18
fet2020/core/models.py
Normal file
18
fet2020/core/models.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.flatpages.models import FlatPage
|
||||
from django.contrib.sites.models import Site
|
||||
from django.db import models
|
||||
|
||||
|
||||
class CustomFlatPage(FlatPage):
|
||||
|
||||
# Managers
|
||||
objects = models.Manager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Statische Webseite"
|
||||
verbose_name_plural = "Statische Webseiten"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save(*args, **kwargs)
|
||||
self.sites.set([Site.objects.get(pk=settings.SITE_ID)])
|
||||
3
fet2020/core/tests.py
Normal file
3
fet2020/core/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
fet2020/core/views.py
Normal file
3
fet2020/core/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Reference in New Issue
Block a user