|
|
|
|
@ -1,6 +1,9 @@ |
|
|
|
|
import uuid |
|
|
|
|
|
|
|
|
|
import pytz |
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.db import models |
|
|
|
|
from django.urls import reverse_lazy |
|
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
|
|
|
|
|
|
# Create your models here. |
|
|
|
|
@ -31,7 +34,49 @@ Section._meta.get_field('enabled').verbose_name = _('Включенно') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Post(BasePost, AbstractStatusModel): |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def sharable_url(self): |
|
|
|
|
""" |
|
|
|
|
An url to reach this post (there is a secret url for sharing unpublished |
|
|
|
|
posts to outside users). |
|
|
|
|
""" |
|
|
|
|
if not self.is_published or self.is_future_published: |
|
|
|
|
if self.secret_key: |
|
|
|
|
kwargs = self.blog.scoping_url_kwargs |
|
|
|
|
kwargs.update({"post_secret_key": self.secret_key}) |
|
|
|
|
return reverse_lazy("blog_ext:blog_post_secret", kwargs=kwargs) |
|
|
|
|
else: |
|
|
|
|
return "A secret sharable url for non-authenticated users is generated when you save this post." |
|
|
|
|
else: |
|
|
|
|
return self.get_absolute_url() |
|
|
|
|
|
|
|
|
|
def get_absolute_url(self): |
|
|
|
|
if self.is_published: |
|
|
|
|
if settings.PINAX_BLOG_SLUG_UNIQUE: |
|
|
|
|
name = "blog_ext:blog_post_slug" |
|
|
|
|
kwargs = { |
|
|
|
|
"post_slug": self.slug |
|
|
|
|
} |
|
|
|
|
else: |
|
|
|
|
name = "blog_ext:blog_post" |
|
|
|
|
if settings.USE_TZ and settings.TIME_ZONE: |
|
|
|
|
published = pytz.timezone(settings.TIME_ZONE).normalize(self.published) |
|
|
|
|
else: |
|
|
|
|
published = self.published |
|
|
|
|
kwargs = { |
|
|
|
|
"year": published.strftime("%Y"), |
|
|
|
|
"month": published.strftime("%m"), |
|
|
|
|
"day": published.strftime("%d"), |
|
|
|
|
"slug": self.slug, |
|
|
|
|
} |
|
|
|
|
else: |
|
|
|
|
name = "blog_ext:blog_post_pk" |
|
|
|
|
kwargs = { |
|
|
|
|
"post_pk": self.pk, |
|
|
|
|
} |
|
|
|
|
kwargs.update(self.blog.scoping_url_kwargs) |
|
|
|
|
return reverse_lazy(name, kwargs=kwargs) |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
verbose_name = _('Пост') |
|
|
|
|
|