class Asset(SortableMixin): name = CharField(max_length=140, default='Untitled Asset') kind = CharField(max_length=8, default='web', choices=( ('web', 'Web Page'), ('video', 'Video (MP4)'), ), verbose_name='Asset Type') url = CharField(max_length=512, verbose_name='URL', validators=[URLValidator()]) parameters = CharField(max_length=512, blank=True, null=True) duration = PositiveIntegerField(default=30, validators=[ MaxValueValidator(1800), MinValueValidator(5), ], verbose_name='Duration (s)') active = BooleanField(default=True) playlist = SortableForeignKey(Playlist) # ordering field asset_order = PositiveIntegerField(default=0, editable=False, db_index=True) class Meta: ordering = ['asset_order'] def __unicode__(self): return self.name
class Tracker(SortableMixin): createur = SortableForeignKey(Profil, verbose_name='créateur', related_name='trackers', on_delete=models.CASCADE) nom = models.CharField(max_length=100) icone = IconField('icône') color = ColorField('couleur', default='#FFFFFF') date_creation = models.DateTimeField('date de création', auto_now_add=True) order = models.PositiveIntegerField(default=0, editable=False, db_index=True) class Meta: unique_together = (('createur', 'nom'),) ordering = ['order'] def __str__(self): return self.nom def get_absolute_url(self): return reverse('tracker:detail-tracker', kwargs={'pk': self.id}) def track_by_hour(self): hours = {} for i in range(24): hours[str(i)] = 0 for track in self.tracks.all(): hours[str(track.datetime.hour)] += 1 return hours def track_by_day(self): weekdays = { 0: 'Lundi', 1: 'Mardi', 2: 'Mercredi', 3: 'Jeudi', 4: 'Vendredi', 5: 'Samedi', 6: 'Dimanche' } days = {} for weekday in weekdays.values(): days[weekday] = 0 for track in self.tracks.all(): days[weekdays[track.datetime.weekday()]] += 1 return days @property def rgba_background_color(self): """ Retourne la commande css pour afficher la couleur du tracker avec une opacité diminué afin de voir les différentes courbes les unes à travers les autres. """ opacity = '0.3' return 'rgba(%s,%s)' % ( ','.join(tuple(str(int(self.color.lstrip('#')[i:i+2], 16)) for i in (0, 2, 4))), opacity )
class Article(SortableMixin): class Meta: ordering = ['order_for_art'] def __str__(self): return self.headline headline = models.CharField(max_length=255) text = models.TextField(max_length=75000) category = SortableForeignKey(Category, on_delete=models.CASCADE) order_for_art = models.PositiveIntegerField(default=0, editable=False, db_index=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True)
class Aspect(SortableMixin): description = models.TextField() game = SortableForeignKey(Game, editable=False, related_name='aspects') order = models.PositiveIntegerField(default=0, editable=False, db_index=True) def __str__(self): return self.name class Meta: ordering = ['order']
class Game(SortableMixin): name = models.CharField(max_length=255) party = SortableForeignKey(Party, editable=False, related_name='games') order = models.PositiveIntegerField(default=0, editable=False, db_index=True) def __str__(self): return self.name class Meta: ordering = ['order']
class Subcategory(Sortable): name = models.CharField(max_length=100) hebrew_name = models.CharField(max_length=100) category = SortableForeignKey(Category) class Meta(Sortable.Meta): pass def __str__(self): return self.hebrew_name def get_absolute_url(self): return reverse('subcategory', args=[self.category.subject.name, self.category.name, self.name])
class Tracker(SortableMixin): createur = SortableForeignKey(Profil, verbose_name='créateur', related_name='trackers', on_delete=models.CASCADE) nom = models.CharField(max_length=100) icone = IconField('icône') color = ColorField('couleur', default='#FFFFFF') date_creation = models.DateTimeField('date de création', auto_now_add=True) order = models.PositiveIntegerField(default=0, editable=False, db_index=True) class Meta: unique_together = (('createur', 'nom'), ) ordering = ['order'] def __str__(self): return self.nom def get_absolute_url(self): return reverse('tracker:detail-tracker', kwargs={'pk': self.id}) def track_by_hour(self): hours = {} for i in range(24): hours[str(i)] = 0 for track in self.tracks.all(): hours[str(track.datetime.hour)] += 1 return hours def track_by_day(self): weekdays = { 0: 'Lundi', 1: 'Mardi', 2: 'Mercredi', 3: 'Jeudi', 4: 'Vendredi', 5: 'Samedi', 6: 'Dimanche' } days = {} for weekday in weekdays.values(): days[weekday] = 0 for track in self.tracks.all(): days[weekdays[track.datetime.weekday()]] += 1 return days
class Category(Sortable): name = models.CharField(max_length=100) hebrew_name = models.CharField(max_length=100) subject = SortableForeignKey(Subject, related_name='categories') subcategories_per_line = models.IntegerField(default=4) class Meta(Sortable.Meta): pass def __str__(self): return self.hebrew_name def get_absolute_url(self): return reverse('category', args=[self.subject.name ,self.name])
class MenuItem(SortableMixin, models.Model): LINK_TARGET_CHOICES = ( ('_blank', '_blank'), ('_top', '_top'), ('_parent', '_parent'), ) menu = SortableForeignKey('Menu', related_name='items', on_delete=models.CASCADE, verbose_name='Меню') name = models.CharField(max_length=255, verbose_name='Название') content_type = models.ForeignKey(ContentType, blank=True, null=True, on_delete=models.CASCADE, verbose_name='Тип контента') object_id = models.PositiveIntegerField(blank=True, null=True, verbose_name='ID обьекта') content_object = GenericForeignKey('content_type', 'object_id') link = models.CharField(max_length=255, blank=True, null=True, verbose_name='Произвольная ссылка') title = models.CharField(max_length=255, blank=True, null=True, verbose_name='Аттрибут title=') target = models.CharField(max_length=10, choices=LINK_TARGET_CHOICES, null=True, blank=True, verbose_name='Аттрибут target=') image = models.ImageField(upload_to='menu', blank=True, null=True, verbose_name='Картинка') show_in_menu = models.BooleanField(default=True, verbose_name='Отображать в меню') order = models.PositiveIntegerField(default=0, editable=False, db_index=True, verbose_name='Порядок') objects = MenuItemManager() def __str__(self): return self.name def get_medium_img(self): if self.image: return get_thumbnailer(self.image)['medium'].url else: return static('shop/no-image.webp') @property def get_url(self): if self.content_object: return self.content_object.get_absolute_url() else: return self.link def save(self, *args, **kwargs): if not self.title: self.title = self.name super(MenuItem, self).save(*args, **kwargs) class Meta: ordering = ['-order'] verbose_name = "Пункт меню" verbose_name_plural = "Пункты меню"