|
26 | 26 | from fluent_pages import appsettings |
27 | 27 | from fluent_utils.django_compat import transaction_atomic, AUTH_USER_MODEL |
28 | 28 | from parler.utils.context import switch_language |
| 29 | +from slug_preview.models import SlugPreviewField |
29 | 30 | from future.utils import with_metaclass, itervalues, iteritems |
30 | 31 |
|
31 | 32 |
|
@@ -151,6 +152,27 @@ def get_absolute_url(self): |
151 | 152 | # is included at a sublevel, it needs to be prepended. |
152 | 153 | return self.default_url |
153 | 154 |
|
| 155 | + def get_absolute_url_format(self): |
| 156 | + if self.is_file: |
| 157 | + url_format = '/{slug}' |
| 158 | + else: |
| 159 | + url_format = '/{slug}/' |
| 160 | + |
| 161 | + # Extra for django-slug-preview |
| 162 | + if self.parent_id: |
| 163 | + # TODO: optimize this call. In some cases this would also work.. |
| 164 | + # that is, unless get_absolute_url() is redefined or ABSOLUTE_URL_OVERRIDES was used. |
| 165 | + #parent_url = self.get_translation(self.get_current_language()).get_parent_cached_url(self) |
| 166 | + |
| 167 | + # Need to fetch the whole parent to make sure the URL matches the actual URL being used. |
| 168 | + parent = self.parent |
| 169 | + with switch_language(parent, self.get_current_language()): |
| 170 | + parent_url = parent.get_absolute_url() |
| 171 | + |
| 172 | + return parent_url.rstrip('/') + url_format |
| 173 | + else: |
| 174 | + return url_format |
| 175 | + |
154 | 176 | @property |
155 | 177 | def default_url(self): |
156 | 178 | """ |
@@ -530,7 +552,7 @@ class UrlNode_Translation(TranslatedFieldsModel): |
530 | 552 | """ |
531 | 553 | # Translated fields |
532 | 554 | title = models.CharField(_("title"), max_length=255) |
533 | | - slug = models.SlugField(_("slug"), max_length=100, help_text=_("The slug is used in the URL of the page")) |
| 555 | + slug = SlugPreviewField(_("slug"), max_length=100, help_text=_("The slug is used in the URL of the page")) |
534 | 556 | override_url = models.CharField(_('Override URL'), editable=True, max_length=255, blank=True, help_text=_('Override the target URL. Be sure to include slashes at the beginning and at the end if it is a local URL. This affects both the navigation and subpages\' URLs.')) |
535 | 557 | _cached_url = models.CharField(max_length=255, db_index=True, null=True, blank=True, editable=False) |
536 | 558 |
|
|
0 commit comments