Esempio n. 1
0
class MarketplaceSettings(BaseSetting):
    couverture_marketplace = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text='Couverture de la marketplace')
    comment_ca_marche = models.ForeignKey(
        ContentPage,
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text='Lien vers la page de description du concept')

    menu_tag_1 = models.ForeignKey(Tag,
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+',
                                   help_text="")
    menu_tag_2 = models.ForeignKey(Tag,
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+',
                                   help_text="")
    menu_tag_3 = models.ForeignKey(Tag,
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+',
                                   help_text="")
    menu_tag_4 = models.ForeignKey(Tag,
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+',
                                   help_text="")
    menu_tag_5 = models.ForeignKey(Tag,
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+',
                                   help_text="")
    menu_tag_6 = models.ForeignKey(Tag,
                                   null=True,
                                   blank=True,
                                   on_delete=models.SET_NULL,
                                   related_name='+',
                                   help_text="")

    menu_label_1 = models.CharField(verbose_name='Label 1',
                                    max_length=30,
                                    null=True,
                                    blank=True)
    menu_url_1 = models.CharField(max_length=200, blank=True, null=True)

    menu_label_2 = models.CharField(verbose_name='Label 2',
                                    max_length=30,
                                    null=True,
                                    blank=True)
    menu_url_2 = models.CharField(max_length=200,
                                  verbose_name='URL 2',
                                  null=True,
                                  blank=True)

    menu_label_3 = models.CharField(verbose_name='Label 3',
                                    max_length=30,
                                    null=True,
                                    blank=True)
    menu_url_3 = models.CharField(max_length=200,
                                  verbose_name='URL 3',
                                  null=True,
                                  blank=True)

    panels = [
        ImageChooserPanel('couverture_marketplace'),
        PageChooserPanel('comment_ca_marche'),
        MultiFieldPanel(
            [
                FieldPanel('menu_tag_1'),
                FieldPanel('menu_tag_2'),
                FieldPanel('menu_tag_3'),
                FieldPanel('menu_tag_4'),
                FieldPanel('menu_tag_5'),
                FieldPanel('menu_tag_6'),
            ],
            heading="Tags produits barre menu",
            classname="collapsible",
        ),
        MultiFieldPanel([
            FieldPanel('menu_label_1'),
            FieldPanel('menu_url_1'),
            FieldPanel('menu_label_2'),
            FieldPanel('menu_url_2'),
            FieldPanel('menu_label_3'),
            FieldPanel('menu_url_3'),
        ],
                        heading="Liens additionnels barre menu",
                        classname="collapsible"),
    ]
Esempio n. 2
0
class TeacherProfile(index.Indexed, models.Model):

    # teacher profile fields
    user = models.OneToOneField(User, blank=False, null=True, related_name="teacher_profile",
                                on_delete=models.CASCADE,
                                help_text="Select user who is the teacher connected to this profile."
                                )
    full_name = models.CharField(max_length=200, null=True, blank=False,
                                 help_text="Enter teacher's full name."
                                 )
    teacher_bio = models.TextField(null=True, blank=True,
                                   help_text="Enter teacher's bio."
                                   )

    subjects = models.TextField(blank=True, null=True, help_text = "Enter the subjects you teach.")


    school_name = models.ForeignKey(SchoolProfile, blank=True, null=True,
                                    on_delete=models.SET_NULL,
                                    help_text="Select the school to which the teacher is connected."
                                    )
    grade_level = models.CharField(max_length=40, blank=False, null=True, choices=LEVEL,
                                   help_text="Enter the grade level the teacher instructs."
                                   )
    profile_image = models.ForeignKey(
        # image class being referenced
        "wagtailimages.Image",
        # allows to be null in db
        null=True,
        # requires when field out in form
        blank=True,
        # on delete on image set this value to null don't cascade'
        on_delete=models.SET_NULL,
        # No special related name
        related_name="+",
        help_text="Upload profile picture."

    )

    panels = [

        FieldPanel('school_name', widget=SchoolChooser),
        FieldPanel('user', widget=TeacherChooser),

        # FieldPanel('school_name'),
        # FieldPanel('user'),

        MultiFieldPanel(
            [
                FieldPanel('full_name'),
                FieldPanel('teacher_bio'),
                FieldPanel('grade_level'),
                FieldPanel('subjects'),
                ImageChooserPanel('profile_image'),
            ],
            heading="Teacher Information",
        ),
    ]

    # lesson_plans orderable?

    def __str__(self):
        return self.full_name or ''

    search_fields = [
        index.SearchField('user', partial_match=True),
    ]

    class Meta:
        verbose_name = ('Teacher profile')
        verbose_name_plural = ('Teacher profiles')
Esempio n. 3
0
class GalleryItem(WagtailCacheMixin, Page):

    subpage_types = []
    description = models.CharField(blank=True, max_length=250)
    direct_sale = models.BooleanField(
        "Direct Sale",
        default=False,
        help_text="Check this box to list this item for "
        "sale directly on your website.")
    direct_sale_price = models.DecimalField(
        "Sale price, $",
        blank=True,
        null=True,
        max_digits=6,
        decimal_places=2,
        help_text="Add more info about this item for the store page only.")
    direct_sale_extra_description = models.CharField(
        "Addtional sale description (optional)",
        blank=True,
        max_length=250,
    )
    stock = models.IntegerField(
        "Number in stock",
        blank=True,
        null=True,
    )
    external_sale = models.BooleanField(
        "External Sale",
        default=False,
        help_text="Check this box to add external sale links (ex. Society6).")
    sale_disclaimer = models.CharField(
        blank=True,
        null=True,
        max_length=250,
        default="Shipping within the U.S. is included in the price.")
    direct_sale_type = models.ForeignKey(
        'DirectSaleType',
        on_delete=models.SET_NULL,
        null=True,
        default=DirectSaleType.get_default_pk,
        help_text='What type of item are you selling? '
        'You can add more options in the Snippets menu.')
    # parent_page_types = ['InstallationPage']
    selected_main_shop_image = models.ForeignKey('GalleryImage',
                                                 null=True,
                                                 blank=True,
                                                 on_delete=models.SET_NULL)

    @property
    def on_sale(self, obj):
        return obj.external_sale or obj.direct_sale

    @property
    def main_image(self):
        if self.selected_main_shop_image:
            return self.selected_main_shop_image.image
        img = self.gallery_images.first()
        if img:
            return img.image
        return None

    @property
    def mediums(self):
        return self.get_parent().specific.mediums

    search_fields = Page.search_fields + [
        index.SearchField('title'),
        index.SearchField('description'),
    ]

    content_panels = Page.content_panels + [
        FieldPanel('description'),
        FieldPanel('external_sale'),
        MultiFieldPanel([
            InlinePanel('external_links',
                        label="External links (ex. Society6)"),
        ],
                        heading="Add external sale links"),
        FieldPanel('direct_sale'),
        MultiFieldPanel([
            FieldPanel('direct_sale_type'),
            FieldPanel('direct_sale_price'),
            FieldPanel('direct_sale_extra_description'),
            FieldPanel('stock'),
            FieldPanel('sale_disclaimer'),
        ],
                        heading="Add to shop (direct sale)"),
        InlinePanel('gallery_images', label="Gallery images"),
    ]

    def save(self, *args, **kwargs):
        if self.stock == 0:
            self.direct_sale = False

        return super(GalleryItem, self).save(*args, **kwargs)

    def clean(self):
        if self.direct_sale:
            if not self.stock:
                raise ValidationError("Please set this item's stock to one or "
                                      "more to list this item for sale.")
            elif self.stock < 1:
                raise ValidationError("Please set this item's stock to one or "
                                      "more to list this item for sale.")
            elif not self.direct_sale_price:
                raise ValidationError(
                    'Please set a price to list this item for sale.')
            elif self.direct_sale_price < 0.01:
                raise ValidationError(
                    'Please set a price to list this item for sale.')
        if self.external_sale and self.external_links.count() is None:
            raise ValidationError('Please add a least one external link, '
                                  'or uncheck "External Sale".')