Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
02aff40d
Commit
02aff40d
authored
4 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
shared: Refactor SubpageMixin usage
parent
9ac93177
No related branches found
Branches containing commit
No related tags found
2 merge requests
!178
Release
,
!177
Upgrade
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
donate/models.py
+22
-16
22 additions, 16 deletions
donate/models.py
senat_campaign/models.py
+6
-16
6 additions, 16 deletions
senat_campaign/models.py
shared/models.py
+4
-1
4 additions, 1 deletion
shared/models.py
uniweb/models.py
+1
-14
1 addition, 14 deletions
uniweb/models.py
with
33 additions
and
47 deletions
donate/models.py
+
22
−
16
View file @
02aff40d
...
...
@@ -20,28 +20,13 @@ from wagtail.images.blocks import ImageChooserBlock
from
wagtail.images.edit_handlers
import
ImageChooserPanel
from
wagtailmetadata.models
import
MetadataPageMixin
from
shared.models
import
SubpageMixin
from
tuning
import
help
from
.forms
import
DonateForm
from
.utils
import
get_donated_amount_from_api
class
SubpageMixin
:
"""
Must be used in class definition before MetadataPageMixin!
"""
# flag for rendering anchor links in menu
is_home
=
False
@property
def
root_page
(
self
):
if
not
hasattr
(
self
,
"
_root_page
"
):
self
.
_root_page
=
self
.
get_ancestors
().
type
(
DonateHomePage
).
specific
().
get
()
return
self
.
_root_page
def
get_meta_image
(
self
):
return
self
.
search_image
or
self
.
root_page
.
get_meta_image
()
class
DonateFormMixin
(
models
.
Model
):
"""
Pages which has donate form. Must be in class definition before Page!
"""
...
...
@@ -270,6 +255,9 @@ class DonateRegionIndexPage(Page, SubpageMixin, MetadataPageMixin):
### OTHERS
# flag for rendering anchor links in menu
is_home
=
False
class
Meta
:
verbose_name
=
"
Přehled krajů
"
...
...
@@ -333,6 +321,9 @@ class DonateRegionPage(
### OTHERS
# flag for rendering anchor links in menu
is_home
=
False
class
Meta
:
verbose_name
=
"
Kraj
"
...
...
@@ -373,6 +364,9 @@ class DonateProjectIndexPage(Page, SubpageMixin, MetadataPageMixin):
### OTHERS
# flag for rendering anchor links in menu
is_home
=
False
class
Meta
:
verbose_name
=
"
Přehled projektů
"
...
...
@@ -479,6 +473,9 @@ class DonateProjectPage(
### OTHERS
# flag for rendering anchor links in menu
is_home
=
False
class
Meta
:
verbose_name
=
"
Projekt
"
...
...
@@ -565,6 +562,9 @@ class DonateTextPage(Page, SubpageMixin, MetadataPageMixin):
### OTHERS
# flag for rendering anchor links in menu
is_home
=
False
class
Meta
:
verbose_name
=
"
Stránka s textem
"
...
...
@@ -602,6 +602,9 @@ class DonateInfoPage(DonateFormMixin, Page, SubpageMixin, MetadataPageMixin):
### OTHERS
# flag for rendering anchor links in menu
is_home
=
False
class
Meta
:
verbose_name
=
"
Infostránka s formulářem
"
...
...
@@ -674,6 +677,9 @@ class DonateTargetedDonationsPage(
### OTHERS
# flag for rendering anchor links in menu
is_home
=
False
class
Meta
:
verbose_name
=
"
Adresné dary
"
...
...
This diff is collapsed.
Click to expand it.
senat_campaign/models.py
+
6
−
16
View file @
02aff40d
...
...
@@ -17,6 +17,7 @@ from wagtail.images.edit_handlers import ImageChooserPanel
from
wagtailmetadata.models
import
MetadataPageMixin
from
calendar_utils.models
import
CalendarMixin
from
shared.models
import
SubpageMixin
from
tuning
import
help
HELP_COMBINED_TITLE
=
(
...
...
@@ -25,18 +26,7 @@ HELP_COMBINED_TITLE = (
)
class
SubpageMixin
:
"""
Must be used in class definition before MetadataPageMixin!
"""
@property
def
root_page
(
self
):
if
not
hasattr
(
self
,
"
_root_page
"
):
self
.
_root_page
=
self
.
get_parent
().
specific
return
self
.
_root_page
def
get_meta_image
(
self
):
return
self
.
search_image
or
self
.
root_page
.
get_meta_image
()
class
MetaMixin
:
def
get_meta_title
(
self
):
if
self
.
seo_title
:
return
self
.
seo_title
...
...
@@ -288,7 +278,7 @@ class SenatCampaignHomePage(Page, MetadataPageMixin, CalendarMixin):
return
context
class
SenatCampaignNewsIndexPage
(
Page
,
SubpageMixin
,
MetadataPageMixin
):
class
SenatCampaignNewsIndexPage
(
Page
,
SubpageMixin
,
MetaMixin
,
MetadataPageMixin
):
### FIELDS
### PANELS
...
...
@@ -340,7 +330,7 @@ class SenatCampaignNewsIndexPage(Page, SubpageMixin, MetadataPageMixin):
return
context
class
SenatCampaignNewsPage
(
Page
,
SubpageMixin
,
MetadataPageMixin
):
class
SenatCampaignNewsPage
(
Page
,
SubpageMixin
,
MetaMixin
,
MetadataPageMixin
):
### FIELDS
date
=
models
.
DateField
(
"
datum
"
)
...
...
@@ -436,7 +426,7 @@ class ProgramBlock(blocks.StructBlock):
label
=
"
programový bod
"
class
SenatCampaignProgramPage
(
Page
,
SubpageMixin
,
MetadataPageMixin
):
class
SenatCampaignProgramPage
(
Page
,
SubpageMixin
,
MetaMixin
,
MetadataPageMixin
):
### FIELDS
committee_preference
=
StreamField
(
...
...
@@ -484,7 +474,7 @@ class SenatCampaignProgramPage(Page, SubpageMixin, MetadataPageMixin):
verbose_name
=
"
Program
"
class
SenatCampaignCookiesPage
(
Page
,
SubpageMixin
,
MetadataPageMixin
):
class
SenatCampaignCookiesPage
(
Page
,
SubpageMixin
,
MetaMixin
,
MetadataPageMixin
):
### FIELDS
body
=
RichTextField
(
"
obsah
"
,
blank
=
True
)
...
...
This diff is collapsed.
Click to expand it.
shared/models.py
+
4
−
1
View file @
02aff40d
...
...
@@ -15,11 +15,14 @@ class SubpageMixin:
@property
def
root_page
(
self
):
if
not
hasattr
(
self
,
"
_root_page
"
):
#
V
ypada to hackove ale lze takto pouzit: dle dokumentace get_ancestors
#
v
ypada to hackove ale lze takto pouzit: dle dokumentace get_ancestors
# vraci stranky v poradi od rootu, tedy domovska stranka je druha v poradi
self
.
_root_page
=
self
.
get_ancestors
().
specific
()[
1
]
return
self
.
_root_page
def
get_meta_image
(
self
):
return
self
.
search_image
or
self
.
root_page
.
get_meta_image
()
class
ArticleMixin
(
models
.
Model
):
"""
Common fields for articles
"""
...
...
This diff is collapsed.
Click to expand it.
uniweb/models.py
+
1
−
14
View file @
02aff40d
...
...
@@ -11,11 +11,11 @@ from wagtail.contrib.table_block.blocks import TableBlock
from
wagtail.core
import
blocks
from
wagtail.core.fields
import
StreamField
from
wagtail.core.models
import
Page
from
wagtail.documents.blocks
import
DocumentChooserBlock
from
wagtail.images.blocks
import
ImageChooserBlock
from
wagtail.images.edit_handlers
import
ImageChooserPanel
from
wagtailmetadata.models
import
MetadataPageMixin
from
shared.models
import
SubpageMixin
from
tuning
import
help
from
.constants
import
(
...
...
@@ -150,19 +150,6 @@ class MenuItemBlock(blocks.StructBlock):
label
=
"
stránka
"
class
SubpageMixin
:
"""
Must be used in class definition before MetadataPageMixin!
"""
@property
def
root_page
(
self
):
if
not
hasattr
(
self
,
"
_root_page
"
):
self
.
_root_page
=
self
.
get_ancestors
().
type
(
UniwebHomePage
).
specific
().
get
()
return
self
.
_root_page
def
get_meta_image
(
self
):
return
self
.
search_image
or
self
.
root_page
.
get_meta_image
()
class
UniwebContentMixin
(
models
.
Model
):
content
=
StreamField
(
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment