class PersonPlaceholder(PersonBase): """Person with a Placeholder to edit content""" content_placeholder = PlaceholderField('content') class Meta: app_label = 'teams' abstract = True
class Category(TranslatableModel): class Meta: verbose_name = _('category') verbose_name_plural = _('categories') description = PlaceholderField('category_description') image = FilerImageField(blank=True, null=True, on_delete=models.SET_NULL) order = OrderField(blank=True, for_fields=[], default=1) translations = TranslatedFields( name=models.CharField(_('name'), blank=False, default='', db_index=True, help_text=_('Please supply the category name.'), max_length=128), slug=models.SlugField(_('slug'), blank=False, default='', db_index=True, help_text=_('Please supply the category slug.'), max_length=128) ) def save(self, *args, **kwargs): if not self.slug: self.slug = slugify('category-' + self.name + ' ' + get_language()) super(Category, self).save(*args, **kwargs) def get_absolute_url(self): with switch_language(self, get_language()): return reverse('shop:product_list_by_category', args=[self.slug]) def __str__(self): return str(self.order) + ". "+ self.name
class Section(TranslatableModel): class Meta: verbose_name = _('section') verbose_name_plural = _('sections') ordering = ['order'] description = PlaceholderField('section_description') course = models.ForeignKey(Course, on_delete=models.CASCADE, related_name='course_sections') order = OrderField(blank=True, for_fields=['course'], default=1) sections = GenericRelation(Action, related_query_name='sections') translations = TranslatedFields( name=models.CharField(_('name'), blank=False, default='', help_text=_('Please supply the section name.'), max_length=128), slug=models.SlugField(_('slug'), blank=True, default='', help_text=_('Please supply the section slug.'), max_length=128) ) # def get_absolute_url(self): # with switch_language(self, get_language()): # return reverse('courses:section_detail', kwargs={'slug': self.slug, }) def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.course.name + '-' + self.name + ' ' + get_language()) super(Section, self).save(*args, **kwargs) def get_edit_test_url(self): with switch_language(self, get_language()): return reverse('elearning:slug_edit_test_section', kwargs={'slug': self.course.slug, 'slug_section': self.slug, }) def __str__(self): return str(self.order) + ". " + self.name
class SquadPlaceholder(SquadBase): """Squad with a Placeholder to edit content""" content_placeholder = PlaceholderField('content') class Meta: app_label = 'teams' abstract = True
class Autoblock(models.Model): composite_id = models.CharField(max_length=150) content = PlaceholderField('content') site = models.ForeignKey(Site) def __unicode__(self): return self.composite_id
class Syllabus(TranslatableModel): class Meta: verbose_name = _('syllabus') verbose_name_plural = _('syllabus') description = PlaceholderField('syllabus_description') image = FilerImageField(blank=True, null=True, on_delete=models.SET_NULL) course = models.OneToOneField(Course, on_delete=models.CASCADE, related_name='syllabus') translations = TranslatedFields( name=models.CharField(_('name'), blank=False, default='', help_text=_('Please supply the syllabus name.'), max_length=128), slug=models.SlugField(_('slug'), blank=False, default='', help_text=_('Please supply the syllabus slug.'), max_length=128) ) def get_absolute_url(self): with switch_language(self, get_language()): print(self.slug) return reverse('courses:syllabus_detail', kwargs={'slug': self.slug, }) def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.course.name + '-' + self.name + ' ' + get_language()) super(Syllabus, self).save(*args, **kwargs) def __str__(self): return self.name
class Translations(models.Model): master = models.ForeignKey(MainModel) language_code = models.CharField(max_length=15, db_index=True) placeholder = PlaceholderField('translated', null=True) class Meta: unique_together = [('master', 'language_code')]
class Commodity(AvailableProductMixin, Product): """ This Commodity model inherits from polymorphic Product, and therefore has to be redefined. """ unit_price = MoneyField( _("Unit price"), decimal_places=3, help_text=_("Net price for this product"), ) product_code = models.CharField( _("Product code"), max_length=255, unique=True, ) quantity = models.PositiveIntegerField( _("Quantity"), default=0, validators=[MinValueValidator(0)], help_text=_("Available quantity in stock") ) # controlling the catalog placeholder = PlaceholderField("Commodity Details") show_breadcrumb = True # hard coded to always show the product's breadcrumb class Meta: verbose_name = _("Commodity") verbose_name_plural = _("Commodities") default_manager = ProductManager() def get_price(self, request): return self.unit_price
class Membership(Product): """ This Commodity model inherits from polymorphic Product, and therefore has to be redefined. """ unit_price = MoneyField( _("Unit price"), decimal_places=3, help_text=_("Net price for this product"), ) product_code = models.CharField( _("Product code"), max_length=255, unique=True, ) signup_date = models.DateField( _("Signed Up"), default=timezone.now, ) profile = models.ForeignKey(User, null=True, blank=True) # controlling the catalog placeholder = PlaceholderField("Membership Details") show_breadcrumb = True # hard coded to always show the product's breadcrumb class Meta: verbose_name = _("Membership") def get_price(self, request): return self.unit_price
class Commodity(Product): """ This Commodity model inherits from polymorphic Product, and therefore has to be redefined. """ unit_price = MoneyField( _("Unit price"), decimal_places=3, help_text=_("Net price for this product"), ) product_code = models.CharField( _("Product code"), max_length=255, unique=True, ) # controlling the catalog placeholder = PlaceholderField("Commodity Details") show_breadcrumb = True # hard coded to always show the product's breadcrumb default_manager = TranslatableManager() class Meta: verbose_name = _("Commodity") verbose_name_plural = _("Commodities") def get_price(self, request): return self.unit_price
class Product(TranslatableModel): class Meta: verbose_name = _('product') verbose_name_plural = _('products') description = PlaceholderField('product_description') image = FilerImageField(blank=True, null=True, on_delete=models.SET_NULL, related_name='product_image') order = OrderField(blank=True, for_fields=[], default=1) category = models.ForeignKey(Category, related_name='products', on_delete=models.CASCADE) price = models.DecimalField(max_digits=10, decimal_places=2) available = models.BooleanField(default=True) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) translations = TranslatedFields( name=models.CharField(_('name'), blank=False, default='', db_index=True, help_text=_('Please supply the product name.'), max_length=128), slug=models.SlugField(_('slug'), blank=False, default='', db_index=True, help_text=_('Please supply the product slug.'), max_length=128) ) def save(self, *args, **kwargs): if not self.slug: self.slug = slugify('product-' + self.name + ' ' + get_language()) super(Product, self).save(*args, **kwargs) def get_absolute_url(self): with switch_language(self, get_language()): return reverse('shop:product_detail', kwargs={'slug': self.slug, }) def __str__(self): return str(self.order) + ". "+ self.name
class Example1(models.Model): char_1 = models.CharField(u'char_1', max_length=255) char_2 = models.CharField(u'char_2', max_length=255) char_3 = models.CharField(u'char_3', max_length=255) char_4 = models.CharField(u'char_4', max_length=255) date_field = models.DateField(null=True) placeholder = PlaceholderField('placeholder') static_admin_url = '' def __init__(self, *args, **kwargs): super(Example1, self).__init__(*args, **kwargs) def callable_item(self, request): return self.char_1 def __str__(self): return self.char_1 def get_absolute_url(self): return reverse("example_detail", args=(self.pk,)) def set_static_url(self, request): language = get_language_from_request(request) if self.pk: self.static_admin_url = reverse('admin:placeholderapp_example1_edit_field', args=(self.pk, language)) return self.pk def dynamic_url(self, request): language = get_language_from_request(request) return reverse('admin:placeholderapp_example1_edit_field', args=(self.pk, language))
class PlaceholderReference(CMSPlugin): cmsplugin_ptr = models.OneToOneField( CMSPlugin, related_name='cms_placeholderreference', parent_link=True) name = models.CharField(max_length=255) placeholder_ref = PlaceholderField(slotname='clipboard') class Meta: app_label = 'cms' def __str__(self): return self.name def copy_to(self, placeholder, language): copy_plugins_to(self.placeholder_ref.get_plugins(), placeholder, to_language=language) def copy_from(self, placeholder, language): copy_plugins_to(placeholder.get_plugins(language), self.placeholder_ref, to_language=self.language) def move_to(self, placeholder, language): for plugin in self.placeholder_ref.get_plugins(): plugin.placeholder = placeholder plugin.language = language plugin.save() def move_from(self, placeholder, language): for plugin in placeholder.get_plugins(): plugin.placeholder = self.placeholder_ref plugin.language = language plugin.save()
class Service(models.Model): class Meta: verbose_name = _('service') verbose_name_plural = _('services') ordering = ['order'] portfolio_web = models.ForeignKey(PortfolioWeb, on_delete=models.CASCADE, default=1, related_name='services') order = models.IntegerField(default=1000, blank=True) image = models.ImageField(upload_to='services/', blank=True, null=True) heading = models.CharField(max_length=100, null=True) description = models.CharField(max_length=500, null=True) is_active = models.BooleanField(default=True) full_description = PlaceholderField('full_description') name_text_color = models.CharField(max_length=30, default='#090909', null=True) name_gradient_deg = models.IntegerField(default=285, blank=True) gradient_color_1 = models.CharField(max_length=30, default='#969696', null=True) gradient_color_2 = models.CharField(max_length=30, default='#dfdfdf', null=True)
class Stack(models.Model): name = models.CharField( verbose_name=_(u'stack name'), max_length=255, blank=True, default='', help_text=_( u'Descriptive name to identify this stack. Not displayed to users.' )) code = models.CharField(verbose_name=_(u'stack code'), max_length=255, unique=True, blank=True, help_text=_(u'To render the stack in templates.')) content = PlaceholderField(slotname=u'stack_content', verbose_name=_(u'stack content'), related_name='stacks_contents') class Meta: verbose_name = _(u'stack') verbose_name_plural = _(u'stacks') def __unicode__(self): return self.name def clean(self): # TODO: check for clashes if the random code is already taken if not self.code: self.code = u'stack-%s' % uuid.uuid4()
class EntryPlaceholder(EntryAbstractClass): """Entry with a Placeholder to edit content""" content_placeholder = PlaceholderField('content') #dm placeholder_render = models.TextField(_('Placeholder render'), blank=True, null=True) page_link = PageField(verbose_name=_('page link'), null=True, blank=True) @property def html_content(self): """No additional formatting is necessary""" if self.placeholder_render: #dm return self.placeholder_render original = super(EntryPlaceholder, self).html_content return original class Meta(EntryAbstractClass.Meta): """EntryPlaceholder's Meta""" abstract = True #dm def get_absolute_url(self): """Return entry's URL""" if self.page_link: return self.page_link.get_absolute_url() else: return '/archivio/%s/%s/%s/%s' % ( self.creation_date.strftime('%Y'), self.creation_date.strftime('%m'), self.creation_date.strftime('%d'), self.slug)
class CharPksExample(models.Model): char_1 = models.CharField(u'char_1', max_length=255) slug = models.SlugField(u'char_1', max_length=255, primary_key=True) placeholder_1 = PlaceholderField('placeholder_1', related_name='charpk_p1') def __str__(self): return "%s - %s" % (self.char_1, self.pk)
class Partners(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='partners') order = OrderField(blank=True, for_fields=[], default=1) organization_name = models.CharField(max_length=128, default='') address1 = models.CharField(max_length=128, blank=True, null=True) address2 = models.CharField(max_length=128, blank=True, null=True) email = models.EmailField() city = models.CharField(max_length=128, default='') country = models.CharField(max_length=128, default='') office_phone = models.CharField(max_length=128, default='') cell_phone = models.CharField(max_length=128, default='') owner_image = models.ImageField(upload_to='partners/%Y/%m/%d/', blank=True, null=True) organization_image = models.ImageField(upload_to='partners/%Y/%m/%d/', blank=True, null=True) description = PlaceholderField('partner_description') slug = models.SlugField(max_length=250, null=True) def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.owner.get_full_name() + '-' + self.id) super(Partners, self).save(*args, **kwargs) def get_absolute_url(self): return reverse('partners:partner_detail', kwargs={'slug': self.slug}) def __str__(self): return self.owner.get_full_name()
class StudyEntity(models.Model): class Meta: verbose_name = "Entity that publishes studies" verbose_name_plural = "Entities that publish studies" #one-to-one link to contacts_and_people.Person entity = models.OneToOneField('contacts_and_people.Entity', primary_key=True, related_name="study_entity", help_text=""" Do not under any circumstances change this field. No, really. Don't touch this. """) # in this case, publish_page must be selected in order for the menu to be # created. This is determined by the menu.StudyMenu class. Similarly, its # menu_title is also configurable here. publish_page = models.BooleanField( u"Publish an automatic clinical studies page", default=False, ) menu_title = models.CharField(u"Title", max_length=50, default="Clinical studies") # each entity's main clinical studies page can have a placeholder for # django CMS plugins, if wanted studies_page_intro = PlaceholderField( 'body', related_name="studies_page_intro", ) # we just get the name from the entity def __unicode__(self): return self.entity.__unicode__()
class Category(CategorizationModel): translations = _categorization_translated_fields() content = PlaceholderField('shopit_category_content') _tax = models.ForeignKey( Tax, models.SET_NULL, blank=True, null=True, verbose_name=_('Tax'), help_text= _("Tax to be applied to products in this category. If empty, parent's tax will be used." )) class Meta: db_table = 'shopit_categories' verbose_name = _('Category') verbose_name_plural = _('Categories') ordering = ['tree_id', 'lft'] @property def tax(self): if not self._tax and self.parent: return self.parent.tax return self._tax @tax.setter def tax(self, value): self._tax = value
class Person(models.Model): id = models.CharField( "ID", help_text= "ID, all lowercase and alphanumeric only, no spaces, will appear in URL like this", max_length=100, primary_key=True) firstname = models.CharField("First name", max_length=50) lastname = models.CharField("Last name", max_length=60) title = models.CharField("Title(s)", max_length=255, blank=True) nickname = models.CharField("Nickname", max_length=50, blank=True) affiliation = models.CharField("Affiliation", max_length=255, blank=True) function = models.CharField("Function", max_length=25, choices=sorted(PERSON_FUNCTIONS.items(), key=lambda x: x[1])) function2 = models.CharField("Secondary function", max_length=25, choices=sorted(PERSON_FUNCTIONS.items(), key=lambda x: x[1]), blank=True) interests = models.CharField("Interests", max_length=255, blank=True) email = models.CharField("E-mail", max_length=60) website = models.URLField("Website", max_length=60, blank=True) twitter = models.CharField("Twitter", max_length=60, blank=True) room = models.CharField("Room", max_length=60, blank=True) phone = models.CharField("Phone", max_length=60, blank=True) birth_date = models.DateField(blank=True, null=True) joined_date = models.DateField(blank=True, null=True) left_date = models.DateField(null=True, blank=True) description = models.TextField( "Description", help_text= "A short description about the person. For more text, use the content field.", blank=True) image = models.ImageField( "Avatar", help_text= "A 120x160 picture of the person, if not specified, you will be punished and a random llama will be shown.", upload_to='avatars/', blank=True, null=True) publications = models.ManyToManyField(Publication, blank=True) content = PlaceholderField('content') def __unicode__(self): return self.fullname() def getrandomlama(self): return settings.STATIC_URL + "/lama" + str(random.randint(1, 6)) + ".jpg" def fullname(self): return self.firstname + " " + self.lastname def initialsname(self): return self.firstname[0] + ". " + self.lastname class Meta: ordering = ['joined_date', 'firstname', 'lastname']
class NodetypePlaceholder(Nodetype): """Nodetype with a Placeholder to edit content""" content_placeholder = PlaceholderField('content') class Meta: """NodetypePlaceholder's Meta""" abstract = True
class GbobjectPlaceholder(GbobjectAbstractClass): """Gbobject with a Placeholder to edit content""" content_placeholder = PlaceholderField('content') class Meta: """GbobjectPlaceholder's Meta""" abstract = True
class EntryPlaceholder(EntryAbstractClass): """Entry with a Placeholder to edit content""" content_placeholder = PlaceholderField('content') class Meta: """EntryPlaceholder's Meta""" abstract = True
class JobsConfig(AppHookConfig): # Job PHFs placeholder_jobs_top = PlaceholderField('jobs_top', related_name='aldryn_jobs_top') placeholder_jobs_sidebar = PlaceholderField( 'jobs_sidebar', related_name='aldryn_jobs_sidebar') # Job detail PHFs placeholder_jobs_detail_top = PlaceholderField( 'jobs_detail_top', related_name='aldryn_jobs_detail_top') placeholder_jobs_detail_bottom = PlaceholderField( 'jobs_detail_bottom', related_name='aldryn_jobs_detail_bottom') placeholder_jobs_detail_footer = PlaceholderField( 'jobs_detail_footer', related_name='aldryn_jobs_detail_footer') # Jobs list PHFs placeholder_jobs_list_top = PlaceholderField( 'jobs_list_top', related_name='aldryn_jobs_list_top') placeholder_jobs_list_bottom = PlaceholderField( 'jobs_list_bottom', related_name='aldryn_jobs_list_bottom') class Meta: verbose_name = _('Aldryn Jobs configuration') verbose_name_plural = _('Aldryn Jobs configurations')
class Manufacturer(CategorizationModel): translations = _categorization_translated_fields() content = PlaceholderField('shopit_manufacturer_content') class Meta: db_table = 'shopit_manufacturers' verbose_name = _('Manufacturer') verbose_name_plural = _('Manufacturers') ordering = ['tree_id', 'lft']
class Message(models.Model): message = PlaceholderField('message') def __str__(self): return self.message class Meta: verbose_name = 'Message' verbose_name_plural = 'Messages'
class ContactUs(models.Model): town = models.OneToOneField(Towns, on_delete=models.CASCADE, related_name='town_contact_us') description = PlaceholderField('description') def __str__(self): return self.town.town_name
class Commodity(CMSPageReferenceMixin, TranslatableModelMixin, BaseProduct): """ Generic Product Commodity to be used whenever the merchant does not require product specific attributes and just required a placeholder field to add arbitrary data. """ # common product fields product_code = models.CharField(_("Product code"), max_length=255, unique=True) unit_price = MoneyField(_("Unit price"), decimal_places=3, help_text=_("Net price for this product")) # controlling the catalog order = models.PositiveIntegerField(verbose_name=_("Sort by"), db_index=True) cms_pages = models.ManyToManyField( 'cms.Page', through=ProductPage, help_text=_("Choose list view this product shall appear on.")) sample_image = image.FilerImageField( verbose_name=_("Sample Image"), blank=True, null=True, help_text=_("Sample image used in the catalog's list view.")) show_breadcrumb = models.BooleanField( _("Show Breadcrumb"), default=True, help_text=_( "Shall the detail page show the product's breadcrumb.")) placeholder = PlaceholderField("Commodity Details") # translatable fields for the catalog's list- and detail views product_name = TranslatedField() slug = TranslatedField() caption = TranslatedField() # filter expression used to search for a product item using the Select2 widget lookup_fields = ( 'product_code__startswith', 'product_name__icontains', ) objects = ProductManager() class Meta: app_label = app_settings.APP_LABEL ordering = ('order', ) verbose_name = _("Commodity") verbose_name_plural = _("Commodities") def __str__(self): return self.product_code def get_price(self, request): return self.unit_price
class MultilingualExample1(TranslatableModel): translations = TranslatedFields( char_1=models.CharField(u'char_1', max_length=255), char_2=models.CharField(u'char_2', max_length=255), ) placeholder_1 = PlaceholderField('placeholder_1') def __unicode__(self): return self.char_1