Ejemplo 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', )
Ejemplo n.º 2
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
Ejemplo 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"
Ejemplo n.º 4
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})
Ejemplo n.º 5
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'
Ejemplo n.º 6
0
class Poll(TimestampModelMixin, models.Model):
    all_objects = models.Manager()
    objects = PollListManager()
    active_polls = ActivePollsListManager()

    question = models.TextField(verbose_name="otázka")
    slug = AutoSlugField(verbose_name="skratka URL",
                         title_field='question',
                         unique=True)

    content_type = models.ForeignKey(
        ContentType,
        verbose_name="typ obsahu",
        limit_choices_to=(Q(app_label='article', model='article')
                          | Q(app_label='blog', model='post')),
        null=True,
        blank=True,
        on_delete=models.PROTECT)
    object_id = models.PositiveIntegerField(verbose_name="id objektu",
                                            null=True,
                                            blank=True)
    content_object = GenericForeignKey('content_type', 'object_id')

    active_from = models.DateTimeField(verbose_name="aktívne od",
                                       blank=True,
                                       null=True)
    checkbox = models.BooleanField(verbose_name="viac odpovedí", default=False)
    approved = models.BooleanField(verbose_name="schválené", default=False)

    answer_count = models.PositiveIntegerField(verbose_name="počet odpovedí",
                                               default=0)

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

    @property
    def choices(self):
        return (Choice.objects.filter(
            poll=self.pk).select_related('poll').order_by('pk'))

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

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

    def msg_id(self):
        return 'poll-' + str(self.pk)

    def can_vote(self, request):
        if request.user.is_authenticated:
            return not RecordUser.objects.filter(user=request.user,
                                                 poll=self).exists()
        else:
            return not RecordIp.objects.filter(ip=request.META['REMOTE_ADDR'],
                                               poll=self).exists()

    def record_vote(self, request):
        if request.user.is_authenticated:
            RecordUser.objects.create(user=request.user, poll=self)
        else:
            RecordIp.objects.create(ip=request.META['REMOTE_ADDR'], poll=self)

    def clean(self):
        if self.content_type and not self.object_id:
            raise ValidationError("Pole id objektu je povinné")
        if self.object_id and not self.content_type:
            raise ValidationError("Pole typ obsahu je povinné")
        if self.content_type:
            self.slug = self.content_type.model + '-' + str(self.object_id)

    def __str__(self):
        return self.question

    class Meta:
        verbose_name = "anketa"
        verbose_name_plural = "ankety"
Ejemplo n.º 7
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
Ejemplo n.º 8
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',)
Ejemplo n.º 9
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