class Event(TranslatableModel): code = models.CharField(verbose_name=_(u'Code'), max_length=1000) starts_at = models.DateTimeField(verbose_name=_('Starts at'), db_index=True) place = models.ForeignKey(Place) program = models.ForeignKey(Program, null=True, blank=True) translations = TranslatedFields( name=models.CharField(verbose_name=_(u'Name'), max_length=1000), description=models.TextField(verbose_name=_('Description'), blank=True, null=True)) __unicode__ = lambda self: self.code
class StoryCategoryHeader(TranslatableModel): name = models.CharField(max_length=100) slug = models.SlugField(max_length=100) background_image = models.FileField( upload_to="uploads/story-category-header/images/%Y/%m/%d") translations = TranslatedFields( category_name=models.CharField(max_length=255, verbose_name=u'* Category Name'), category_description=models.TextField( verbose_name=u'* Category Description')) def __unicode(self): return self.name
class Institucio(TranslatableModel): nom = models.CharField(_('name'), max_length=50) nom_curt = models.SlugField(_('short name'), max_length=10) url = models.CharField('URL', max_length=100) translations = TranslatedFields(descripcio=models.TextField( _('description')), ) class Meta: verbose_name = _('institution') verbose_name_plural = _('institutions') def __unicode__(self): return self.nom_curt.upper()
class OfferingStatus(TranslationModelMixin, TranslatableModel): """ Master data containing all offering status. For translatable fields check ``OfferingStatusTranslation``. :slug: A unique slug identifier. translated: :name: The displayable name for the status. """ slug = models.SlugField(verbose_name=_('Slug'), ) translations = TranslatedFields(name=models.CharField( verbose_name=_('Name'), max_length=128, ))
class BaseCategory(TranslatableModel): translations = TranslatedFields( title=models.CharField(max_length=200), description=models.TextField(blank=True, null=True, default=""), slug=models.SlugField(), ) class Meta: abstract = True unique_together = [("title", "language_code")] verbose_name_plural = "categories" def __str__(self): return self.title
class TeamBannerTranslationModel(TranslatableModel): translations = TranslatedFields( members=models.CharField(max_length=255, default="members"), member_description=models.CharField(max_length=255), member_more_detail=models.CharField(max_length=255, default="More details"), ) def __str__(self): return str(self.lazy_translation_getter('members', self.pk)) class Meta: verbose_name = "TeamBanner Translation model" verbose_name_plural = "TeamBanner Translation models"
class Sector(TranslatableModel): """ Holds information about the sector of the practice. For translatable fields see ``SectorTranslation``. """ translations = TranslatedFields(name=models.CharField( verbose_name=_('Name'), max_length=256, )) def __unicode__(self): return self.safe_translation_getter('name', 'Untranslated sector')
class Reference(TranslatableModel): translations = TranslatedFields( donor_name=models.CharField(max_length=200), donor_title=models.CharField(max_length=200), reference_text=PlaceholderField('ph_reference_text')) donor_logo = models.ImageField(upload_to=give_file_name) donor_detail_img = models.ImageField(upload_to=give_file_name) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.lazy_translation_getter('name', 'MyMode: %s' % self.donor_name)
class GoodPracticeExample(TranslatableModel): """ Contains the information about a certain practice. For translatable fields see ``GoodPracticeExampleTranslation``. :description: The description of the good practice. :goals: The goals of this practice. :sectors: The sectors of this practice. :countries: The countries this practice takes place. translated: :title: A short title for the practice. :is_published: True, if the practice should show up. """ practice_description = PlaceholderField( 'good_practice_example_practice_description', related_name='goodpracticeexamples', ) goals = models.ManyToManyField( 'good_practice_examples.Goal', verbose_name=_('Goals'), ) sectors = models.ManyToManyField( 'good_practice_examples.Sector', verbose_name=_('Sectors'), ) countries = models.ManyToManyField( 'good_practice_examples.Country', verbose_name=_('Countries'), ) translations = TranslatedFields(title=models.CharField( verbose_name=_('Title'), max_length=256, ), is_published=models.BooleanField( verbose_name=_('Is published'), default=False, )) objects = HvadPublishedManager() def __unicode__(self): return self.safe_translation_getter('title', 'Untranslated example')
class Experiment(TranslatableModel): objects = ExperimentManager() class Meta: ordering = ['order'] translations = TranslatedFields( title=models.CharField(max_length=128), short_title=models.CharField(max_length=60, blank=True, default=''), description=models.TextField(), measurements=MarkupField(blank=True, default='', default_markup_type='plain'), introduction=MarkupField(blank=True, default='', default_markup_type='markdown'), ) slug = models.SlugField(max_length=128, unique=True, db_index=True) thumbnail = models.ImageField(upload_to=experiment_thumbnail_upload_to) xpi_url = models.URLField() version = models.CharField(blank=True, max_length=128) order = models.IntegerField(default=0) changelog_url = models.URLField(blank=True) contribute_url = models.URLField(blank=True) bug_report_url = models.URLField(blank=True) discourse_url = models.URLField(blank=True) privacy_notice_url = models.URLField(blank=True) addon_id = models.CharField( max_length=500, blank=False, ) gradient_start = ColorField(default='#e07634') gradient_stop = ColorField(default='#4cffa8') contributors = models.ManyToManyField(User, related_name='contributor') created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) @cached_property def installation_count(self): return UserInstallation.objects.filter(experiment=self).count() def __str__(self): return self.title def natural_key(self): return (self.slug, )
class FlatPage(TranslatableModel): name = models.CharField(_('Name'), max_length=100) translations = TranslatedFields( slug=models.CharField(_('slug'), max_length=100, db_index=True), title=models.CharField(_('title'), max_length=200), content=models.TextField(_('content'), blank=True), ) enable_comments = models.BooleanField(_('enable comments'), default=False) template_name = models.CharField( _('template name'), max_length=70, blank=True, help_text=_( "Example: 'multilingual_flatpages/contact_page.html'. If this isn't provided, " "the system will use 'multilingual_flatpages/default.html'."), ) registration_required = models.BooleanField( _('registration required'), help_text= _("If this is checked, only logged-in users will be able to view the page." ), default=False, ) sites = models.ManyToManyField(Site, verbose_name=_('sites')) class Meta: app_label = "multilingual_flatpages" verbose_name = _('flat page') verbose_name_plural = _('flat pages') ordering = ('slug', ) def __str__(self): return "%s -- %s" % (self.slug, self.title) def get_absolute_url(self): # Handle script prefix manually because we bypass reverse() if self.slug.startswith("/"): slug = self.slug[1:] else: slug = self.slug return reverse('multilingual_flatpages', args=[slug]) def get_translation_url(self, lang): old_lang = get_language() activate(lang) translation = FlatPage.objects.language(lang).get(id=self.id) url = translation.get_absolute_url() activate(old_lang) return url
class MicroAlerta(TranslatableModel): data = models.DateTimeField(_('date')) creat = models.DateTimeField(_('created'), auto_now_add=True) actualizat = models.DateTimeField(_('updated'), auto_now=True) translations = TranslatedFields(alerta=models.TextField(_('alert')), ) class Meta: verbose_name = _('microalert') verbose_name_plural = _('microalerts') ordering = ['-data'] def __unicode__(self): return self.alerta
class TeamDisplayTranslationModel(TranslatableModel): translations = TranslatedFields( teams_title=models.CharField(max_length=255, default="Teams"), all=models.CharField(max_length=255, default="All"), members_title=models.CharField(max_length=255, default="Members"), projects_title=models.CharField(max_length=255, default="Projects"), formation_title=models.CharField(max_length=255, default="Formation"), ) def __str__(self): return str(self.lazy_translation_getter('teams_title', self.pk)) class Meta: verbose_name = "TeamDisplay Translation model" verbose_name_plural = "TeamDisplay Translation models"
class Topic(TranslatableModel): """ A topic is a project type, aka. Template. """ untranslated_name = models.CharField(_("Untranslated name"), max_length=128, default='New topic') slug = AutoSlugField(populate_from="untranslated_name", always_update=True, unique=True) translations = TranslatedFields( label=models.CharField("Label", max_length=512)) def __unicode__(self): return self.untranslated_name
class ConcreteAB(AbstractAA, AbstractB): shared_field_ab = models.CharField(max_length=255) translations = TranslatedFields( translated_field_ab=models.CharField(max_length=255), ) def __str__(self): return '%s, %s, %s' % ( str( self.safe_translation_getter('translated_field_a', self.shared_field_a)), self.safe_translation_getter('translated_field_b', str(self.shared_field_b)), self.safe_translation_getter('translated_field_ab', self.shared_field_ab), )
class TranslatedMany(TranslatableModel): """ WARNING: this is not officially supported. This test model is more of a monitor so we know what we break, than a promise not to break it. """ name = models.CharField(max_length=128) translations = TranslatedFields( translated_field=models.CharField(max_length=128), many=models.ManyToManyField(Normal, related_name='translated_many'), ) def __str__(self): return ('%s, %s <%s>' % (self.name, self.translated_field, self.language_code) if get_cached_translation(self) is not None else '%s <none>' % self.name)
class DiscoverItem(APIModelMixin, TranslatedModelFallbackMixin, TranslatableModel, MPTTModel, UUIDModel): title = models.CharField(max_length=100) subtitle = models.CharField(max_length=100, blank=True) description = models.CharField(max_length=100, blank=True) position = models.PositiveSmallIntegerField() countries = CountriesField() image = models.URLField(blank=True, default='') cover = models.URLField(blank=True, default='') icon = models.URLField(blank=True, default='') parent = TreeForeignKey('self', null=True, blank=True, related_name='children') show_children = models.BooleanField(default=True) shouts_query = HStoreField(blank=True) show_shouts = models.BooleanField(default=False) objects = TranslationTreeManager() class Meta: unique_together = ('countries', 'position', 'parent') # Todo (mo): Remove position, ordering can be done using mptt attrs class MPTTMeta: order_insertion_by = ['position'] translations = TranslatedFields( _local_title=models.CharField(max_length=30, blank=True, default=''), _local_sub_title=models.CharField(max_length=60, blank=True, default=''), _local_description=models.CharField(max_length=100, blank=True, default='')) def __unicode__(self): return "%s in %s" % (self.title, filter(None, self.countries)) @property def parents(self): return self.get_ancestors() @property def children(self): return self.get_children()
class BaseMediaFolder(TranslatableModel): translations = TranslatedFields( description=models.CharField(max_length=200, blank=True, null=True), title=models.CharField(max_length=200, blank=True, null=True), ) slug = models.SlugField() creation_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True) icon = models.ForeignKey( "camomilla.Media", on_delete=models.SET_NULL, null=True, blank=True, verbose_name=_("Image cover"), ) path = models.TextField(blank=True, null=True) updir = models.ForeignKey( "self", on_delete=models.CASCADE, related_name="child_folders", null=True, blank=True, ) class Meta: abstract = True def update_childs(self): for folder in self.child_folders.all(): folder.save() def save(self, *args, **kwargs): if self.updir: if self.updir.id == self.id: raise ValidationError({"updir": "Unvalid parent"}) self.path = "{0}/{1}".format(self.updir.path, self.slug) else: self.path = "/{0}".format(self.slug) super(BaseMediaFolder, self).save(*args, **kwargs) self.update_childs() def __str__(self): to_string = self.slug if self.title: to_string += " - " + self.title return to_string
class ExperimentNotification(TranslatableModel): experiment = models.ForeignKey('Experiment', related_name='notifications', db_index=True) translations = TranslatedFields( title=models.CharField(max_length=128), text=models.CharField(max_length=256) ) notify_after = models.DateTimeField(null=True, blank=True, default=None) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) class Meta: ordering = ('experiment', 'modified',)
class Title(TranslatableModel): """ Title Model """ translations = TranslatedFields(title=models.CharField( _('title'), help_text=_("to be translated"), max_length=255), ) anchor = models.CharField(_('anchor'), help_text=_("don't translate"), max_length=255, unique=True) def __unicode__(self): try: return self.title except: return self.anchor
class Project(TranslatableModel): name = models.CharField(max_length=100, blank=False) translations = TranslatedFields(description=models.TextField(null=True)) status = models.ForeignKey(ProjectStatus, default=0, on_delete=models.SET_DEFAULT) website = models.CharField(max_length=200, blank=True, null=True) display_order = models.IntegerField(blank=False, null=False, default=0) display_banner_height = models.IntegerField(blank=False, null=False, default=0) def __str__(self): return self.name
class Related(TranslatableModel): """ Model with foreign keys to Normal, both shared and translatable """ normal = models.ForeignKey(Normal, related_name='rel1', null=True, on_delete=models.CASCADE) translated_fields = TranslatedFields( translated=models.ForeignKey(Normal, related_name='rel3', null=True, on_delete=models.CASCADE), translated_to_translated=models.ForeignKey(Normal, related_name='rel4', null=True, on_delete=models.CASCADE), )
class Tag(TranslatableModel): name = models.CharField(max_length=100, unique=True) slug = models.SlugField() translations = TranslatedFields(translated_name=models.CharField( max_length=100, verbose_name=u"* Translated Name (shown on website)")) def __unicode__(self): return "Tag: " + self.name @staticmethod def autocomplete_search_fields(): return ( "id__iexact", "name__icontains", )
class ArticleChapter(TranslatableModel): creation_date = models.DateField(auto_now_add=True) last_modified = models.DateField(auto_now=True) name = models.CharField(max_length=200) slug = models.SlugField() related_stories = models.ManyToManyField('ArticlePage', verbose_name=u'Related Stories', blank=True, null=True) videos = models.ManyToManyField(Video, verbose_name=u'Related Videos', blank=True, null=True) pano_head = models.FileField( upload_to='uploads/article/pano_head/%Y/%m/%d', blank=True, null=True, verbose_name=u'Chapter Heading Pano Image') translations = TranslatedFields( headline=models.CharField(max_length=255, verbose_name=u'* Title/Headline'), subheadline=models.CharField(max_length=255, blank=True, null=True, verbose_name=u'* Subheadline (Optional)'), body_text=models.TextField(verbose_name=u'* Description'), quote=models.TextField(blank=True, null=True, verbose_name=u'* Quote (Optional)'), quote_attribution=models.TextField( blank=True, null=True, verbose_name=u'* Attribution (Optional)'), interactives=models.ManyToManyField( Interactive, verbose_name=u'Interactive or Infographic', blank=True, null=True), ) def __unicode__(self): return self.name @staticmethod def autocomplete_search_fields(): return ( "id__iexact", "name__icontains", )
class News(TranslatableModel): def _get_size(self): return self.lazy_translation_getter('title', unicode(self.pk)) ts_add = models.DateTimeField(_('date added'), auto_now=False, auto_now_add=True) ts_edit = models.DateTimeField(_('last update'), auto_now=True, auto_now_add=True) translations = TranslatedFields( title=models.CharField(_('title'), max_length=255), subtitle1=models.CharField(_('subtitle 1'), max_length=255), subtitle2=models.CharField(_('subtitle 2'), max_length=255), content=RichTextField(_('content'), config_name='basic_ckeditor', blank=True, null=True), ) published = models.BooleanField( _('published'), default=True, help_text= _("The same for all translations. Si consiglia 250x250 pixel, PNG o JPG." )) picture = models.ImageField( _('picture'), blank=True, null=True, upload_to='news', help_text= _("The same for all translations. Si consiglia 640x480 pixel con soggetto centrale, PNG o JPG. ATTENZIONE: la visualizzazione cambia da dispositivo a dispositivo." )) def __unicode__(self): return self.lazy_translation_getter('title', unicode(self.pk)) def get_absolute_url(self): return reverse('montecatini_news.views.news', None, [ self.id, ]) class Meta(): ordering = ('-ts_add', ) verbose_name = _('news') verbose_name_plural = _('news_plural')
class LangSkillVal(models.Model): """ This is a set of language skill vals in europass format. * A1 - very basic knowleges * A2 - beginer * B1 - can understand something * B2 - can understand more * C1 - profy * C2 - almost nativ user """ #: The title of language skill as indicated in comment before. Not for editing. title = models.CharField(max_length=2) translations = TranslatedFields(description=models.CharField( max_length=128, blank=True, null=True), ) def __unicode__(self): return self.title
class Ability(TranslatableModel): """ Skills """ translations = TranslatedFields(title=models.CharField(max_length=128), comment=models.CharField(max_length=1024)) """translated title and comments for skills. :param title: The name of skill (like Vectorial graphic or Text Processing) :type title: str or unicode :param comment: The explanetion of skill (like Adobe Illustrator, Inkscape, good knowleges of MS Word etc.) :type comment: str or unicode""" #: the linked :py:class:`udata.models.Human` human = models.ForeignKey(Human) def __unicode__(self): return self.title
class Event(TranslatableModel, models.Model): codename = models.CharField(max_length=256, unique=True) start = models.DateTimeField() end = models.DateTimeField() translations = TranslatedFields( name=models.CharField(max_length=512), description=models.TextField(), subscription_motivator=models.TextField(), ) class Meta: verbose_name = _('Event') verbose_name_plural = _('Events') def __unicode__(self): return self.safe_translation_getter('name', str(self.pk))
class Tech(TranslatableModel): icon = models.ImageField(null=True, blank=True, upload_to="technology-icons", storage=S3Storage()) translations = TranslatedFields(title=models.CharField(max_length=255), description=models.TextField(null=True, blank=True)) order = models.IntegerField(blank=True, default=0) class Meta: ordering = ['order'] def __unicode__(self): return self.title
class Services(CoreObject, TranslatableModel): SOCIAL_CHOICES = ( ('legal', 'legal'), ('info', 'info'), ('users', 'users'), ('suitcase', 'suitcase'), ('university', 'university'), ('pencil', 'pencil'), ('rocket', 'rocket'), ) display = models.CharField(max_length=20, choices=SOCIAL_CHOICES, default='rocket') #image = models.ImageField(_('Service Image'),upload_to = storage.hashed_upload_to('image'), null=True,blank=True)#default = 'images/None/default.jpg' translations = TranslatedFields( title=models.CharField(_('Service Title'), max_length=100, db_index=True), service_description=models.TextField( _('Service Description Field'), help_text=_('please insert some description here'), blank=True), ) class Meta: verbose_name = _('Service') verbose_name_plural = _('Services') def save(self, *args, **kwargs): try: this = Services.objects.get(id=self.id).image if this and this != self.image: this.delete(save=False) except: pass super(Services, self).save(*args, **kwargs) def delete(self, *args, **kwargs): if self.image: os.remove(self.image.path) super(Services, self).delete(*args, **kwargs) def __unicode__(self): return self.safe_translation_getter('title', )