diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms_common.py | 24 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/form.html | 6 | ||||
-rw-r--r-- | ishtar_common/views.py | 12 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 14 |
4 files changed, 43 insertions, 13 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index d8a4523ab..16c9dd52d 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -45,7 +45,7 @@ from .forms import FinalForm, FormSet, reverse_lazy, name_validator, \ TableSelect, ManageOldType, CustomForm, FieldType, FormHeader, \ FormSetWithDeleteSwitches, BSForm, get_data_from_formset, \ file_size_validator, HistorySelect, CustomFormSearch, QAForm, IshtarForm, \ - MultiSearchForm + MultiSearchForm, LockForm from ishtar_common.utils import is_downloadable, clean_session_cache, \ max_size_help @@ -1371,7 +1371,7 @@ class DocumentSelect(HistorySelect): } -class DocumentFormSelection(CustomFormSearch): +class DocumentFormSelection(LockForm, CustomFormSearch): SEARCH_AND_SELECT = True form_label = _(u"Document search") associated_models = {'pk': models.Document} @@ -1386,11 +1386,21 @@ class DocumentFormSelection(CustomFormSearch): ), validators=[models.valid_id(models.Document)]) - def clean(self): - cleaned_data = self.cleaned_data - if 'pk' not in cleaned_data or not cleaned_data['pk']: - raise forms.ValidationError(_(u"You should select an item.")) - return cleaned_data + +class DocumentFormMultiSelection(LockForm, MultiSearchForm): + form_label = _(u"Document search") + associated_models = {'pks': models.Document} + pk_key = 'pks' + + pk = forms.CharField( + label="", required=False, + widget=widgets.DataTable( + reverse_lazy('get-document'), DocumentSelect, + models.Document, + multiple_select=True, + gallery=True + ), + validators=[models.valid_ids(models.Document)]) class QADocumentFormMulti(QAForm): diff --git a/ishtar_common/templates/ishtar/form.html b/ishtar_common/templates/ishtar/form.html index 03bd0d207..29960125c 100644 --- a/ishtar_common/templates/ishtar/form.html +++ b/ishtar_common/templates/ishtar/form.html @@ -35,5 +35,11 @@ {% include 'ishtar/blocks/footer.html' %} </div> </form> +{% if open_url %} +<script language="javascript" type="text/javascript"> +$(document).ready(function(){ + {% if open_url %}load_window("{{open_url}}");{% endif %} +}); +</script>{% endif %} {% endblock %} diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 150dfa2ca..710d6d7e6 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -1887,7 +1887,7 @@ class DocumentFormMixin(IshtarMixin, LoginRequiredMixin): model = models.Document def get_success_url(self): - return reverse('display-document', args=[self.object.pk]) + return reverse("edit-document") + "?open_item={}".format(self.object.pk) class DocumentCreateView(DocumentFormMixin, CreateView): @@ -1919,6 +1919,14 @@ class DocumentSelectView(IshtarMixin, LoginRequiredMixin, self.pk = form.cleaned_data['pk'] return super(DocumentSelectView, self).form_valid(form) + def get_context_data(self, **kwargs): + data = super(DocumentSelectView, self).get_context_data(**kwargs) + if self.request.GET and "open_item" in self.request.GET: + data["open_url"] =\ + reverse("show-document", + args=[self.request.GET["open_item"]]) + "/" + return data + def get_success_url(self): return reverse(self.redir_url, args=[self.pk]) @@ -1964,7 +1972,7 @@ class DocumentEditView(DocumentFormMixin, UpdateView): document_deletion_steps = [ - ('selec-document_deletion', forms.DocumentFormSelection), + ('selec-document_deletion', forms.DocumentFormMultiSelection), ('final-document_deletion', FinalDeleteForm) ] diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 7802f82cb..1ad394f25 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -1959,11 +1959,17 @@ class SourceWizard(Wizard): return dct -class DocumentDeletionWizard(DeletionWizard): +DOCUMENT_EXCLUDED = models.Document.RELATED_MODELS + [ + "id", "history_creator", "history_modifier", "search_vector", "imports", + "last_modified" +] + + +class DocumentDeletionWizard(MultipleDeletionWizard): model = models.Document fields = [ f.name for f in models.Document._meta.get_fields() - if f.name != 'id' and f.name not in models.Document.RELATED_MODELS] + if f.name not in DOCUMENT_EXCLUDED] fields += models.Document.RELATED_MODELS - filter_owns = {'selec-document_deletion': ['pk']} - + filter_owns = {'selec-document_deletion': ['pks']} + redirect_url = "document_deletion" |