Пример #1
0
 def clean_image(self):
     data = self.cleaned_data
     post = get_request().POST
     if int(post['user']) != data['image'].user.pk:
         raise forms.ValidationError(
             _("Please select an image that belongs to Album Owner."))
     return data['image']
Пример #2
0
    def __init__(self, *args, **kwargs):
        super(ImageAdminForm, self).__init__(*args, **kwargs)

        self.fields['title'].required = False

        qu = User.objects.filter(is_active=True)
        owner = get_request().user
        if not owner.is_superuser:
            qu = qu.filter(pk=owner.pk)
        self.fields['user'] = UserChoiceField(queryset=qu)
        self.fields['user'].required = False

        self.fields['mediafile'].initial = self.instance.pk
Пример #3
0
    def __init__(self, *args, **kwargs):
        super(AlbumAdminForm, self).__init__(*args, **kwargs)

        if not 'instance' in kwargs:
            """
            Adding a new Album
            """
            qu = User.objects.filter(is_active=True)
            owner = get_request().user
            if not owner.is_superuser:
                qu = qu.filter(pk=owner.pk)
            self.fields['user'] = UserChoiceField(queryset=qu)
            self.fields['user'].label = _('Owner')
Пример #4
0
    def __init__(self, *args, **kwargs):
        super(ImageAdminForm, self).__init__(*args, **kwargs)

        self.fields['title'].required = False

        qu = User.objects.filter(is_active=True)
        owner = get_request().user
        if not owner.is_superuser:
            qu = qu.filter(pk=owner.pk)
        self.fields['user'] = UserChoiceField(queryset=qu)
        self.fields['user'].required = False

        self.fields['mediafile'].initial = self.instance.pk
Пример #5
0
    def __init__(self, *args, **kwargs):
        super(AlbumAdminForm, self).__init__(*args, **kwargs)

        if not 'instance' in  kwargs:
            """
            Adding a new Album
            """
            qu = User.objects.filter(is_active=True)
            owner = get_request().user
            if not owner.is_superuser:
                qu = qu.filter(pk=owner.pk)
            self.fields['user'] = UserChoiceField(queryset=qu) 
            self.fields['user'].label = _('Owner')
Пример #6
0
    def __init__(self, *args, **kwargs):
        super(InlineImageForm, self).__init__(*args, **kwargs)
        try:
            image = Image.objects.get(pk=self.instance.image_id)
            self.fields["mediafile"].initial = image.pk
        except:
            pass

        """
        Build selection according to Album owner
        """
        qi = Image.objects.all()
        owner = get_request().user
        if not owner.is_superuser:
            qi = qi.filter(user=owner) 
        self.fields['image'].choices = [(u'',u'----------')] + [(img.pk, img.__unicode__()) for img in qi]
Пример #7
0
 def __init__(self, *args, **kwargs):
     super(InlineImageForm, self).__init__(*args, **kwargs)
     try:
         image = Image.objects.get(pk=self.instance.image_id)
         self.fields["mediafile"].initial = image.pk
     except:
         pass
     """
     Build selection according to Album owner
     """
     qi = Image.objects.all()
     owner = get_request().user
     if not owner.is_superuser:
         qi = qi.filter(user=owner)
     self.fields['image'].choices = [(u'', u'----------')] + [
         (img.pk, img.__unicode__()) for img in qi
     ]
Пример #8
0
    def __init__(self, *args, **kwargs):
        super(ZipImageAdminForm, self).__init__(*args, **kwargs)

        owner = get_request().user

        qa = Album.objects.all().order_by('user__first_name', 'name')
        qu = User.objects.filter(is_active=True)

        if not owner.is_superuser:
            qa = qa.filter(user=owner)
            qu = qu.filter(pk=owner.pk)

        self.fields['album'] = AlbumOwnerChoiceField(queryset=qa) 
        self.fields['album'].required = False

        self.fields['user'] = UserChoiceField(queryset=qu)
        self.fields['user'].required = False
        self.fields['user'].label = _('Owner')
Пример #9
0
    def __init__(self, *args, **kwargs):
        super(ZipImageAdminForm, self).__init__(*args, **kwargs)

        print("PRE: get_request()")
        owner = get_request().user
        print(owner)

        qa = Album.objects.all().order_by('user__first_name', 'name')
        qu = User.objects.filter(is_active=True)

        if not owner.is_superuser:
            qa = qa.filter(user=owner)
            qu = qu.filter(pk=owner.pk)

        self.fields['album'] = AlbumOwnerChoiceField(queryset=qa)
        self.fields['album'].required = False

        self.fields['user'] = UserChoiceField(queryset=qu)
        self.fields['user'].required = False
        self.fields['user'].label = _('Owner')
Пример #10
0
 def clean_image(self):
     data = self.cleaned_data
     post = get_request().POST 
     if int(post['user']) != data['image'].user.pk: 
         raise forms.ValidationError(_("Please select an image that belongs to Album Owner.")) 
     return data['image']