Esempio n. 1
0
class Post(TimestampModelMixin, models.Model):
    all_objects = PostManager()
    objects = PublishedPostManager()

    blog = models.ForeignKey(Blog, on_delete=models.PROTECT)
    title = models.CharField(max_length=100, verbose_name='názov')
    slug = AutoSlugField(title_field='title', in_respect_to=('blog', ))
    original_perex = RichTextOriginalField(filtered_field='filtered_perex',
                                           property_name='perex',
                                           verbose_name='perex',
                                           max_length=1000)
    filtered_perex = RichTextFilteredField()
    original_content = RichTextOriginalField(filtered_field='filtered_content',
                                             property_name='content',
                                             verbose_name='obsah',
                                             parsers={'html': 'blog'},
                                             max_length=100000)
    filtered_content = RichTextFilteredField()
    pub_time = models.DateTimeField(verbose_name='čas publikácie',
                                    db_index=True)
    linux = models.BooleanField('linuxový blog', default=False)
    polls = GenericRelation(Poll)
    comments_header = GenericRelation(RootHeader)
    comments = GenericRelation(Comment)
    attachments = GenericRelation(Attachment)
    hit = HitCountField()

    content_fields = (
        'original_perex',
        'original_content',
    )

    def get_absolute_url(self):
        return reverse('blog:post-detail', args=(self.blog.slug, self.slug))

    def published(self):
        if not self.pub_time:
            return False
        return self.pub_time < timezone.now()

    published.short_description = 'je publikovaný'
    published.boolean = True

    @property
    def author(self):
        return self.blog.author

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'zápis'
        verbose_name_plural = 'zápisy'
        unique_together = (('blog', 'slug'), )
        ordering = ('-pub_time', )
Esempio n. 2
0
class Note(TimestampModelMixin, models.Model):
    content_type = models.ForeignKey(ContentType,
                                     limit_choices_to=(Q(app_label='news',
                                                         model='news')),
                                     verbose_name='typ obsahu',
                                     on_delete=models.PROTECT)
    object_id = models.PositiveIntegerField(verbose_name='id objektu', )
    content_object = GenericForeignKey('content_type', 'object_id')

    subject = models.CharField('predmet', max_length=100)

    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               blank=True,
                               null=True,
                               verbose_name='autor',
                               on_delete=models.SET_NULL)
    authors_name = models.CharField(max_length=255, verbose_name='meno autora')

    original_text = RichTextOriginalField(filtered_field='filtered_text',
                                          property_name='text',
                                          verbose_name='poznámka',
                                          max_length=20000)
    filtered_text = RichTextFilteredField()

    def __str__(self):
        return self.subject
        #return Truncator(strip_tags(self.filtered_text).replace('&shy;', '')).words(3, truncate="...")

    class Meta:
        verbose_name = 'poznámka'
        verbose_name_plural = 'poznámky'
Esempio n. 3
0
class Blog(TimestampModelMixin, models.Model):
	author = models.OneToOneField(
		settings.AUTH_USER_MODEL,
		verbose_name="autor",
		on_delete=models.CASCADE
	)
	title = models.CharField(
		verbose_name="názov blogu",
		max_length=100
	)
	slug = AutoSlugField(
		verbose_name="skratka URL",
		title_field='title',
		unique=True
	)
	original_description = RichTextOriginalField(
		verbose_name="popis blogu",
		filtered_field='filtered_description',
		property_name='description',
		max_length=1000,
		blank=True
	)
	filtered_description = RichTextFilteredField(
	)
	original_sidebar = RichTextOriginalField(
		verbose_name="bočný panel",
		filtered_field='filtered_sidebar',
		property_name='sidebar',
		max_length=1000,
		blank=True
	)
	filtered_sidebar = RichTextFilteredField(
	)

	content_fields = ('original_descriptoin', 'original_sidebar',)
	rating_statistics = GenericRelation('rating.Statistics')
	notification_events = GenericRelation('notifications.Event')

	def get_absolute_url(self):
		return reverse('blog:post-list-category', kwargs={'category': self.slug, 'page': 1})

	def __str__(self):
		return self.title

	class Meta:
		verbose_name = "blog"
		verbose_name_plural = "blogy"
Esempio n. 4
0
class Tweet(TimestampModelMixin, models.Model):
	title = models.CharField(
		verbose_name="titulok",
		max_length=255
	)
	slug = AutoSlugField(
		verbose_name="skratka URL",
		title_field='title',
		unique=True
	)

	original_text = RichTextOriginalField(
		verbose_name="text",
		filtered_field='filtered_text',
		property_name='text',
		max_length=TWEET_MAX_LENGTH
	)
	filtered_text = RichTextFilteredField()


	author = models.ForeignKey(
		settings.AUTH_USER_MODEL,
		verbose_name="autor",
		on_delete=models.CASCADE
	)

	link_text = models.CharField(
		verbose_name="text odkazu",
		max_length=100,
		blank=True
	)
	link_url = models.URLField(
		verbose_name="odkaz",
		max_length=1000,
		blank=True
	)

	comments_header = GenericRelation('comments.RootHeader')
	comments = GenericRelation('comments.Comment')

	content_fields = ('original_text',)

	class Meta:
		verbose_name = "tweet"
		verbose_name_plural = "tweety"

	def get_absolute_url(self):
		return reverse('tweets:detail', kwargs={'slug': self.slug})

	def get_list_url(self):
		return reverse('tweets:list', kwargs={'page': 1})

	def __str__(self):
		return self.title
Esempio n. 5
0
class NodeRevision(TimestampModelMixin, models.Model):
	node = models.ForeignKey('blackhole.Node', on_delete=models.CASCADE)
	author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.SET_NULL)
	title = models.CharField(max_length=128)
	original_body = RichTextOriginalField(
		filtered_field='filtered_body',
		property_name='body',
		parsers={'raw': '', 'html': 'full'}
	)
	filtered_body = RichTextFilteredField()
	log = models.TextField(blank=True)

	def __str__(self):
		return self.title
Esempio n. 6
0
class Blog(TimestampModelMixin, models.Model):
    author = models.OneToOneField(settings.AUTH_USER_MODEL,
                                  on_delete=models.CASCADE)
    title = models.CharField(max_length=100, verbose_name='názov blogu')
    slug = AutoSlugField(title_field='title', unique=True)
    original_description = RichTextOriginalField(
        filtered_field='filtered_description',
        property_name='description',
        verbose_name='popis blogu',
        max_length=1000,
        blank=True)
    filtered_description = RichTextFilteredField()
    original_sidebar = RichTextOriginalField(filtered_field='filtered_sidebar',
                                             property_name='sidebar',
                                             verbose_name='bočný panel',
                                             max_length=1000,
                                             blank=True)
    filtered_sidebar = RichTextFilteredField()

    content_fields = (
        'original_descriptoin',
        'original_sidebar',
    )

    def get_absolute_url(self):
        return reverse('blog:post-list-category',
                       kwargs={
                           'category': self.slug,
                           'page': 1
                       })

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'blog'
        verbose_name_plural = 'blogy'
Esempio n. 7
0
class Page(mptt.models.MPTTModel, TimestampModelMixin):
    TYPE_CHOICES = (
        ('h', 'Domovská stránka'),
        ('i', 'Interná stránka'),
        ('p', 'Stránka wiki'),
    )

    title = models.CharField(verbose_name="titulok", max_length=255)
    last_author = models.ForeignKey(settings.AUTH_USER_MODEL,
                                    verbose_name="posledný autor",
                                    blank=True,
                                    null=True,
                                    on_delete=models.SET_NULL)
    slug = AutoSlugField(verbose_name="skratka URL",
                         title_field='title',
                         unique=True)
    parent = models.ForeignKey('self',
                               verbose_name="nadradená stránka",
                               related_name='children',
                               blank=True,
                               null=True,
                               on_delete=models.PROTECT)
    original_text = RichTextOriginalField(verbose_name="text",
                                          filtered_field='filtered_text',
                                          property_name='text')
    filtered_text = RichTextFilteredField()
    page_type = models.CharField(verbose_name="typ stránky",
                                 max_length=1,
                                 choices=TYPE_CHOICES,
                                 default='p')

    content_fields = ('original_text', )

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "Wiki stránka"
        verbose_name_plural = "Wiki stránky"

    def get_absolute_url(self):
        if self.page_type == 'h' and not self.parent:
            return reverse('wiki:home')
        else:
            return reverse('wiki:page', kwargs={'slug': self.slug, 'page': 1})
Esempio n. 8
0
class Note(TimestampModelMixin, models.Model):
    content_type = models.ForeignKey(
        ContentType,
        verbose_name="typ obsahu",
        limit_choices_to=(Q(app_label='news', model='news')
                          | Q(app_label='comments', model='comment')
                          | Q(app_label='forum', model='topic')),
        on_delete=models.PROTECT)
    object_id = models.PositiveIntegerField(verbose_name="id objektu", )
    content_object = GenericForeignKey('content_type', 'object_id')

    subject = models.CharField("predmet", max_length=100, blank=True)

    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               verbose_name="autor",
                               blank=True,
                               null=True,
                               on_delete=models.SET_NULL)
    authors_name = models.CharField(verbose_name="meno autora", max_length=255)

    original_text = RichTextOriginalField(verbose_name="poznámka",
                                          filtered_field='filtered_text',
                                          property_name='text',
                                          max_length=20000)
    filtered_text = RichTextFilteredField()

    is_public = models.BooleanField(
        verbose_name="poznámka je verejná",
        help_text="Poznámku môže vidieť ktorýkoľvek návštevník",
        blank=True,
        default=False,
    )

    def __str__(self):
        return self.subject

    class Meta:
        verbose_name = "poznámka"
        verbose_name_plural = "poznámky"
Esempio n. 9
0
class Desktop(TimestampModelMixin, models.Model):
    objects = DesktopManager()

    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               verbose_name='autor',
                               related_name='my_desktops',
                               on_delete=models.CASCADE)
    title = models.CharField('názov', max_length=255)
    image = AutoImageField('desktop',
                           upload_to='desktops',
                           resize_source=dict(size=(4096, 4096)))

    original_text = RichTextOriginalField(
        filtered_field='filtered_text',
        property_name='text',
        verbose_name='popis',
        max_length=DESKTOP_DESCRIPTION_MAX_LENGTH)
    filtered_text = RichTextFilteredField()

    favorited = models.ManyToManyField(settings.AUTH_USER_MODEL,
                                       through='FavoriteDesktop')

    comments_header = GenericRelation(RootHeader)
    comments = GenericRelation(Comment)
    hit = HitCountField()

    def get_absolute_url(self):
        return reverse('desktops:detail', args=(self.pk, ))

    def get_update_url(self):
        return reverse('desktops:update', args=(self.pk, ))

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'desktop'
        verbose_name_plural = 'desktopy'
Esempio n. 10
0
class Article(TimestampModelMixin, models.Model):
    all_articles = models.Manager()
    objects = ArticleManager()

    title = models.CharField(verbose_name="názov", max_length=255)
    slug = models.SlugField(verbose_name="skratka URL", unique=True)
    category = models.ForeignKey(Category,
                                 verbose_name="kategória",
                                 on_delete=models.PROTECT)

    original_perex = RichTextOriginalField(
        verbose_name="text na titulnej stránke",
        filtered_field='filtered_perex',
        property_name='perex',
        parsers={'raw': ''})
    filtered_perex = RichTextFilteredField()

    original_annotation = RichTextOriginalField(
        verbose_name="text pred telom článku",
        filtered_field='filtered_annotation',
        property_name='annotation',
        parsers={'raw': ''})
    filtered_annotation = RichTextFilteredField()

    original_content = RichTextOriginalField(verbose_name="obsah",
                                             filtered_field='filtered_content',
                                             property_name='content',
                                             parsers={'raw': ''})
    filtered_content = RichTextFilteredField()

    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               verbose_name="autor",
                               on_delete=models.SET_NULL,
                               blank=True,
                               null=True)
    authors_name = models.CharField(verbose_name="meno autora", max_length=255)
    pub_time = models.DateTimeField(verbose_name="čas publikácie",
                                    default=now,
                                    db_index=True)
    published = models.BooleanField(verbose_name="publikované", default=False)
    top = models.BooleanField(verbose_name="hodnotný článok", default=False)
    image = AutoImageField(verbose_name="obrázok",
                           upload_to='article/thumbnails',
                           resize_source=dict(size=(2048, 2048)),
                           blank=True)

    polls = GenericRelation('polls.Poll')
    comments_header = GenericRelation('comments.RootHeader')
    comments = GenericRelation('comments.Comment')
    attachments = GenericRelation('attachment.Attachment')
    hit = HitCountField()

    content_fields = (
        'original_perex',
        'original_annotation',
        'original_content',
    )

    @property
    def poll_set(self):
        return self.polls.all().filter(approved=True).order_by('pk').all()

    def get_absolute_url(self):
        return reverse('article:detail', kwargs={'slug': self.slug})

    @cached_property
    def series_object(self):
        if hasattr(self, 'series'):
            return self.series.series
        else:
            return None

    @cached_property
    def related_documents(self):
        series = self.series_object
        if not series:
            return None
        articles = Article.objects.filter(series__series=series)
        related = related_documents(instance=self,
                                    queryset=articles.only(
                                        'pk', 'series__id', 'title', 'slug'),
                                    ordering=['series__id'],
                                    select_range=3)
        related['up'] = series
        return related

    def is_published(self):
        return self.published and self.pub_time <= now()

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "článok"
        verbose_name_plural = "články"
Esempio n. 11
0
class User(AbstractUser):
    objects = UserManager()

    jabber = models.CharField(max_length=127, blank=True)
    url = models.CharField(max_length=255, blank=True)
    signature = models.CharField('podpis', max_length=255, blank=True)
    display_mail = models.BooleanField('zobrazovať e-mail', default=False)
    distribution = models.CharField('linuxová distribúcia',
                                    max_length=50,
                                    blank=True)
    original_info = RichTextOriginalField(
        filtered_field='filtered_info',
        property_name='info',
        parsers={'html': 'profile'},
        verbose_name='informácie',
        validators=[MaxLengthValidator(100000)],
        blank=True)
    filtered_info = RichTextFilteredField(blank=True)
    year = models.SmallIntegerField(
        'rok narodenia',
        validators=[MinValueValidator(1900),
                    MaxValueValidator(2015)],
        blank=True,
        null=True)
    avatar = AutoImageField('fotografia',
                            upload_to='accounts/avatars',
                            resize_source=dict(size=(512, 512)),
                            blank=True)
    settings = models.TextField('nastavenia', blank=True)
    geoposition = GeopositionField(verbose_name='poloha', blank=True)

    def __init__(self, *args, **kwargs):
        super(User, self).__init__(*args, **kwargs)
        self._meta.get_field('username').validators = [UsernameValidator]

    def clean_fields(self, exclude=None):
        if self.email:
            qs = get_default_manager(self).filter(email=self.email).exclude(
                pk=self.pk)
            if qs.exists():
                raise ValidationError({
                    'email':
                    ['Používateľ s touto e-mailovou adresou už existuje']
                })
        super(User, self).clean_fields(exclude)

    def get_absolute_url(self):
        return reverse('accounts:profile', kwargs={'pk': self.pk})

    def get_full_name(self):
        full_name = ('%s %s' % (self.first_name, self.last_name)).strip()
        return full_name or self.username or self.email

    get_full_name.short_description = 'celé meno'
    get_full_name.admin_order_field = 'last_name,first_name,username'

    @property
    def user_settings(self):
        try:
            return json.loads(self.settings)
        except ValueError:
            return {}

    @user_settings.setter
    def user_settings(self, val):
        self.settings = json.dumps(val, cls=DjangoJSONEncoder)

    @property
    def count_new(self):
        return {k.replace('.', '_'): v for k, v in get_count_new(self).items()}

    @property
    def last_desktop(self):
        Desktop = apps.get_model('desktops', 'desktop')
        return (Desktop.objects.all().filter(
            author=self).order_by('-pk').first())

    def __str__(self):
        return self.get_full_name() or self.username

    class Meta:
        db_table = 'auth_user'
        verbose_name = 'používateľ'
        verbose_name_plural = 'používatelia'
Esempio n. 12
0
class News(TimestampModelMixin, models.Model):
    all_news = NewsManager()
    objects = NewsListManager()

    title = models.CharField(max_length=255, verbose_name='titulok')
    slug = AutoSlugField(title_field='title', unique=True)
    category = models.ForeignKey(Category,
                                 verbose_name='kategória',
                                 on_delete=models.PROTECT)

    original_short_text = RichTextOriginalField(
        filtered_field='filtered_short_text',
        property_name='short_text',
        verbose_name='krátky text',
        parsers={'html': 'news_short'},
        max_length=NEWS_MAX_LENGTH)
    filtered_short_text = RichTextFilteredField()

    original_long_text = RichTextOriginalField(
        filtered_field='filtered_long_text',
        property_name='long_text',
        verbose_name='dlhý text',
        parsers={'html': 'news_long'},
        help_text=
        'Vyplňte v prípade, že sa text v detaile správy má líšiť od textu v zozname.'
    )
    filtered_long_text = RichTextFilteredField()

    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               on_delete=models.SET_NULL,
                               blank=True,
                               null=True,
                               verbose_name='autor')
    authors_name = models.CharField(max_length=255, verbose_name='meno autora')
    source = models.CharField(max_length=100, verbose_name='zdroj', blank=True)
    source_url = models.URLField(max_length=1000,
                                 verbose_name='URL zdroja',
                                 blank=True)
    approved = models.BooleanField(default=False, verbose_name='schválená')
    comments_header = GenericRelation(RootHeader)
    attachments = GenericRelation(Attachment)
    comments = GenericRelation(Comment)
    notes = GenericRelation(Note)

    content_fields = (
        'original_short_text',
        'original_long_text',
    )

    class Meta:
        verbose_name = 'správa'
        verbose_name_plural = 'správy'

    def get_absolute_url(self):
        return reverse('news:detail', kwargs={'slug': self.slug})

    def get_list_url(self):
        return reverse('news:list', kwargs={'page': 1})

    @cached_property
    def admin_notes(self):
        return self.notes.order_by('pk')

    def __str__(self):
        return self.title
Esempio n. 13
0
class Topic(TimestampModelMixin, models.Model):
    objects = TopicManager()
    topics = TopicListManager()

    ip_address = models.GenericIPAddressField('IP adresa',
                                              blank=True,
                                              null=True)
    section = models.ForeignKey(Section,
                                verbose_name='sekcia',
                                on_delete=models.PROTECT)
    title = models.CharField('predmet', max_length=100)
    original_text = RichTextOriginalField(filtered_field="filtered_text",
                                          property_name="text",
                                          verbose_name='text',
                                          max_length=FORUM_TOPIC_MAX_LENGTH)
    filtered_text = RichTextFilteredField()
    authors_name = models.CharField('meno autora', max_length=50, blank=False)
    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               blank=True,
                               null=True,
                               verbose_name='autor',
                               on_delete=models.SET_NULL)
    comments_header = GenericRelation(RootHeader)
    attachments = GenericRelation(Attachment)
    comments = GenericRelation(Comment)
    is_removed = models.BooleanField('vymazané', default=False)
    is_resolved = models.BooleanField('vyriešené', default=False)

    breadcrumb_label = 'fórum'

    content_fields = ('original_text', )

    def is_public(self):
        return not self.is_removed

    def get_tags(self):
        tags = []
        if self.is_removed:
            tags.append('deleted')
        if self.is_resolved:
            tags.append('resolved')
        if tags:
            return ' ' + ' '.join(tags)
        else:
            return ''

    def get_attachments(self):
        return self.attachments.all()

    def get_authors_name(self):
        if self.author:
            if self.author.get_full_name():
                return self.author.get_full_name()
            else:
                return self.author.username
        else:
            return self.authors_name

    get_authors_name.short_description = 'meno autora'

    def get_absolute_url(self):
        return reverse('forum:topic-detail', kwargs={'pk': self.pk})

    def get_list_url(self):
        return reverse('forum:overview', kwargs={'page': 1})

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = 'téma vo fóre'
        verbose_name_plural = 'témy vo fóre'
Esempio n. 14
0
class Post(TimestampModelMixin, models.Model):
	all_objects = PostManager()
	objects = PublishedPostManager()

	blog = models.ForeignKey(
		Blog,
		verbose_name="blog",
		on_delete=models.PROTECT
	)
	title = models.CharField(
		verbose_name="názov",
		max_length=100
	)
	slug = AutoSlugField(
		verbose_name="skratka URL",
		title_field='title',
		in_respect_to=('blog',)
	)
	original_perex = RichTextOriginalField(
		verbose_name="perex",
		filtered_field='filtered_perex',
		property_name='perex',
		max_length=1000
	)
	filtered_perex = RichTextFilteredField(
	)
	original_content = RichTextOriginalField(
		verbose_name="obsah",
		filtered_field='filtered_content',
		property_name='content',
		parsers={'html': 'blog'},
		max_length=100000
	)
	filtered_content = RichTextFilteredField(
	)
	pub_time = models.DateTimeField(
		verbose_name="čas publikácie",
		db_index=True
	)
	linux = models.BooleanField(
		"linuxový blog",
		default=False
	)

	polls = GenericRelation('polls.Poll')
	comments_header = GenericRelation('comments.RootHeader')
	comments = GenericRelation('comments.Comment')
	attachments = GenericRelation('attachment.Attachment')
	rating_statistics = GenericRelation('rating.Statistics')
	notification_events = GenericRelation('notifications.Event')
	hit = HitCountField()

	content_fields = ('original_perex', 'original_content',)

	def get_absolute_url(self):
		return reverse('blog:post-detail', args=(self.blog.slug, self.slug))

	def published(self):
		if not self.pub_time:
			return False
		return self.pub_time < timezone.now()
	published.short_description = "je publikovaný"
	published.boolean = True

	@property
	def author(self):
		return self.blog.author

	def __str__(self):
		return self.title

	class Meta:
		verbose_name = "zápis"
		verbose_name_plural = "zápisy"
		unique_together = (('blog', 'slug'),)
		ordering = ('-pub_time',)
Esempio n. 15
0
class News(TimestampModelMixin, models.Model):
    all_news = NewsManager()
    objects = NewsListManager()

    title = models.CharField(verbose_name="titulok", max_length=255)
    slug = AutoSlugField(verbose_name="skratka URL",
                         title_field='title',
                         unique=True)
    category = models.ForeignKey(Category,
                                 verbose_name="kategória",
                                 on_delete=models.PROTECT)

    original_short_text = RichTextOriginalField(
        verbose_name="krátky text",
        filtered_field='filtered_short_text',
        property_name='short_text',
        parsers={'html': 'news_short'},
        max_length=NEWS_MAX_LENGTH)
    filtered_short_text = RichTextFilteredField()

    original_long_text = RichTextOriginalField(
        verbose_name="dlhý text",
        filtered_field='filtered_long_text',
        property_name='long_text',
        parsers={'html': 'news_long'},
        help_text=
        "Vyplňte v prípade, že sa text v detaile správy má líšiť od textu v zozname."
    )
    filtered_long_text = RichTextFilteredField()

    author = models.ForeignKey(settings.AUTH_USER_MODEL,
                               verbose_name="autor",
                               on_delete=models.SET_NULL,
                               blank=True,
                               null=True)
    authors_name = models.CharField(verbose_name="meno autora", max_length=255)
    source = models.CharField(verbose_name="zdroj", max_length=100, blank=True)
    source_url = models.URLField(verbose_name="URL zdroja",
                                 max_length=1000,
                                 blank=True)
    approved = models.BooleanField(verbose_name="schválená", default=False)

    comments_header = GenericRelation('comments.RootHeader')
    comments = GenericRelation('comments.Comment')
    attachments = GenericRelation('attachment.Attachment')
    notes = GenericRelation('notes.Note')

    content_fields = (
        'original_short_text',
        'original_long_text',
    )

    class Meta:
        verbose_name = "správa"
        verbose_name_plural = "správy"

    def get_absolute_url(self):
        return reverse('news:detail', kwargs={'slug': self.slug})

    def get_list_url(self):
        return reverse('news:list', kwargs={'page': 1})

    @cached_property
    def admin_notes(self):
        return self.notes.order_by('pk')

    @cached_property
    def public_notes(self):
        return self.admin_notes.filter(is_public=True)

    def __str__(self):
        return self.title
Esempio n. 16
0
class Comment(MPTTModel, TimestampModelMixin):
	objects = CommentManager()

	content_type = models.ForeignKey(ContentType, verbose_name='typ obsahu', related_name='content_type_set_for_%(class)s', on_delete=models.PROTECT)
	object_id = models.PositiveIntegerField('ID objektu')
	content_object = GenericForeignKey('content_type', 'object_id')
	parent = TreeForeignKey('self', null=True, blank=True, related_name='children', verbose_name='nadradený', on_delete=models.CASCADE)

	subject = models.CharField('predmet', max_length=100)
	user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='používateľ', blank=True, null=True, related_name='%(class)s_comments', on_delete=models.SET_NULL)
	user_name = models.CharField('používateľské meno', max_length=50, blank=True)
	original_comment = RichTextOriginalField(filtered_field='filtered_comment', property_name='comment', verbose_name='obsah', max_length=COMMENT_MAX_LENGTH)
	filtered_comment = RichTextFilteredField()

	ip_address = models.GenericIPAddressField('IP adresa', blank=True, null=True)
	is_public = models.BooleanField('verejný', default=True)
	is_removed = models.BooleanField('odstránený', default=False)

	is_locked = models.BooleanField('uzamknutý', default=False)

	attachments = GenericRelation(Attachment)

	content_fields = ('original_comment',)

	def get_or_create_root_header(self):
		try:
			header = RootHeader.objects.get(content_type=self.content_type, object_id=self.object_id)
			return header
		except RootHeader.DoesNotExist:
			with transaction.atomic():
				header, created = RootHeader.objects.get_or_create(content_type=self.content_type, object_id=self.object_id)
				if created:
					header.pub_date = self.created
					header.save()
				return header

	def get_absolute_url(self):
		return '%s#link_%d' % (reverse('comments:comments', args=(self.get_or_create_root_header().pk,), kwargs={}), self.id)

	def get_single_comment_url(self):
		return reverse('comments:comment-single', args=(self.pk,))

	def get_tags(self):
		tags = []
		if getattr(self, 'is_new', False):
			tags.append('new')
		if not self.is_public:
			tags.append('private')
		if self.is_removed:
			tags.append('deleted')
		if tags:
			return ' ' + ' '.join(tags)
		else:
			return ''

	def _get_name(self):
		return self.user_name
	name = property(_get_name)

	def save(self, *args, **kwargs):
		if not self.user_name and self.user:
			self.user_name = force_str(self.user)
		return super(Comment, self).save(*args, **kwargs)

	def __str__(self):
		return self.subject

	class Meta:
		ordering = ('tree_id', 'lft')
		index_together = (('object_id', 'content_type',),)
		verbose_name = 'komentár'
		verbose_name_plural = 'komentáre'