Skip to content

Settings Models

cjkcms.models.wagtailsettings_models.LayoutSettings

Bases: ClusterableModel, BaseSiteSetting

Branding, navbar, and theme settings.

Source code in cjkcms/models/wagtailsettings_models.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
@register_setting(icon="grip")
class LayoutSettings(ClusterableModel, BaseSiteSetting):
    """
    Branding, navbar, and theme settings.
    """

    class Meta:
        verbose_name = _("Layout")

    logo = models.ForeignKey(
        get_image_model_string(),
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="+",
        verbose_name=_("Logo"),
        help_text=_("Brand logo used in the navbar and throughout the site"),
    )
    favicon = models.ForeignKey(
        get_image_model_string(),
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="favicon",
        verbose_name=_("Favicon"),
    )

    default_seo_image = models.ForeignKey(
        get_image_model_string(),
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="default_seo_image",
        verbose_name=_("Default SEO Image"),
    )

    navbar_color_scheme = models.CharField(
        blank=True,
        max_length=50,
        choices=None,
        default="",
        verbose_name=_("Navbar color scheme"),
        help_text=_(
            "Optimizes text and other navbar elements for use with light or dark backgrounds."
        ),  # noqa
    )

    navbar_class = models.CharField(
        blank=True,
        max_length=255,
        default="",
        verbose_name=_("Navbar CSS class"),
        help_text=_(
            'Custom classes applied to navbar e.g. "bg-light", "bg-dark", "bg-primary".'
        ),
    )
    navbar_fixed = models.BooleanField(
        default=False,
        verbose_name=_("Fixed navbar"),
        help_text=_("Fixed navbar will remain at the top of the page when scrolling."),
    )
    navbar_wrapper_fluid = models.BooleanField(
        default=True,
        verbose_name=_("Full width navbar"),
        help_text=_("The navbar will fill edge to edge."),
    )
    navbar_content_fluid = models.BooleanField(
        default=False,
        verbose_name=_("Full width navbar contents"),
        help_text=_("Content within the navbar will fill edge to edge."),
    )
    navbar_collapse_mode = models.CharField(
        blank=True,
        max_length=50,
        choices=None,
        default="",
        verbose_name=_("Collapse navbar menu"),
        help_text=_(
            "Control on what screen sizes to show and collapse the navbar menu links."
        ),
    )
    navbar_format = models.CharField(
        blank=True,
        max_length=50,
        choices=None,
        default="",
        verbose_name=_("Navbar format"),
    )

    navbar_search = models.BooleanField(
        default=True,
        verbose_name=_("Search box"),
        help_text=_("Show search box in navbar"),
    )

    search_format = models.CharField(
        blank=True,
        max_length=50,
        choices=[],
        default="",
        verbose_name=_("Search format"),
    )

    searchbox_input_class = models.CharField(
        blank=True,
        max_length=255,
        default="border-secondary mb-0",
        verbose_name=_("Searchbox input class"),
        help_text=_("Classes applied to searchbox input"),
    )

    searchbutton_class = models.CharField(
        blank=True,
        max_length=255,
        default="btn btn-outline-secondary",
        verbose_name=_("Search button (with text) class"),
        help_text=_(
            "Classes applied to search button. Add e.g. `fas fa-search` for icon."
        ),
    )

    searchbutton_label = models.CharField(
        blank=True,
        max_length=255,
        default="Search",
        verbose_name=_("Search button label"),
        help_text=_(
            "Leave empty when using icon-only button. Otherwise, add button label."
        ),
    )

    navbar_langselector = models.CharField(
        blank=True,
        null=True,
        max_length=255,
        choices=None,
        default=None,
        verbose_name=_("Language selector"),
        help_text=_("Choose lang choice selector"),
    )

    breadcrumbs = models.BooleanField(
        default=False,
        verbose_name=_("Breadcrumbs"),
        help_text=_("Show breadcrumbs in page header"),
    )
    breadcrumb_icon = models.CharField(
        blank=True,
        max_length=32,
        default="slash",
        verbose_name=_("Breadcrumb icon"),
        help_text=_("Bootstrap icon name. See docs for built-in options."),
    )

    frontend_theme = models.CharField(
        blank=True,
        max_length=50,
        choices=None,
        default="",
        verbose_name=_("Theme variant"),
        help_text=cms_settings.CJKCMS_FRONTEND_THEME_HELP,
    )

    awesome_cdn = models.BooleanField(
        default=False,
        verbose_name=_("Font Awesome"),
        help_text=_("Load font awesome from CDN"),
    )

    bootstrap_icons = models.BooleanField(
        default=False,
        verbose_name=_("Bootstrap Icons CSS"),
        help_text=_("Load bootstrap icons css from local/static folder"),
    )

    custom_font = models.BooleanField(
        default=False,
        verbose_name=_("Use custom font"),
        help_text=_("Custom body font e.g. from CDN & include css body override"),
    )

    font_url = models.CharField(
        blank=True,
        max_length=250,
        default=cms_settings.CJKCMS_FONT_URL,
        verbose_name=_("Font URL"),
        help_text=_("Full URL to font css file"),
    )

    font_family = models.CharField(
        blank=True,
        max_length=128,
        default=cms_settings.CJKCMS_FONT_FAMILY,
        verbose_name=_("Font Family"),
        help_text=_("Font family name, e.g. 'Open Sans, sans-serif'"),
    )

    base_template = models.CharField(
        blank=True,
        max_length=200,
        default=cms_settings.CJKCMS_BASE_TEMPLATE_DEFAULT,
        verbose_name=_("Base template"),
        help_text=cms_settings.CJKCMS_BASE_TEMPLATE_HELP,
    )

    articles_show_author = models.BooleanField(
        default=True,
        verbose_name=_("Show author in articles"),
        help_text=_("If disabled, override by filling `display author as` in article"),
    )

    articles_date_format = models.CharField(
        blank=True,
        max_length=200,
        default="Y-m-d",
        verbose_name=_("Date format in articles"),
        help_text=_("Format of the publication date in articles. Set blank to hide."),
    )

    panels = [
        MultiFieldPanel(
            [
                FieldPanel("logo"),
                FieldPanel("favicon"),
                FieldPanel("default_seo_image"),
            ],
            heading=_("Branding"),
            classname="collapsed",
        ),
        InlinePanel(
            "site_navbar",
            help_text=_("Choose one or more navbars"),
            heading=_("Site Navbars"),
        ),
        MultiFieldPanel(
            [
                FieldPanel("navbar_color_scheme"),
                FieldPanel("navbar_class"),
                FieldPanel("navbar_fixed"),
                FieldPanel("navbar_wrapper_fluid"),
                FieldPanel("navbar_content_fluid"),
                FieldPanel("navbar_collapse_mode"),
                FieldPanel("navbar_format"),
                FieldPanel("navbar_langselector"),
            ],
            heading=_("Site Navbar Layout"),
        ),
        MultiFieldPanel(
            [
                FieldPanel("navbar_search"),
                FieldPanel("search_format"),
                FieldPanel("searchbox_input_class"),
                FieldPanel("searchbutton_class"),
                FieldPanel("searchbutton_label"),
            ],
            heading=_("Search box in navbar"),
        ),
        MultiFieldPanel(
            [
                FieldPanel("breadcrumbs"),
                FieldPanel("breadcrumb_icon"),
            ],
            heading=_("Site Header / Breadcrumbs"),
        ),
        InlinePanel(
            "site_footer",
            help_text=_("Choose one or more footers"),
            heading=_("Site Footers"),
        ),
        MultiFieldPanel(
            [
                FieldPanel("frontend_theme"),
                FieldPanel("base_template"),
                FieldPanel("awesome_cdn"),
                FieldPanel("bootstrap_icons"),
                FieldPanel("custom_font"),
                FieldPanel("font_url"),
                FieldPanel("font_family"),
            ],
            heading=_("Theming"),
        ),
        MultiFieldPanel(
            [
                FieldPanel("articles_show_author"),
                FieldPanel("articles_date_format"),
            ],
            heading=_("Article Pages"),
        ),
    ]

    def __init__(self, *args, **kwargs):
        """
        Inject custom choices and defaults into the form fields
        to enable customization of settings without causing migration issues.
        """
        super().__init__(*args, **kwargs)
        # Set choices dynamically.
        self._meta.get_field(
            "frontend_theme"
        ).choices = cms_settings.CJKCMS_FRONTEND_THEME_CHOICES  # type: ignore
        self._meta.get_field(
            "navbar_collapse_mode"
        ).choices = cms_settings.CJKCMS_FRONTEND_NAVBAR_COLLAPSE_MODE_CHOICES  # type: ignore
        self._meta.get_field(
            "navbar_color_scheme"
        ).choices = cms_settings.CJKCMS_FRONTEND_NAVBAR_COLOR_SCHEME_CHOICES  # type: ignore
        self._meta.get_field(
            "navbar_format"
        ).choices = cms_settings.CJKCMS_FRONTEND_NAVBAR_FORMAT_CHOICES  # type: ignore
        self._meta.get_field(
            "search_format"
        ).choices = cms_settings.CJKCMS_FRONTEND_SEARCH_FORMAT_CHOICES  # type: ignore
        self._meta.get_field(
            "navbar_langselector"
        ).choices = cms_settings.CJKCMS_LANGUAGE_SELECTOR_CHOICES  # type: ignore
        # Set default dynamically.
        if not self.id:  # type: ignore # if new record / id not yet assigned
            self.frontend_theme = cms_settings.CJKCMS_FRONTEND_THEME_DEFAULT
            self.navbar_class = cms_settings.CJKCMS_FRONTEND_NAVBAR_CLASS_DEFAULT
            self.navbar_collapse_mode = (
                cms_settings.CJKCMS_FRONTEND_NAVBAR_COLLAPSE_MODE_DEFAULT
            )
            self.navbar_color_scheme = (
                cms_settings.CJKCMS_FRONTEND_NAVBAR_COLOR_SCHEME_DEFAULT
            )
            self.navbar_format = cms_settings.CJKCMS_FRONTEND_NAVBAR_FORMAT_DEFAULT
            self.search_format = cms_settings.CJKCMS_FRONTEND_SEARCH_FORMAT_DEFAULT
            self.base_template = cms_settings.CJKCMS_BASE_TEMPLATE_DEFAULT

__init__

__init__(*args, **kwargs)

Inject custom choices and defaults into the form fields to enable customization of settings without causing migration issues.

Source code in cjkcms/models/wagtailsettings_models.py
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
def __init__(self, *args, **kwargs):
    """
    Inject custom choices and defaults into the form fields
    to enable customization of settings without causing migration issues.
    """
    super().__init__(*args, **kwargs)
    # Set choices dynamically.
    self._meta.get_field(
        "frontend_theme"
    ).choices = cms_settings.CJKCMS_FRONTEND_THEME_CHOICES  # type: ignore
    self._meta.get_field(
        "navbar_collapse_mode"
    ).choices = cms_settings.CJKCMS_FRONTEND_NAVBAR_COLLAPSE_MODE_CHOICES  # type: ignore
    self._meta.get_field(
        "navbar_color_scheme"
    ).choices = cms_settings.CJKCMS_FRONTEND_NAVBAR_COLOR_SCHEME_CHOICES  # type: ignore
    self._meta.get_field(
        "navbar_format"
    ).choices = cms_settings.CJKCMS_FRONTEND_NAVBAR_FORMAT_CHOICES  # type: ignore
    self._meta.get_field(
        "search_format"
    ).choices = cms_settings.CJKCMS_FRONTEND_SEARCH_FORMAT_CHOICES  # type: ignore
    self._meta.get_field(
        "navbar_langselector"
    ).choices = cms_settings.CJKCMS_LANGUAGE_SELECTOR_CHOICES  # type: ignore
    # Set default dynamically.
    if not self.id:  # type: ignore # if new record / id not yet assigned
        self.frontend_theme = cms_settings.CJKCMS_FRONTEND_THEME_DEFAULT
        self.navbar_class = cms_settings.CJKCMS_FRONTEND_NAVBAR_CLASS_DEFAULT
        self.navbar_collapse_mode = (
            cms_settings.CJKCMS_FRONTEND_NAVBAR_COLLAPSE_MODE_DEFAULT
        )
        self.navbar_color_scheme = (
            cms_settings.CJKCMS_FRONTEND_NAVBAR_COLOR_SCHEME_DEFAULT
        )
        self.navbar_format = cms_settings.CJKCMS_FRONTEND_NAVBAR_FORMAT_DEFAULT
        self.search_format = cms_settings.CJKCMS_FRONTEND_SEARCH_FORMAT_DEFAULT
        self.base_template = cms_settings.CJKCMS_BASE_TEMPLATE_DEFAULT

cjkcms.models.wagtailsettings_models.SocialMediaSettings

Bases: BaseSiteSetting

Social media accounts.

Source code in cjkcms/models/wagtailsettings_models.py
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@register_setting(icon="group")
class SocialMediaSettings(BaseSiteSetting):
    """
    Social media accounts.
    """

    class Meta:
        verbose_name = _("Social Media")
        app_label = "cjkcms"

    facebook = models.URLField(
        blank=True,
        verbose_name=_("Facebook"),
        help_text=_("Your Facebook page URL"),
    )
    twitter = models.URLField(
        blank=True,
        verbose_name=_("Twitter"),
        help_text=_("Your Twitter page URL"),
    )
    instagram = models.CharField(
        max_length=255,
        blank=True,
        verbose_name=_("Instagram"),
        help_text=_("Your Instagram username, without the @"),
    )
    linkedin = models.URLField(
        blank=True,
        verbose_name=_("LinkedIn"),
        help_text=_("Your LinkedIn page URL"),
    )
    youtube = models.URLField(
        blank=True,
        verbose_name=_("YouTube"),
        help_text=_("Your YouTube channel or user account URL"),
    )
    vimeo = models.URLField(
        blank=True,
        verbose_name=_("Vimeo"),
        help_text=_("Your Vimeo channel or user account URL"),
    )

    location = models.CharField(
        blank=True,
        max_length=50,
        choices=cms_settings.CJKCMS_SOC_LOCATION_CHOICES,
        default=cms_settings.CJKCMS_SOC_LOCATION_DEFAULT,
        verbose_name=_("Location of social media block"),
    )

    @property
    def twitter_handle(self):
        """
        Gets the handle of the twitter account from a URL.
        """
        return self.twitter.strip().strip("/").split("/")[-1]

    @property
    def social_json(self):
        """
        Returns non-blank social accounts as a JSON list.
        """
        socialist = [
            self.facebook,
            self.twitter,
            self.instagram,
            self.youtube,
            self.linkedin,
            self.vimeo,
        ]
        socialist = list(filter(None, socialist))
        return json.dumps(socialist)

    panels = [
        MultiFieldPanel(
            [
                FieldPanel("facebook"),
                FieldPanel("twitter"),
                FieldPanel("instagram"),
                FieldPanel("linkedin"),
                FieldPanel("youtube"),
                FieldPanel("vimeo"),
            ],
            _("Social Media Accounts"),
        ),
        FieldPanel("location"),
    ]

social_json property

social_json

Returns non-blank social accounts as a JSON list.

twitter_handle property

twitter_handle

Gets the handle of the twitter account from a URL.