class TestNoModelForm(forms.Form):
    from constrainedfilefield.fields import ConstrainedFileField
    the_file = ConstrainedFileField(null=True,
                                    blank=True,
                                    upload_to='testfile',
                                    content_types=['image/png'],
                                    max_upload_size=10240).formfield()
class TestModelNoValidate(models.Model):
    the_file = ConstrainedFileField(null=True,
                                    blank=True,
                                    upload_to='testfile')
    the_image = ConstrainedImageField(null=True,
                                      blank=True,
                                      upload_to='testfile')
class TestModelJs(models.Model):
    the_file = ConstrainedFileField(null=True,
                                    blank=True,
                                    upload_to='testfile',
                                    content_types=['image/png'],
                                    max_upload_size=10240,
                                    js_checker=True)
Exemplo n.º 4
0
class Attachment(models.Model):
    title = models.CharField(max_length=200, verbose_name="Title")
    last_update = models.DateTimeField(auto_now=True)
    file = ConstrainedFileField(upload_to=attachment_path,
                                content_types=[
                                    'image/png', 'image/jpeg', 'image/bmp',
                                    'image/gif', 'audio/aac', 'audio/mpeg',
                                    'audio/ogg', 'audio/x-flac', 'audio/x-wav',
                                    'video/mp4', 'video/x-ms-wmv',
                                    'video/webm', 'application/pdf',
                                    'text/plain', 'application/zip'
                                ],
                                null=True,
                                verbose_name="File",
                                max_upload_size=52428800)
    TYPE_OF_ATTACHMENT = (
        ('audio', 'Audio'),
        ('image', 'Image'),
        ('text', 'Text'),
        ('video', 'Video'),
        ('other', 'Other'),
    )
    type = models.CharField(max_length=5,
                            choices=TYPE_OF_ATTACHMENT,
                            blank=True,
                            default='image',
                            help_text='Select allowed attachment type',
                            verbose_name="Attachment type")
    task = models.ForeignKey(Task, on_delete=models.CASCADE)

    class Meta:
        verbose_name_plural = "Attachment"

    def __str__(self):
        return self.title
Exemplo n.º 5
0
class Places(models.Model):

    title = models.CharField(max_length=100)
    latitude = models.FloatField(
        null=True,
        blank=True,
    )
    longitude = models.FloatField(
        null=True,
        blank=True,
    )
    location = models.PointField(null=True, srid=4326, default=Point(27, -38))
    objects = models.GeoManager()
    sound = ConstrainedFileField(max_upload_size=4194304)
    prefered_radius = models.IntegerField(default=5, help_text="in kilometers")
    rating = GenericRelation(Rating, related_query_name='foos')
    usersave = models.CharField(max_length=100)

    def __str__(self):
        return self.title

    def save(self, *args, **kwargs):
        if self.latitude and self.longitude:
            self.location = Point(self.longitude, self.latitude)

        super(Places, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return reverse('posts:detail', kwargs={'id': self.id})
class TestElement(models.Model):
    container = models.ForeignKey(TestContainer,
                                  on_delete=models.CASCADE,
                                  related_name='test_elements')
    the_file = ConstrainedFileField(null=True,
                                    blank=True,
                                    upload_to='testfile',
                                    content_types=['image/png', 'image/jpeg'])
Exemplo n.º 7
0
class TestModel(models.Model):
    the_file = ConstrainedFileField(
        null=True,
        blank=True,
        upload_to="testfile",
        content_types=["image/png"],
        max_upload_size=10240,
    )
Exemplo n.º 8
0
class Board(models.Model):
    name = models.CharField(max_length=20, primary_key=True)
    cover = ConstrainedFileField(null=True,
                                 blank=True,
                                 max_upload_size=512000,
                                 content_types=['image/jpeg', 'image/png'],
                                 upload_to=board_upload_handler)

    def __str__(self):
        return self.name
Exemplo n.º 9
0
class TestNoModelJsForm(forms.Form):
    from constrainedfilefield.fields import ConstrainedFileField

    the_file = ConstrainedFileField(
        null=True,
        blank=True,
        upload_to="testfile",
        content_types=["image/png"],
        max_upload_size=10240,
        js_checker=True,
    ).formfield()
Exemplo n.º 10
0
class TestDocModel(models.Model):
    the_file = ConstrainedFileField(
        null=False,
        blank=False,
        upload_to="testfile",
        content_types=[
            "application/msword",  # .doc
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",  # .docx
            "application/vnd.oasis.opendocument.text",  # .odt
        ],
        max_upload_size=10240,
    )
Exemplo n.º 11
0
class Clip(models.Model):
    name = models.CharField(max_length=20)
    board = models.ForeignKey(Board, on_delete=models.CASCADE)
    sound = ConstrainedFileField(max_upload_size=250000,
                                 content_types=['audio/mpeg', 'audio/mp3'],
                                 upload_to=clip_upload_handler)

    def __str__(self):
        return self.name

    class Meta:
        unique_together = ("name", "board")
Exemplo n.º 12
0
class TestModelJs(models.Model):
    the_file = ConstrainedFileField(
        null=True,
        blank=True,
        upload_to="testfile",
        content_types=["image/png"],
        max_upload_size=10240,
        js_checker=True,
    )
    the_image = ConstrainedImageField(
        null=True,
        blank=True,
        upload_to="testfile",
        content_types=["image/png"],
        min_upload_size=1024,
        max_upload_size=10240,
        js_checker=True,
    )
Exemplo n.º 13
0
class Document(models.Model):
    """
        A file and the meta-data describing that file in the catalogue.
    """
    category = models.ForeignKey(DocumentCategory, on_delete=models.CASCADE)

    sort_order = models.PositiveSmallIntegerField(default=0, verbose_name='Order')

    user = models.ForeignKey(django.conf.settings.AUTH_USER_MODEL, on_delete=models.SET(1))

    creation_date = models.DateTimeField(auto_now_add=True, verbose_name='Created')

    update_date = models.DateTimeField(auto_now=True, verbose_name='Last Modified')

    title = models.CharField(max_length=512)

    description = models.TextField(null=True, blank=True)

    is_published = models.BooleanField(default=False)

    if appConfig.settings.USE_PRIVATE_FILES:
        from private_storage.fields import PrivateFileField
        file = PrivateFileField(
            upload_to=document_upload_path_callback,
            content_types=appConfig.settings.CONTENT_TYPE_WHITELIST,
            max_file_size=appConfig.settings.MAX_FILESIZE \
                if appConfig.settings.MAX_FILESIZE else None
        )
    else:
        from constrainedfilefield.fields import ConstrainedFileField
        file = ConstrainedFileField(
            max_length=200,
            upload_to=document_upload_path_callback,
            content_types=appConfig.settings.CONTENT_TYPE_WHITELIST,
            max_upload_size=appConfig.settings.MAX_FILESIZE * 1024 * 1024 \
                if appConfig.settings.MAX_FILESIZE else 0
        )
    objects = DocumentManager()
    published = PublishedDocumentManager()

    class Meta:
        ordering = ('sort_order', )

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse('document_catalogue:document_detail', kwargs={'pk': self.pk, })

    def get_edit_url(self):
        return reverse('document_catalogue:document_edit', kwargs={'pk': self.pk, })

    def get_download_url(self):
        return reverse('document_catalogue:document_download', kwargs={'pk': self.pk, })

    def get_filetype(self):
        name, extension = os.path.splitext(self.file.name)
        return extension[1:]

    def filename(self):
        return os.path.basename(self.file.name)

    def save(self, *args, **kwargs):
        if not self.sort_order:
            last = Document.objects.order_by('sort_order').values('sort_order').last()
            self.sort_order = last['sort_order'] + 1 if last else 1
        super().save(*args, **kwargs)
Exemplo n.º 14
0
class Poster(models.Model):
    title = models.CharField(max_length=256)
    slug = models.SlugField(max_length=40, unique=True, blank=True)
    conference = models.ForeignKey(Conference, on_delete=models.CASCADE)
    created_at = models.DateTimeField(auto_now_add=True)
    pub_date = models.DateField('date published', default=date.today)
    authors = models.ManyToManyField(Author, through='PosterAuthor')
    access_key = models.CharField(max_length=256, unique=True)
    external_id = models.CharField(max_length=256, blank=True)
    active = models.BooleanField(default=False)
    preview_small = models.ImageField(blank=True, upload_to=unique_upload)
    preview_large = models.ImageField(blank=True, upload_to=unique_upload)
    pdf = ConstrainedFileField(
                    blank=True,
                    upload_to=unique_upload,
                    max_upload_size=16777216,
                    content_types=['application/pdf'])

    def generate_preview(self):
        generate_preview(self)

    def save(self, *args, **kwargs):
        if not self.pk: # only create slug the first time the object is saved
            unique_slugify(self, self.title)
        super(Poster, self).save(*args, **kwargs)

    @property
    def author_list(self):
        return AuthorList(PosterAuthor.objects.filter(poster=self).order_by('position'))

    @property
    def first_author(self):
        poster_author = PosterAuthor.objects.filter(poster=self).order_by('position').first()
        return getattr(poster_author, 'author', Author(name='<no author>'))

    @property
    def num_authors(self):
        return PosterAuthor.objects.filter(poster=self).count()

    @property
    def ref_short(self):
        ''' poster title and first author '''
        etal = 'et al.' if self.num_authors > 1 else ''
        return ' '.join([self.title, 'by', self.first_author.name, etal])

    @property
    def ref_long(self):
        ''' poster title, all authors, conference name '''
        return ' '.join([self.title + '.', str(self.author_list), '(' + self.conference.name + ')'])

    @property
    def ext_url(self):
        ''' link to external paper '''
        eid = self.external_id.split('/')[-1]
        url = self.conference.link_url
        if not eid or not url:
            return None
        return url.format(id=eid)

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

    def __str__(self):
        return self.ref_short + ' (' + str(self.conference.name) + ')'
Exemplo n.º 15
0
class Exercise(models.Model):
    """Exercise model class."""

    name = models.CharField(max_length=255, verbose_name="nom de l'exercice")
    due_date = models.DateTimeField(verbose_name="Date à laquelle rendre")
    instruction = models.TextField(verbose_name="Consignes de l'exercice")
    author = models.ForeignKey(
        to="accounts.User",
        on_delete=models.PROTECT,
        blank=True,
        null=True,
        verbose_name="Auteur de l'exercice",
    )
    difficulty = models.ForeignKey(
        to="exercises.Difficulty",
        on_delete=models.PROTECT,
        verbose_name="Difficulté de l'exercice",
    )
    session = models.ForeignKey(
        to="exercises.Session",
        on_delete=models.CASCADE,
        related_name="exercises",
        verbose_name="Session de l'exercice",
    )
    section = models.ForeignKey(
        to="exercises.Section",
        on_delete=models.CASCADE,
        verbose_name="Section de l'exercice",
    )
    tags = models.ManyToManyField(
        to="exercises.Tag",
        related_name="exercises_tags",
        verbose_name="Tags associés",
        blank=True,
    )

    errors_template = models.ManyToManyField(
        to="exercises.ErrorsTemplate",
        related_name="exercises_errorsTemplate",
        verbose_name="Templates d'erreurs associés",
        blank=True,
    )

    project_files = ConstrainedFileField(
        upload_to=path_and_rename,
        validators=[validate_file_extensions],
        content_types=["application/gzip"],
        default="",
        storage=OverwriteStorage(),
        blank=True,
    )

    requirements = models.ManyToManyField(
        to="exercises.Requirement",
        related_name="exercises_requirements",
        verbose_name="Dépendances associées",
        blank=True,
    )

    docker_image = models.ForeignKey(
        to="sandbox.SandboxProfile",
        on_delete=models.CASCADE,
        verbose_name="Image docker associée",
        blank=True,
        null=True,
    )

    def __str__(self):
        """Return a string getter.

        :return: String formattage of the object
        :rtype: str
        """
        return "Exercice n°{id} - {name} - pour le {due_date}".format(
            id=self.id,
            name=self.name,
            due_date=self.due_date,
        )

    class Meta(object):
        """The Meta class that defines some fields."""

        verbose_name = "exercice"