X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/3263fb5558f69c727e61a6d4c0b3575a0f081ef6..ddf19efc791510fde4615c00cc85299c213d5924:/apps/catalogue/forms.py diff --git a/apps/catalogue/forms.py b/apps/catalogue/forms.py index e286a1d5..36dbef73 100644 --- a/apps/catalogue/forms.py +++ b/apps/catalogue/forms.py @@ -26,12 +26,8 @@ class DocumentCreateForm(forms.Form): """ owner_organization = forms.CharField(required=False) title = forms.CharField() - language = forms.CharField() publisher = forms.CharField(required=False) description = forms.CharField(required=False) - rights = forms.CharField(required=False) - audience = forms.CharField() - cover = forms.FileField(required=False) def clean_cover(self): @@ -56,22 +52,27 @@ class TagForm(forms.Form): 'data-content': category.tutorial, }) if self.instance: - self.field().initial = self.initial() + self.field().initial = self.get_initial() - def save(self): - assert self.instance, 'No instance provided' - self.instance.tags.remove(*self.instance.tags.filter(category=self.category)) - self.instance.tags.add(self.cleaned_tags()) + def save(self, instance=None): + instance = instance or self.instance + assert instance, 'No instance provided' + self.category.set_tags_for(instance, self.cleaned_tags()) def field(self): raise NotImplementedError - def initial(self): + def get_initial(self): raise NotImplementedError def cleaned_tags(self): raise NotImplementedError + def metadata_rows(self): + return '\n'.join( + '%(value)s' % {'name': tag.category.dc_tag, 'value': tag.dc_value} + for tag in self.cleaned_tags()) + class TagSelect(forms.Select): def render_option(self, selected_choices, option_value, option_label): @@ -106,7 +107,7 @@ class TagSingleForm(TagForm): def field(self): return self.fields['tag'] - def initial(self): + def get_initial(self): return self.instance.tags.get(category=self.category) def cleaned_tags(self): @@ -124,7 +125,7 @@ class TagMultipleForm(TagForm): def field(self): return self.fields['tags'] - def initial(self): + def get_initial(self): return self.instance.tags.filter(category=self.category) def cleaned_tags(self):