Beispiel #1
0
class UserFolder(models.Model):
    name = models.CharField(_("Name"), max_length=255)
    # parent = models.ForeignKey(
    #    'self', blank=True, null=True, related_name='children')
    owner = select2_fields.ForeignKey(User, verbose_name=_("Owner"))
    created_at = models.DateTimeField(auto_now_add=True)
    access_groups = select2_fields.ManyToManyField(
        "authentication.AccessGroup",
        blank=True,
        verbose_name=_("Groups"),
        help_text=_("Select one or more groups who"
                    " can access in read only to this folder"),
    )
    users = select2_fields.ManyToManyField(
        User,
        blank=True,
        verbose_name=_("Users"),
        related_name="shared_files",
        help_text=_("Select one or more users who"
                    " can access in read only to this folder"),
    )

    class Meta:
        unique_together = (("name", "owner"), )
        verbose_name = _("User directory")
        verbose_name_plural = _("User directories")
        ordering = ["name"]
        app_label = "podfile"

    def clean(self):
        if self.name == "Home":
            same_home = UserFolder.objects.filter(owner=self.owner,
                                                  name="Home")
            if same_home:
                raise ValidationError(
                    "A user cannot have have multiple home directories.")

    def __str__(self):
        return "{0}".format(self.name)

    def get_all_files(self):
        file_list = self.customfilemodel_set.all()
        image_list = self.customimagemodel_set.all()
        result_list = sorted(chain(image_list, file_list),
                             key=attrgetter("uploaded_at"))
        return result_list

    def delete(self):
        for file in self.customfilemodel_set.all():
            file.delete()
        for img in self.customimagemodel_set.all():
            img.delete()
        super(UserFolder, self).delete()
Beispiel #2
0
class UserFolder(models.Model):
    name = models.CharField(_('Name'), max_length=255)
    # parent = models.ForeignKey(
    #    'self', blank=True, null=True, related_name='children')
    owner = select2_fields.ForeignKey(User, verbose_name=_('Owner'))
    created_at = models.DateTimeField(auto_now_add=True)
    groups = select2_fields.ManyToManyField(
        Group, blank=True, verbose_name=_('Groups'),
        help_text=_('Select one or more groups who'
                    ' can access in read only to this folder'))
    users = select2_fields.ManyToManyField(
        User, blank=True, verbose_name=_('Users'),
        related_name="shared_files",
        help_text=_('Select one or more users who'
                    ' can access in read only to this folder'))

    class Meta:
        unique_together = (('name', 'owner'),)
        verbose_name = _('User directory')
        verbose_name_plural = _('User directories')
        ordering = ['name']
        app_label = 'podfile'

    def clean(self):
        if self.name == 'Home':
            same_home = UserFolder.objects.filter(
                owner=self.owner, name='Home')
            if same_home:
                raise ValidationError(
                    'A user cannot have have multiple home directories.')

    def __str__(self):
        return '{0}'.format(self.name)

    def get_all_files(self):
        file_list = self.customfilemodel_set.all()
        image_list = self.customimagemodel_set.all()
        result_list = sorted(
            chain(image_list, file_list),
            key=attrgetter('uploaded_at'))
        return result_list

    def delete(self):
        for file in self.customfilemodel_set.all():
            file.delete()
        for img in self.customimagemodel_set.all():
            img.delete()
        super(UserFolder, self).delete()
Beispiel #3
0
class EnrichmentGroup(models.Model):
    video = select2_fields.OneToOneField(
        Video,
        verbose_name=_('Video'),
        # editable=False, null=True,
        on_delete=models.CASCADE)
    groups = select2_fields.ManyToManyField(Group,
                                            blank=True,
                                            verbose_name=_('Groups'),
                                            help_text=_(
                                                'Select one or more groups who'
                                                ' can access to the'
                                                ' enrichment of the video'))

    class Meta:
        ordering = ['video']
        verbose_name = _('Enrichment Video Group')
        verbose_name_plural = _('Enrichment Video Groups')

    @property
    def sites(self):
        return self.video.sites

    def __str__(self):
        return "Enrichment group %s" % (self.video)
Beispiel #4
0
class AbstractServiceFormItem(models.Model):
    _responsibles: Set[ResponsibilityPerson]
    sub_items: 'Iterable[AbstractServiceFormItem]'

    class Meta:
        abstract = True
        ordering = ('order', )

    order = models.PositiveIntegerField(default=0,
                                        blank=False,
                                        null=False,
                                        db_index=True,
                                        verbose_name=_('Order'))
    responsibles = select2_fields.ManyToManyField(
        ResponsibilityPerson,
        blank=True,
        verbose_name=_('Responsible persons'),
        related_name='%(class)s_related',
        overlay=_('Choose responsibles'),
    )

    @cached_property
    def responsibles_display(self) -> str:
        first_resp = ''
        responsibles = self.responsibles.all()
        if responsibles:
            first_resp = str(self.responsibles.first())
        if len(responsibles) > 1:
            return _('{} (and others)').format(first_resp)
        else:
            return first_resp

    def background_color_display(self) -> 'ColorStr':
        raise NotImplementedError
Beispiel #5
0
class Owner(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    auth_type = models.CharField(max_length=20,
                                 choices=AUTH_TYPE,
                                 default=AUTH_TYPE[0][0])
    affiliation = models.CharField(max_length=50,
                                   choices=AFFILIATION,
                                   default=AFFILIATION[0][0])
    commentaire = models.TextField(_("Comment"), blank=True, default="")
    hashkey = models.CharField(max_length=64,
                               unique=True,
                               blank=True,
                               default="")
    userpicture = models.ForeignKey(CustomImageModel,
                                    blank=True,
                                    null=True,
                                    verbose_name=_("Picture"))
    establishment = models.CharField(
        _("Establishment"),
        max_length=10,
        blank=True,
        choices=ESTABLISHMENTS,
        default=ESTABLISHMENTS[0][0],
    )
    accessgroups = select2_fields.ManyToManyField("authentication.AccessGroup",
                                                  blank=True)
    sites = models.ManyToManyField(Site)

    def __str__(self):
        if HIDE_USERNAME:
            return "%s %s" % (self.user.first_name, self.user.last_name)
        return "%s %s (%s)" % (
            self.user.first_name,
            self.user.last_name,
            self.user.username,
        )

    def save(self, *args, **kwargs):
        self.hashkey = hashlib.sha256(
            (SECRET_KEY + self.user.username).encode("utf-8")).hexdigest()
        super(Owner, self).save(*args, **kwargs)

    def is_manager(self):
        group_ids = (self.user.groups.all().filter(
            groupsite__sites=Site.objects.get_current()).values_list(
                "id", flat=True))
        return (self.user.is_staff and
                Permission.objects.filter(group__id__in=group_ids).count() > 0)

    @property
    def email(self):
        return self.user.email
Beispiel #6
0
class AccessGroup(models.Model):
    display_name = models.CharField(max_length=128, blank=True, default="")
    code_name = models.CharField(max_length=128, unique=True)
    sites = models.ManyToManyField(Site)
    users = select2_fields.ManyToManyField(
        Owner,
        blank=True,
        ajax=True,
        search_field=lambda q: Q(user__username__icontains=q)
        | Q(user__first_name__icontains=q)
        | Q(user__last_name__icontains=q),
        through="Owner_accessgroups",
    )

    def __str__(self):
        return "%s" % (self.display_name)

    class Meta:
        verbose_name = _("Access Groups")
        verbose_name_plural = _("Access Groups")
Beispiel #7
0
class Recorder(models.Model):
    # Recorder name
    name = models.CharField(_("name"), max_length=200, unique=True)
    # Description of the recorder
    description = RichTextField(_("description"), config_name="complete", blank=True)
    # IP address of the recorder
    address_ip = models.GenericIPAddressField(
        _("Address IP"), unique=True, help_text=_("IP address of the recorder.")
    )
    # Salt for
    salt = models.CharField(
        _("salt"), max_length=50, blank=True, help_text=_("Recorder salt.")
    )

    # Recording type (video, AUdioVideoCasst, etc)
    recording_type = models.CharField(
        _("Recording Type"),
        max_length=50,
        choices=RECORDER_TYPE,
        default=RECORDER_TYPE[0][0],
    )
    # Manager of the recorder who received mails
    user = select2_fields.ForeignKey(
        User,
        on_delete=models.CASCADE,
        limit_choices_to={"is_staff": True},
        help_text=_(
            "Manager of this recorder. This manager will receive recorder "
            "emails and he will be the owner of the published videos. If no "
            "user is selected, this recorder will use manual assign system."
        ),
        verbose_name=_("User"),
        null=True,
        blank=True,
    )
    # Additionnal additional_users
    additional_users = select2_fields.ManyToManyField(
        User,
        blank=True,
        ajax=True,
        js_options={"width": "off"},
        verbose_name=_("Additional users"),
        search_field=select_recorder_user(),
        related_name="users_recorders",
        help_text=_(
            "You can add additionals users to the recorder. They "
            "will become the additionnals owners of the published videos "
            "and will have the same rights as the owner except that they "
            "can't delete the published videos."
        ),
    )
    # Default type of published videos by this recorder
    type = models.ForeignKey(
        Type, on_delete=models.CASCADE, help_text=_("Video type by default.")
    )
    is_draft = models.BooleanField(
        verbose_name=_("Draft"),
        help_text=_(
            "If this box is checked, "
            "the video will be visible and accessible only by you "
            "and the additional owners."
        ),
        default=True,
    )
    is_restricted = models.BooleanField(
        verbose_name=_("Restricted access"),
        help_text=_(
            "If this box is checked, "
            "the video will only be accessible to authenticated users."
        ),
        default=False,
    )
    restrict_access_to_groups = select2_fields.ManyToManyField(
        Group,
        blank=True,
        verbose_name=_("Groups"),
        help_text=_("Select one or more groups who can access to this video"),
    )
    password = models.CharField(
        _("password"),
        help_text=_("Viewing this video will not be possible without this password."),
        max_length=50,
        blank=True,
        null=True,
    )
    cursus = models.CharField(
        _("University course"),
        max_length=1,
        choices=CURSUS_CODES,
        default="0",
        help_text=_("Select an university course as audience target of the content."),
    )
    main_lang = models.CharField(
        _("Main language"),
        max_length=2,
        choices=LANG_CHOICES,
        default=get_language(),
        help_text=_("Select the main language used in the content."),
    )
    transcript = models.BooleanField(
        _("Transcript"),
        default=False,
        help_text=_("Check this box if you want to transcript the audio. (beta version)"),
    )
    tags = TagField(
        help_text=_(
            "Separate tags with spaces, "
            "enclose the tags consist of several words in quotation marks."
        ),
        verbose_name=_("Tags"),
    )
    discipline = select2_fields.ManyToManyField(
        Discipline, blank=True, verbose_name=_("Disciplines")
    )
    licence = models.CharField(
        _("Licence"),
        max_length=8,
        choices=LICENCE_CHOICES,
        blank=True,
        null=True,
    )
    channel = select2_fields.ManyToManyField(
        Channel, verbose_name=_("Channels"), blank=True
    )
    theme = models.ManyToManyField(
        Theme,
        verbose_name=_("Themes"),
        blank=True,
        help_text=_(
            'Hold down "Control", or "Command" ' "on a Mac, to select more than one."
        ),
    )
    allow_downloading = models.BooleanField(
        _("allow downloading"),
        default=False,
        help_text=_("Check this box if you to allow downloading of the encoded files"),
    )
    is_360 = models.BooleanField(
        _("video 360"),
        default=False,
        help_text=_("Check this box if you want to use the 360 player for the video"),
    )
    disable_comment = models.BooleanField(
        _("Disable comment"),
        help_text=_("Allows you to turn off all comments on this video."),
        default=False,
    )

    # Directory name where videos of this recorder are published
    directory = models.CharField(
        _("Publication directory"),
        max_length=50,
        unique=True,
        help_text=_("Basic directory containing the videos published by the recorder."),
    )
    sites = models.ManyToManyField(Site)

    def __unicode__(self):
        return "%s - %s" % (self.name, self.address_ip)

    def __str__(self):
        return "%s - %s" % (self.name, self.address_ip)

    def ipunder(self):
        return self.address_ip.replace(".", "_")

    def save(self, *args, **kwargs):
        super(Recorder, self).save(*args, **kwargs)

    class Meta:
        verbose_name = _("Recorder")
        verbose_name_plural = _("Recorders")
        ordering = ["name"]