Example #1
0
class Categorie(models.Model):
    name = models.CharField(max_length=50, unique=True, default='')
    slug = models.SlugField(unique=True, max_length=50, default='')
    desc = models.CharField(max_length=50, default='')
    amazon_nodeid = models.CharField(max_length=50)
    amazon_index = models.CharField(max_length=50)
    image = StdImageField(
        upload_to=UploadToAutoSlug(populate_from='name'),
        variations={'thumbnail': {
            "width": 300,
            "height": 300,
            "crop": True
        }})
    is_top_display = models.BooleanField(default=False)
    date_creation = models.DateTimeField(auto_now_add=True)
    date_update = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.name

    #@models.permalink
    def get_absolute_url(self):
        return reverse(
            'shopping:categories_detail',
            args=[self.amazon_index, self.amazon_nodeid, self.slug, 1])
Example #2
0
class Calendar(NationBuilderResource, ImageMixin):
    objects = CalendarManager()

    name = models.CharField(_("titre"), max_length=255)
    slug = models.SlugField(_("slug"))

    user_contributed = models.BooleanField(
        _('Les utilisateurs peuvent ajouter des événements'), default=False)

    description = models.TextField(
        _('description'),
        blank=True,
        help_text=_("Saisissez une description (HTML accepté)"))

    image = StdImageField(
        _("bannière"),
        upload_to=UploadToAutoSlug("name", path="events/calendars/"),
        variations={
            'thumbnail': (400, 250),
            'banner': (1200, 400),
        },
        blank=True,
    )

    class Meta:
        verbose_name = 'agenda'

    def __str__(self):
        return self.name
Example #3
0
class Person(TimeStampedModel):
    """ Person model. """
    uuid = models.UUIDField(blank=False,
                            null=False,
                            default=uuid4,
                            editable=False,
                            verbose_name=_('UUID'))
    partner = models.ForeignKey(Partner, null=True, blank=False)
    given_name = models.CharField(max_length=255)
    family_name = models.CharField(max_length=255, null=True, blank=True)
    bio = models.TextField(null=True, blank=True)
    profile_image_url = models.URLField(null=True, blank=True)
    profile_image = StdImageField(
        upload_to=UploadToAutoSlug(populate_from='uuid',
                                   path='media/people/profile_images'),
        blank=True,
        null=True,
        variations={
            'medium': (110, 110),
        },
    )
    slug = AutoSlugField(populate_from=('given_name', 'family_name'),
                         editable=True)
    profile_url = models.URLField(null=True, blank=True)
    email = models.EmailField(null=True, blank=True, max_length=255)

    class Meta:
        unique_together = (('partner', 'uuid'), )
        verbose_name_plural = _('People')

    def __str__(self):
        return self.full_name

    @property
    def full_name(self):
        if self.family_name:
            return ' '.join((
                self.given_name,
                self.family_name,
            ))
        else:
            return self.given_name

    @property
    def get_profile_image_url(self):
        url = self.profile_image_url
        if not url:
            if self.profile_image and hasattr(self.profile_image, 'url'):
                url = self.profile_image.url

        return url
Example #4
0
class Marque(models.Model):
    name = models.CharField(max_length=50, unique=True, default='')
    slug = models.CharField(max_length=50, unique=True)
    image = StdImageField(
        upload_to=UploadToAutoSlug(populate_from='name'),
        variations={'thumbnail': {
            "width": 80,
            "height": 80,
            "crop": True
        }})
    categories = models.ManyToManyField(Categorie)
    is_home_display = models.BooleanField(default=False)
    date_creation = models.DateTimeField(auto_now_add=True)
    date_update = models.DateTimeField(auto_now=True)

    def get_absolute_url(self):
        return reverse('shopping:marques_detail', args=[self.slug])

    def __str__(self):
        return self.name
Example #5
0
class ProgramType(TimeStampedModel):
    name = models.CharField(max_length=32,
                            unique=True,
                            null=False,
                            blank=False)
    applicable_seat_types = models.ManyToManyField(
        SeatType,
        help_text=
        _('Seat types that qualify for completion of programs of this type. Learners completing '
          'associated courses, but enrolled in other seat types, will NOT have their completion '
          'of the course counted toward the completion of the program.'),
    )
    logo_image = StdImageField(
        upload_to=UploadToAutoSlug(populate_from='name',
                                   path='media/program_types/logo_images'),
        blank=True,
        null=True,
        variations={
            'large': (256, 256),
            'medium': (128, 128),
            'small': (64, 64),
            'x-small': (32, 32),
        },
        help_text=_(
            'Please provide an image file with transparent background'),
    )
    slug = AutoSlugField(
        populate_from='name',
        editable=True,
        unique=True,
        help_text=_(
            'Leave this field blank to have the value generated automatically.'
        ))

    def __str__(self):
        return self.name
Example #6
0
class Course(TimeStampedModel):
    """ Course model. """
    partner = models.ForeignKey(Partner)
    uuid = models.UUIDField(default=uuid4,
                            editable=False,
                            verbose_name=_('UUID'))
    canonical_course_run = models.OneToOneField(
        'course_metadata.CourseRun',
        related_name='canonical_for_course',
        default=None,
        null=True,
        blank=True)
    key = models.CharField(max_length=255)
    title = models.CharField(max_length=255,
                             default=None,
                             null=True,
                             blank=True)
    short_description = models.CharField(max_length=255,
                                         default=None,
                                         null=True,
                                         blank=True)
    full_description = models.TextField(default=None, null=True, blank=True)
    authoring_organizations = SortedManyToManyField(
        Organization, blank=True, related_name='authored_courses')
    sponsoring_organizations = SortedManyToManyField(
        Organization, blank=True, related_name='sponsored_courses')
    subjects = models.ManyToManyField(Subject, blank=True)
    prerequisites = models.ManyToManyField(Prerequisite, blank=True)
    level_type = models.ForeignKey(LevelType,
                                   default=None,
                                   null=True,
                                   blank=True)
    expected_learning_items = SortedManyToManyField(ExpectedLearningItem,
                                                    blank=True)
    outcome = models.TextField(blank=True, null=True)
    prerequisites_raw = models.TextField(blank=True, null=True)
    syllabus_raw = models.TextField(blank=True, null=True)
    card_image_url = models.URLField(null=True, blank=True)
    image = StdImageField(upload_to=UploadToAutoSlug(
        populate_from='uuid', path='media/course/image'),
                          blank=True,
                          null=True,
                          variations={
                              'original': (2120, 1192),
                              'small': (318, 178)
                          },
                          help_text=_('Please provide a course preview image'))
    slug = AutoSlugField(populate_from='key', editable=True)
    video = models.ForeignKey(Video, default=None, null=True, blank=True)

    # TODO Remove this field.
    number = models.CharField(
        max_length=50,
        null=True,
        blank=True,
        help_text=_('Course number format e.g CS002x, BIO1.1x, BIO1.2x'))

    objects = CourseQuerySet.as_manager()

    class Meta:
        unique_together = (
            ('partner', 'uuid'),
            ('partner', 'key'),
        )

    def __str__(self):
        return '{key}: {title}'.format(key=self.key, title=self.title)

    @property
    def image_url(self):
        if self.image:
            return self.image.small.url

        return self.card_image_url

    @property
    def original_image_url(self):
        if self.image:
            return self.image.url
        return None

    @property
    def marketing_url(self):
        url = None
        if self.partner.marketing_site_url_root:
            path = 'course/{slug}'.format(slug=self.slug)
            url = urljoin(self.partner.marketing_site_url_root, path)

        return url

    @property
    def active_course_runs(self):
        """ Returns course runs that have not yet ended and meet the following enrollment criteria:
            - Open for enrollment
            - OR will be open for enrollment in the future
            - OR have no specified enrollment close date (e.g. self-paced courses)

        Returns:
            QuerySet
        """
        now = datetime.datetime.now(pytz.UTC)
        return self.course_runs.filter(
            Q(end__gt=now)
            & (Q(enrollment_end__gt=now) | Q(enrollment_end__isnull=True)))

    @classmethod
    def search(cls, query):
        """ Queries the search index.

        Args:
            query (str) -- Elasticsearch querystring (e.g. `title:intro*`)

        Returns:
            QuerySet
        """
        query = clean_query(query)
        results = SearchQuerySet().models(cls).raw_search(query)
        ids = {result.pk for result in results}

        if waffle.switch_is_active('log_course_search_queries'):
            logger.info(
                'Course search query {query} returned the following ids: {course_ids}'
                .format(query=query, course_ids=ids))

        return cls.objects.filter(pk__in=ids)