Exemple #1
0
 class Meta:
     model = License
     exclude = ('license_uri', 'license_name')
     widgets = {
         'allow_commercial_use': NoBulletsRadioSelect(),
         'allow_modifications': NoBulletsRadioSelect(),
     }
Exemple #2
0
 class Meta:
     model = Album
     exclude = ('user', 'owner', 'user_images', 'tags', 'created_at', 'comment_receiver')
     widgets = {
         'description': forms.Textarea(attrs={'cols':60,'rows':3}),
         'publicly_visible': NoBulletsRadioSelect(),
     }
Exemple #3
0
 class Meta:
     model = Submission
     fields = (
         'publicly_visible',
         #'allow_commercial_use', 'allow_modifications',
         'parity',
         'scale_units',
         'scale_type',
         'scale_lower',
         'scale_upper',
         'scale_est',
         'scale_err',
         'positional_error',
         'center_ra',
         'center_dec',
         'radius',
         'tweak_order',
         'downsample_factor',
         'use_sextractor',
         'crpix_center',
         'invert',
         #'source_type'
     )
     widgets = {
         #'scale_type': forms.RadioSelect(template_name='radio-horizontal.html'), #renderer=HorizontalRenderer),
         'scale_type': HorizontalRadioSelect(),
         'scale_lower': forms.TextInput(attrs={'size': '5'}),
         'scale_upper': forms.TextInput(attrs={'size': '5'}),
         'scale_est': forms.TextInput(attrs={'size': '5'}),
         'scale_err': forms.TextInput(attrs={'size': '5'}),
         'positional_error': forms.TextInput(attrs={'size': '5'}),
         'center_ra': forms.TextInput(attrs={'size': '5'}),
         'center_dec': forms.TextInput(attrs={'size': '5'}),
         'radius': forms.TextInput(attrs={'size': '5'}),
         'tweak_order': forms.TextInput(attrs={'size': 5}),
         'downsample_factor': forms.TextInput(attrs={'size': '5'}),
         'use_sextractor': forms.CheckboxInput(),
         'crpix_center': forms.CheckboxInput(),
         'invert': forms.CheckboxInput(),
         'parity': NoBulletsRadioSelect(),
         'publicly_visible': NoBulletsRadioSelect(),
         #'parity': forms.RadioSelect(template='radio-nobullets.html'), #renderer=NoBulletsRenderer),
         #'source_type': forms.RadioSelect(renderer=NoBulletsRenderer),
         #'publicly_visible': forms.RadioSelect(template='radio-nobullets.html'), #renderer=NoBulletsRenderer),
         #'allow_commercial_use':forms.RadioSelect(renderer=NoBulletsRenderer),
         #'allow_modifications':forms.RadioSelect(renderer=NoBulletsRenderer),
     }
Exemple #4
0
 class Meta:
     model = UserImage
     exclude = (
         'image',
         'user',
         'tags',
         'flags',
         'original_file_name',
         'submission',
         'owner',
         'comment_receiver',
         'license',
         'sky_objects',
     )
     widgets = {
         'description': forms.Textarea(attrs={'cols':60,'rows':3}),
         'publicly_visible': NoBulletsRadioSelect(),
     }
Exemple #5
0
class SubmissionForm(forms.ModelForm):
    SCALE_PRESET_SETTINGS = {'1':(0.1,180),
                             '2':(1,180),
                             '3':(10,180),
                             '4':(0.05,0.15)}

    file  = forms.FileField(
        required=False,
        widget=forms.FileInput(attrs={'size':'80','style':'border:0px'})
    )

    url = forms.CharField(
        widget=forms.TextInput(attrs={'size':'80'}),
        initial='http://',
        required=False
    )

    upload_type = forms.ChoiceField(
        #widget=forms.RadioSelect(template_name='radio-horizontal.html'), #renderer=HorizontalRenderer),
        widget = HorizontalRadioSelect(),
        choices=(('file','file'),('url','url')),
        initial='file'
    )

    scale_preset = forms.ChoiceField(
        #widget=forms.RadioSelect(template='radio-nobullets.html'), #renderer=NoBulletsRenderer),
        widget = NoBulletsRadioSelect(),
        choices=(
            ('1','default (0.1 to 180 degrees)'),
            ('2','wide field (1 to 180 degrees)'),
            ('3','very wide field (10 to 180 degrees)'),
            ('4','tiny (3 to 9 arcmin)'),
            ('5','custom')
        ),
        initial='1'
    )

    album = forms.ChoiceField(choices=(), required=False)
    new_album_title = forms.CharField(
        widget=forms.TextInput(attrs={'size':'40'}),
        max_length=64,
        required=False
    )

    allow_commercial_use = forms.ChoiceField(
        #widget=forms.RadioSelect(template='radio-nobullets.html'), #renderer=NoBulletsRenderer),
        widget = NoBulletsRadioSelect(),
        choices=License.YES_NO,
        initial='d',
    )

    allow_modifications = forms.ChoiceField(
        #widget=forms.RadioSelect(template='radio-nobullets.html'), #renderer=NoBulletsRenderer),
        widget = NoBulletsRadioSelect(),
        choices=License.YES_SA_NO,
        initial='d',
    )

    advanced_settings = forms.BooleanField(widget=forms.HiddenInput(),
                                           initial=False, required=False)


    class Meta:
        model = Submission
        fields = (
            'publicly_visible',
            #'allow_commercial_use', 'allow_modifications',
            'parity','scale_units','scale_type','scale_lower',
            'scale_upper','scale_est','scale_err','positional_error',
            'center_ra','center_dec','radius', 'tweak_order', 'downsample_factor',
            'use_sextractor', 'crpix_center',
            'invert',
            #'source_type'
            )
        widgets = {
            #'scale_type': forms.RadioSelect(template_name='radio-horizontal.html'), #renderer=HorizontalRenderer),
            'scale_type': HorizontalRadioSelect(),
            'scale_lower': forms.TextInput(attrs={'size':'5'}),
            'scale_upper': forms.TextInput(attrs={'size':'5'}),
            'scale_est': forms.TextInput(attrs={'size':'5'}),
            'scale_err': forms.TextInput(attrs={'size':'5'}),
            'positional_error': forms.TextInput(attrs={'size':'5'}),
            'center_ra': forms.TextInput(attrs={'size':'5'}),
            'center_dec': forms.TextInput(attrs={'size':'5'}),
            'radius': forms.TextInput(attrs={'size':'5'}),
            'tweak_order': forms.TextInput(attrs={'size':5}),
            'downsample_factor': forms.TextInput(attrs={'size':'5'}),
            'use_sextractor': forms.CheckboxInput(),
            'crpix_center': forms.CheckboxInput(),
            'invert': forms.CheckboxInput(),

            'parity': NoBulletsRadioSelect(),
            'publicly_visible': NoBulletsRadioSelect(),
            #'parity': forms.RadioSelect(template='radio-nobullets.html'), #renderer=NoBulletsRenderer),
            #'source_type': forms.RadioSelect(renderer=NoBulletsRenderer),
            #'publicly_visible': forms.RadioSelect(template='radio-nobullets.html'), #renderer=NoBulletsRenderer),
            #'allow_commercial_use':forms.RadioSelect(renderer=NoBulletsRenderer),
            #'allow_modifications':forms.RadioSelect(renderer=NoBulletsRenderer),
        }

    def clean(self):
        number_message = "Enter a number."

        scale_preset = self.cleaned_data.get('scale_preset','')
        if scale_preset == '5':
            # custom preset error handling
            scale_type = self.cleaned_data.get('scale_type','')
            if scale_type == 'ul':
                scale_lower = self.cleaned_data.get('scale_lower')
                scale_upper = self.cleaned_data.get('scale_upper')
                if not scale_lower:
                    self._errors['scale_lower'] = self.error_class([number_message])
                if not scale_upper:
                    self._errors['scale_upper'] = self.error_class([number_message])
            elif scale_type == 'ev':
                scale_est = self.cleaned_data.get('scale_est')
                scale_err = self.cleaned_data.get('scale_err')
                if not scale_est:
                    self._errors['scale_est'] = self.error_class([number_message])
                if not scale_err:
                    self._errors['scale_err'] = self.error_class([number_message])
        else:
            # if scale isn't custom, use preset settings
            self.cleaned_data['scale_type'] = 'ul'
            self.cleaned_data['scale_units'] = 'degwidth'
            self.cleaned_data['scale_lower'] = self.SCALE_PRESET_SETTINGS[scale_preset][0]
            self.cleaned_data['scale_upper'] = self.SCALE_PRESET_SETTINGS[scale_preset][1]

        center_ra = self.cleaned_data.get('center_ra')
        center_dec = self.cleaned_data.get('center_dec')
        radius = self.cleaned_data.get('radius')
        if center_ra or center_dec or radius:
            if not center_ra:
                self._errors['center_ra'] = self.error_class([number_message])
            if not center_dec:
                self._errors['center_dec'] = self.error_class([number_message])
            if not radius:
                self._errors['radius'] = self.error_class([number_message])

        tweak_order = self.cleaned_data.get('tweak_order')
        if tweak_order < 0 or tweak_order > 9:
            self._errors['tweak_order'] = self.error_class(['Tweak order must be between 0 and 9'])

        upload_type = self.cleaned_data.get('upload_type','')
        if upload_type == 'file':
            if not self.cleaned_data.get('file'):
                raise forms.ValidationError("You must select a file to upload.")
        elif upload_type == 'url':
            url = self.cleaned_data.get('url','')
            if not (url.startswith('http://') or url.startswith('ftp://') or url.startswith('https://')):
                url = 'http://' + url
            if url.startswith('http://http://') or url.startswith('http://ftp://') or url.startswith('http://https://'):
                url = url[7:]
            if len(url) == 0:
                raise forms.ValidationError("You must enter a url to upload.")
            print('Cleaned URL:', url)
            urlvalidator = URLValidator()
            try:
                urlvalidator(url)
            except forms.ValidationError:
                raise forms.ValidationError("You must enter a valid url.")
            self.cleaned_data['url'] = url

        return self.cleaned_data

    def __init__(self, user, *args, **kwargs):
        super(SubmissionForm, self).__init__(*args, **kwargs)
        #if user.is_authenticated():
        #    self.fields['album'].queryset = user.albums
        self.fields['album'].choices = [('', 'none')]
        if user.is_authenticated():
            for album in Album.objects.filter(user=user).all():
                self.fields['album'].choices += [(album.id, album.title)]
            self.fields['album'].choices += [('new', 'create new album...')]
        self.fields['album'].initial = ''
Exemple #6
0
 class Meta:
     model = UserProfile
     exclude = ('apikey', 'default_license', 'user')
     widgets = {
         'default_publicly_visible': NoBulletsRadioSelect(),
         }