Esempio n. 1
0
class Notification(models.Model):
    """
    A notification
    """
    class Meta:
        verbose_name = _(u'Notification')
        verbose_name_plural = _(u'Notifications')

    subscription = models.ForeignKey(Subscription,
                                     related_name='subscription',
                                     db_index=True)
    pubdate = models.DateTimeField(_(u'Date de création'),
                                   auto_now_add=True,
                                   db_index=True)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField(db_index=True)
    content_object = GenericForeignKey('content_type', 'object_id')
    is_read = models.BooleanField(_(u'Lue'), default=False, db_index=True)
    is_dead = models.BooleanField(_(u'Morte'), default=False)
    url = models.CharField('URL', max_length=255)
    sender = models.ForeignKey(User, related_name='sender', db_index=True)
    title = models.CharField('Titre', max_length=200)
    objects = NotificationManager()

    def __unicode__(self):
        return _(u'Notification du membre "{0}" à propos de : {1} #{2} ({3})')\
            .format(self.subscription.user, self.content_type, self.content_object.pk, self.subscription)

    @staticmethod
    def has_read_permission(request):
        return request.user.is_authenticated()

    def has_object_read_permission(self, request):
        return Notification.has_read_permission(
            request) and self.subscription.user == request.user
Esempio n. 2
0
class Notification(models.Model):
    """
    A notification
    """
    class Meta:
        verbose_name = _("Notification")
        verbose_name_plural = _("Notifications")

    subscription = models.ForeignKey(Subscription,
                                     related_name="subscription",
                                     db_index=True,
                                     on_delete=models.CASCADE)
    pubdate = models.DateTimeField(_("Date de création"),
                                   auto_now_add=True,
                                   db_index=True)
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField(db_index=True)
    content_object = GenericForeignKey("content_type", "object_id")
    is_read = models.BooleanField(_("Lue"), default=False, db_index=True)
    is_dead = models.BooleanField(_("Morte"), default=False)
    url = models.CharField("URL", max_length=255)
    sender = models.ForeignKey(User,
                               related_name="sender",
                               db_index=True,
                               on_delete=models.CASCADE)
    title = models.CharField("Titre", max_length=200)
    objects = NotificationManager()

    def __str__(self):
        return _('Notification du membre "{0}" à propos de : {1} #{2} ({3})'
                 ).format(self.subscription.user, self.content_type,
                          self.content_object.pk, self.subscription)

    def __copy__(self):
        return Notification(
            subscription=self.subscription,
            pubdate=self.pubdate,
            content_type=self.content_type,
            object_id=self.object_id,
            content_object=self.content_object,
            is_read=self.is_read,
            is_dead=self.is_dead,
            url=self.url,
            sender=self.sender,
            title=self.title,
        )

    @staticmethod
    def has_read_permission(request):
        return request.user.is_authenticated

    def has_object_read_permission(self, request):
        return Notification.has_read_permission(
            request) and self.subscription.user == request.user