Beispiel #1
0
class BaseAliasForm(ModelForm):
    class Meta:
        model = Artist
        parent_model = Artist
        #fields = ('child',)
        exclude = []

    def __init__(self, *args, **kwargs):
        super(BaseAliasForm, self).__init__(*args, **kwargs)
        instance = getattr(self, 'instance', None)

    child = search_fields.AutocompleteField('alibrary.artist',
                                            allow_new=True,
                                            required=False,
                                            label=_('Alias'))

    def clean_child(self):

        child = self.cleaned_data['child']
        if not child.pk:
            log.debug('saving not existant child: %s' % child.name)
            child.save()
        return child

    def clean(self, *args, **kwargs):

        cd = super(BaseAliasForm, self).clean()
        return cd

    def save(self, *args, **kwargs):
        instance = super(BaseAliasForm, self).save(*args, **kwargs)
        return instance
Beispiel #2
0
class BaseExtraartistForm(ModelForm):
    class Meta:
        model = MediaExtraartists
        parent_model = Media
        fields = (
            'artist',
            'profession',
        )
        # labels in django 1.6 only... leave them here for the future...
        labels = {
            'profession': _('Credited as'),
        }

    def __init__(self, *args, **kwargs):
        super(BaseExtraartistForm, self).__init__(*args, **kwargs)
        instance = getattr(self, 'instance', None)

        self.fields['profession'].label = _('Credited as')

    artist = search_fields.AutocompleteField('alibrary.artist',
                                             allow_new=True,
                                             required=False,
                                             label=_('Artist'))

    def clean_artist(self):

        artist = self.cleaned_data['artist']
        try:
            if not artist.pk:
                log.debug('saving not existant artist: %s' % artist.name)
                artist.save()
            return artist
        except:
            return None
Beispiel #3
0
class BaseAlbumartistForm(ModelForm):
    class Meta:
        model = ReleaseAlbumartists
        parent_model = Release
        fields = (
            'artist',
            'join_phrase',
            'position',
        )

    def __init__(self, *args, **kwargs):
        instance = getattr(self, 'instance', None)
        super(BaseAlbumartistForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False

        base_layout = Row(
            Column(Field('join_phrase'), css_class='span3'),
            Column(Field('artist'), css_class='span5'),
            Column(Field('DELETE'), css_class='span4 delete'),
            css_class='albumartist-row row-fluid form-autogrow',
        )

        self.helper.add_layout(base_layout)

    def clean_artist(self):
        artist = self.cleaned_data['artist']
        if artist and not artist.pk:
            log.debug('saving not existant artist: %s' % artist.name)
            artist.save()
        return artist

    artist = search_fields.AutocompleteField('alibrary.artist',
                                             allow_new=True,
                                             required=False)
Beispiel #4
0
class BaseReleaseMediaForm(ModelForm):
    class Meta:
        model = Media
        parent_model = Release
        exclude = []

    def __init__(self, *args, **kwargs):
        self.instance = kwargs['instance']
        super(BaseReleaseMediaForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_tag = False

        base_layout = Row(
            Column(
                Field('tracknumber', css_class='input-small'),
                Field('mediatype', css_class='input-small'),
                Field('license', css_class='input-small'),
                HTML(
                    '<div><span style="padding-right: 68px;">&nbsp;</span><a href="%s"><i class="icon icon-edit"></i> Edit Track</a></div>'
                    % self.instance.get_edit_url()),
                css_class='span3'),
            Column(
                LookupField('name', css_class='input-large'),
                LookupField('artist', css_class='input-large'),
                LookupField('isrc', css_class='input-large'),
                HTML(
                    '<div style="opacity: 0.5;"><span style="padding-right: 48px;">File:</span>%s</div>'
                    % self.instance.filename),
                css_class='span9'),
            css_class='releasemedia-row row-fluid',
        )

        self.helper.add_layout(base_layout)

    artist = search_fields.AutocompleteField('alibrary.artist',
                                             allow_new=True,
                                             required=False)
    TRACKNUMBER_CHOICES = [('', '---')] + list(
        ((str(x), x) for x in range(1, 301)))
    tracknumber = forms.ChoiceField(label=_('No.'),
                                    required=False,
                                    choices=TRACKNUMBER_CHOICES)

    def clean(self, *args, **kwargs):
        cd = super(BaseReleaseMediaForm, self).clean()

        try:
            cd['tracknumber'] = int(cd['tracknumber'])
        except:
            cd['tracknumber'] = None

        return cd
Beispiel #5
0
class BaseMediaartistForm(ModelForm):
    class Meta:
        model = MediaArtists
        parent_model = Media
        fields = (
            'artist',
            'join_phrase',
            'position',
        )

    def __init__(self, *args, **kwargs):
        super(BaseMediaartistForm, self).__init__(*args, **kwargs)
        instance = getattr(self, 'instance', None)

    def clean_artist(self):
        artist = self.cleaned_data['artist']
        if not artist.pk:
            artist.save()

        return artist

    artist = search_fields.AutocompleteField('alibrary.artist',
                                             allow_new=True,
                                             required=False)
Beispiel #6
0
class LabelForm(ModelForm):
    class Meta:
        model = Label
        fields = ('name', 'type', 'labelcode', 'parent', 'date_start',
                  'date_end', 'description', 'address', 'country', 'phone',
                  'fax', 'email', 'main_image', 'd_tags')

    def __init__(self, *args, **kwargs):

        self.user = kwargs['initial']['user']
        self.instance = kwargs['instance']

        self.label = kwargs.pop('label', None)

        super(LabelForm, self).__init__(*args, **kwargs)
        """
        Prototype function, set some fields to readonly depending on permissions
        """
        """
        if not self.user.has_perm("alibrary.admin_release", self.instance):
            self.fields['catalognumber'].widget.attrs['readonly'] = 'readonly'
        """

        self.helper = FormHelper()
        self.helper.form_id = "id_feedback_form_%s" % 'asd'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        base_layout = Fieldset(
            _('General'),
            LookupField('name', css_class='input-xlarge'),
            LookupField('type', css_class='input-xlarge'),
            LookupField('labelcode', css_class='input-xlarge'),
            LookupField('parent', css_class='input-xlarge'),
        )

        activity_layout = Fieldset(
            _('Activity'),
            LookupField('date_start', css_class='input-xlarge'),
            LookupField('date_end', css_class='input-xlarge'),
        )

        contact_layout = Fieldset(
            _('Contact'),
            LookupField('address', css_class='input-xlarge'),
            LookupField('country', css_class='input-xlarge'),
            LookupField('phone', css_class='input-xlarge'),
            LookupField('fax', css_class='input-xlarge'),
            LookupField('email', css_class='input-xlarge'),
        )

        meta_layout = Fieldset(
            'Meta',
            LookupField('description', css_class='input-xxlarge'),
            LookupImageField('main_image', ),
            LookupField('remote_image', ),
        )

        tagging_layout = Fieldset(
            'Tags',
            LookupField('d_tags'),
        )

        layout = Layout(
            base_layout,
            activity_layout,
            contact_layout,
            meta_layout,
            tagging_layout,
        )

        self.helper.add_layout(layout)

    main_image = forms.Field(widget=FileInput(), required=False)
    remote_image = forms.URLField(required=False)
    d_tags = TagField(widget=TagAutocompleteTagIt(max_tags=9),
                      required=False,
                      label=_('Tags'))
    description = forms.CharField(widget=forms.Textarea(), required=False)
    parent = search_fields.AutocompleteField('alibrary.label',
                                             allow_new=True,
                                             required=False,
                                             label=_('Parent Label'))

    def clean(self, *args, **kwargs):
        cd = super(LabelForm, self).clean()

        try:
            parent = cd['parent']
            if not parent.pk:
                parent.creator = self.user
                parent.save()
        except:
            pass

        try:
            if parent.pk == self.instance.pk:
                self._errors["parent"] = self.error_class(
                    [_('The parent label can not be itself!')])
        except:
            pass

        if cd.get('remote_image', None):
            remote_file = get_file_from_url(cd['remote_image'])
            if remote_file:
                cd['main_image'] = remote_file

        return cd

    def save(self, *args, **kwargs):
        return super(LabelForm, self).save(*args, **kwargs)
Beispiel #7
0
class MediaForm(ModelForm):
    class Meta:
        model = Media
        fields = (
            'name',
            'description',
            'lyrics',
            'lyrics_language',
            'artist',
            'tracknumber',
            'medianumber',
            'opus_number',
            'mediatype',
            'version',
            # 'filename',
            'license',
            'release',
            'd_tags',
            'isrc',
        )

    def __init__(self, *args, **kwargs):

        self.user = kwargs['initial']['user']
        self.instance = kwargs['instance']

        self.label = kwargs.pop('label', None)

        super(MediaForm, self).__init__(*args, **kwargs)
        """
        Prototype function, set some fields to readonly depending on permissions
        """
        # if not self.user.has_perm("alibrary.admin_release", self.instance) and self.instance.release and self.instance.release.publish_date:
        if not self.user.has_perm("alibrary.admin_release", self.instance):
            # self.fields['license'].widget.attrs['disabled'] = 'disabled'
            self.fields['license'].widget.attrs['readonly'] = 'readonly'

        self.helper = FormHelper()
        self.helper.form_tag = False

        # rewrite labels
        self.fields['medianumber'].label = _('Disc number')
        self.fields['opus_number'].label = _('Opus N.')
        # self.fields['filename'].label = _('Orig. Filename')

        base_layout = Fieldset(
            _('General'),
            LookupField('name', css_class='input-xlarge'),
            LookupField('release', css_class='input-xlarge'),
            LookupField('artist', css_class='input-xlarge'),
            LookupField('mediatype', css_class='input-xlarge'),
            LookupField('tracknumber', css_class='input-xlarge'),
            Field('medianumber', css_class='input-xlarge'),
            Field('opus_number', css_class='input-xlarge'),
            Field('version', css_class='input-xlarge'),
            HTML(
                '<div style="opacity: 0.5;"><span style="padding: 0 44px 0 0;">Orig. Filename:</span>%s</div>'
                % self.instance.original_filename),
        )

        identifiers_layout = Fieldset(
            _('Identifiers'),
            LookupField('isrc', css_class='input-xlarge'),
        )

        license_layout = Fieldset(
            _('License/Source'),
            Field('license', css_class='input-xlarge'),
        )

        meta_layout = Fieldset(
            'Meta',
            LookupField('description', css_class='input-xlarge'),
        )

        lyrics_layout = Fieldset(
            'Lyrics',
            LookupField('lyrics_language', css_class='input-xlarge'),
            LookupField('lyrics', css_class='input-xlarge'),
        )

        tagging_layout = Fieldset(
            'Tags',
            LookupField('d_tags'),
        )

        layout = Layout(
            base_layout,
            HTML('<div id="artist_relation_container"></div>'),
            identifiers_layout,
            license_layout,
            meta_layout,
            lyrics_layout,
            tagging_layout,
        )

        self.helper.add_layout(layout)

    d_tags = TagField(widget=TagAutocompleteTagIt(max_tags=9),
                      required=False,
                      label=_('Tags'))
    release = search_fields.AutocompleteField('alibrary.release',
                                              allow_new=True,
                                              required=False,
                                              label=_('Release'))

    name = forms.CharField(required=True, label='Title')
    artist = search_fields.AutocompleteField('alibrary.artist',
                                             allow_new=True,
                                             required=False,
                                             label=_('Artist'))
    description = forms.CharField(widget=forms.Textarea(), required=False)

    def clean_license(self):
        instance = getattr(self, 'instance', None)
        if instance and instance.pk and not self.user.has_perm(
                "alibrary.admin_release", instance):
            return instance.license
        else:
            return self.cleaned_data['license']

    def clean(self, *args, **kwargs):

        cd = super(MediaForm, self).clean()

        # hack. allow_new in AutoCompleteSelectField does _not_ automatically create new objects???
        try:
            artist = cd['artist']
            if not artist.pk:
                artist.creator = self.user
                artist.save()
        except:
            pass

        try:
            release = cd['release']
            if not release.pk:
                release.creator = self.user
                release.save()

        except:
            pass

        return cd

    # TODO: take a look at save
    def save(self, *args, **kwargs):
        return super(MediaForm, self).save(*args, **kwargs)
Beispiel #8
0
class ReleaseBulkeditForm(Form):
    def __init__(self, *args, **kwargs):

        self.instance = kwargs.pop('instance', False)
        self.disable_license = False
        """
        # publishing removed
        if self.instance and self.instance.publish_date:
            self.disable_license = True
        """
        super(ReleaseBulkeditForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        form_class = 'input-xlarge'
        if self.disable_license:
            form_class = 'hidden'

        base_layout = Div(
            Div(
                HTML('<p>"%s": %s</p>' % (
                    _('Bulk Edit'),
                    _('Choose Artist name and/or license to apply on each track.'
                      )))),
            Row(
                Column(Field('bulk_artist_name', css_class='input-xlarge'),
                       css_class='main'),
                Column(HTML(
                    '<button type="button" id="bulk_apply_artist_name" value="apply" class="btn btn-mini pull-right bulk_apply" id="submit-"><i class="icon-plus"></i> %s</button>'
                    % _('Apply Artist to all tracks')),
                       css_class='side'),
                css_class='bulkedit-row row-fluid',
            ),
            Row(
                Column(Field('bulk_license', css_class=form_class),
                       css_class='main'),
                Column(HTML(
                    '<button type="button" id="bulk_apply_license" value="apply" class="btn btn-mini pull-right bulk_apply" id="submit-"><i class="icon-plus"></i> %s</button>'
                    % _('Apply License to all tracks')),
                       css_class='side'),
                css_class='bulkedit-row row-fluid',
            ),
            css_class='bulk_edit',
        )

        self.helper.add_layout(base_layout)

    bulk_artist_name = search_fields.AutocompleteField('alibrary.artist',
                                                       allow_new=True,
                                                       required=False,
                                                       label=_('Artist'))
    bulk_license = forms.ModelChoiceField(
        queryset=License.objects.filter(selectable=True),
        required=False,
        label=_('License'))

    def save(self, *args, **kwargs):
        return True
Beispiel #9
0
class ReleaseForm(ModelForm):
    class Meta:
        model = Release
        fields = (
            'name',
            'label',
            'releasetype',
            'totaltracks',
            'release_country',
            'catalognumber',
            'description',
            'main_image',
            'releasedate_approx',
            'd_tags',
            'barcode',
        )

    def __init__(self, *args, **kwargs):

        self.user = kwargs['initial']['user']
        self.instance = kwargs['instance']
        self.label = kwargs.pop('label', None)

        super(ReleaseForm, self).__init__(*args, **kwargs)
        """
        Prototype function, set some fields to readonly depending on permissions
        """
        if not self.user.has_perm("alibrary.admin_release", self.instance):
            self.fields['catalognumber'].widget.attrs['readonly'] = 'readonly'

        self.helper = FormHelper()
        self.helper.form_id = "id_feedback_form_%s" % 'asd'
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        # TODO: this is very ugly!
        unknown_label, c = Label.objects.get_or_create(slug='unknown')
        if c:
            Label.objects.filter(pk=unknown_label.pk).update(
                name='Unknown label', slug='unknown')

        noton_label, c = Label.objects.get_or_create(
            slug='not-on-label-self-released')
        if c:
            Label.objects.filter(pk=unknown_label.pk).update(
                name='Not on Label / Self Released',
                slug='not-on-label-self-released')

        base_layout = Fieldset(
            _('General'),
            LookupField('name', css_class='input-xlarge'),
            LookupField('releasetype', css_class='input-xlarge'),
            LookupField('totaltracks', css_class='input-xlarge'),
        )

        catalog_layout = Fieldset(
            _('Label/Catalog'),
            LookupField('label', css_class='input-xlarge'),
            HTML(
                """<ul class="horizontal unstyled clearfix action label-select">
                <li><a data-label="%s" data-label_id="%s" href="#"><i class="icon-double-angle-right"></i> %s</a></li>
                <li><a data-label="%s" data-label_id="%s" href="#"><i class="icon-double-angle-right"></i> %s</a></li>
            </ul>""" %
                (unknown_label.name, unknown_label.pk, unknown_label.name,
                 noton_label.name, noton_label.pk, noton_label.name)),
            LookupField('catalognumber', css_class='input-xlarge'),
            LookupField('release_country', css_class='input-xlarge'),
            LookupField('releasedate_approx', css_class='input-xlarge'),
        )

        meta_layout = Fieldset(
            'Meta',
            LookupField('description', css_class='input-xxlarge'),
            LookupImageField('main_image', ),
            LookupField('remote_image', ),
        )

        tagging_layout = Fieldset(
            'Tags',
            LookupField('d_tags'),
        )

        identifiers_layout = Fieldset(
            _('Identifiers'),
            LookupField('barcode', css_class='input-xlarge'),
        )

        layout = Layout(
            base_layout,
            HTML('<div id="artist_relation_container"></div>'),
            meta_layout,
            catalog_layout,
            identifiers_layout,
            tagging_layout,
        )

        self.helper.add_layout(layout)

    main_image = forms.Field(widget=AdvancedFileInput(), required=False)
    remote_image = forms.URLField(required=False)
    releasedate_approx = ApproximateDateFormField(label="Releasedate",
                                                  required=False)
    d_tags = TagField(widget=TagAutocompleteTagIt(max_tags=9),
                      required=False,
                      label=_('Tags'))

    label = search_fields.AutocompleteField('alibrary.label',
                                            allow_new=True,
                                            required=False)

    description = forms.CharField(widget=forms.Textarea(), required=False)

    # TODO: rework clean function
    def clean(self, *args, **kwargs):

        cd = super(ReleaseForm, self).clean()

        try:
            label = cd['label']
            if not label.pk:
                label.creator = self.user
                label.save()
        except:
            pass

        if cd.get('remote_image', None):
            remote_file = get_file_from_url(cd['remote_image'])
            if remote_file:
                cd['main_image'] = remote_file

        return cd

    def save(self, *args, **kwargs):
        return super(ReleaseForm, self).save(*args, **kwargs)
Beispiel #10
0
class PlaylistForm(ModelForm):
    class Meta:
        model = Playlist
        fields = [
            'name',
            'd_tags',
            'description',
            'main_image',
            #'playout_mode_random',
            'rotation',
            'rotation_date_start',
            'rotation_date_end',
            'dayparts',
            'weather',
            'seasons',
            'target_duration',
            'series',
            'series_number'
        ]

        widgets = {
            'rotation_date_start':
            SelectDateWidget(
                years=ROTATION_YEAR_CHOICES,
                empty_label=(_('Year'), _('Month'), _('Day')),
            ),
            'rotation_date_end':
            SelectDateWidget(
                years=ROTATION_YEAR_CHOICES,
                empty_label=(_('Year'), _('Month'), _('Day')),
            ),
        }

    def __init__(self, *args, **kwargs):

        try:
            self.user = kwargs['initial']['user']
            self.instance = kwargs['instance']
        except:
            pass

        super(PlaylistForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_tag = False

        self.fields['name'].label = _('Title')

        if self.instance.type == 'broadcast':
            self.fields['d_tags'].required = True
            self.fields['dayparts'].required = True
            self.fields['target_duration'].required = True
            self.fields['target_duration'].widget.attrs[
                'disabled'] = 'disabled'

        if self.instance.type == 'playlist':
            self.fields['d_tags'].required = True

        base_layout = Fieldset(
            _('General'),
            #Div(HTML('<h4>%s</h4><p>%s</p>' % (_('Bulk Edit'), _('Choose Artist name and/or license to apply on every track.'))), css_class='form-help'),
            Field('name', css_class='input-xlarge'),
            Div(Field('target_duration'), css_class='target-duration'),
            Field('description', css_class='input-xlarge'),
            'main_image',
            css_class='base')

        series_layout = Fieldset("%s %s" %
                                 ('<i class="icon-tags"></i>', _('Series')),
                                 Div(Field('series', css_class='input-xlarge'),
                                     css_class='series'),
                                 Div(Field('series_number',
                                           css_class='input-xlarge'),
                                     css_class='series-number'),
                                 css_class='series')

        tagging_layout = Fieldset("%s %s" %
                                  ('<i class="icon-tags"></i>', _('Tags')),
                                  'd_tags',
                                  css_class='tagging')

        playout_mode_layout = Fieldset(
            "%s %s" % ('<i class="icon-random"></i>', _('Playout Mode')),
            'playout_mode_random',
            css_class='playout-mode')

        rotation_layout = Fieldset(
            "%s %s" % ('<i class="icon-random"></i>', _('Random Rotation')),
            'rotation',
            'rotation_date_start',
            'rotation_date_end',
            css_class='rotation')

        daypart_layout = Fieldset(
            "%s %s" %
            ('<i class="icon-calendar"></i>', _('Best Broadcast...')),
            Div(Field('dayparts'), css_class='dayparts'),
            Div(Field('seasons'), css_class='seasons'),
            Div(Field('weather'), css_class='weather'),
            css_class='daypart')

        layout = Layout(
            base_layout,
            tagging_layout,
            series_layout,
            #playout_mode_layout,
            rotation_layout,
            daypart_layout,
        )

        self.helper.add_layout(layout)

    # main_image = forms.Field(widget=FileInput(), required=False)
    main_image = forms.Field(widget=AdvancedFileInput(), required=False)
    d_tags = TagField(widget=TagAutocompleteTagIt(max_tags=9),
                      required=False,
                      label=_('Tags'))
    description = forms.CharField(widget=forms.Textarea(), required=False)

    rotation = forms.BooleanField(
        required=False,
        label=_('Include in rotation'),
        help_text=
        _('Allow this broadcast to be aired at random time if nothing else is scheduled.'
          ))

    series = search_fields.AutocompleteField('alibrary.series',
                                             allow_new=True,
                                             required=False)

    target_duration = forms.ChoiceField(
        widget=forms.RadioSelect,
        choices=alibrary_settings.PLAYLIST_TARGET_DURATION_CHOICES,
        required=False)
    dayparts = forms.ModelMultipleChoiceField(
        label='...%s' % _('Dayparts'),
        widget=DaypartWidget(),
        queryset=Daypart.objects.active(),
        required=False)

    seasons = forms.ModelMultipleChoiceField(
        label='...%s' % _('Seasons'),
        queryset=Season.objects.all(),
        required=False,
        widget=forms.CheckboxSelectMultiple)
    weather = forms.ModelMultipleChoiceField(
        label='...%s' % _('Weather'),
        queryset=Weather.objects.all(),
        required=False,
        widget=forms.CheckboxSelectMultiple)

    def clean(self, *args, **kwargs):
        cd = super(PlaylistForm, self).clean()
        series = cd['series']
        try:
            if not series.pk:
                series.save()
        except:
            pass

        return cd

    def clean_target_duration(self):
        target_duration = self.cleaned_data['target_duration']

        try:
            return int(target_duration)
        except:
            return None

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