diff --git a/apis_bibsonomy/templates/apis_bibsonomy/partials/autofill_bibsonomy.html b/apis_bibsonomy/templates/apis_bibsonomy/partials/autofill_bibsonomy.html new file mode 100644 index 0000000..81f59b2 --- /dev/null +++ b/apis_bibsonomy/templates/apis_bibsonomy/partials/autofill_bibsonomy.html @@ -0,0 +1,18 @@ +{% comment %} +iterate through the `last_bibsonomy_reference` that is set in +the session and use it to fill out the `bibs_url` form field +{% endcomment %} + + diff --git a/apis_bibsonomy/templates/apis_bibsonomy/partials/reference_list.html b/apis_bibsonomy/templates/apis_bibsonomy/partials/reference_list.html index 7b97793..bb35905 100644 --- a/apis_bibsonomy/templates/apis_bibsonomy/partials/reference_list.html +++ b/apis_bibsonomy/templates/apis_bibsonomy/partials/reference_list.html @@ -30,4 +30,5 @@ {% include "apis_bibsonomy/partials/reinit_select2.html" %} {% include "apis_bibsonomy/partials/fix_select2_bootstrap_focus.html" %} +{% include "apis_bibsonomy/partials/autofill_bibsonomy.html" %} diff --git a/apis_bibsonomy/views.py b/apis_bibsonomy/views.py index 943de8c..b76df08 100644 --- a/apis_bibsonomy/views.py +++ b/apis_bibsonomy/views.py @@ -63,6 +63,12 @@ def get_success_url(self): def form_valid(self, form): args = form.cleaned_data + # we store the data about the last entered entry in the session + # so we can automatically fill the form with the last reference + self.request.session["last_bibsonomy_reference"] = form.cleaned_data.copy() + ref = Reference.objects.filter(bibs_url=form.cleaned_data['bibs_url']).order_by("last_update").first() + self.request.session["last_bibsonomy_reference_title"] = ref.bibtexjson.get("title") + args['content_type'] = ContentType.objects.get_for_id(self.request.resolver_match.kwargs['contenttype']) args['object_id'] = self.request.resolver_match.kwargs['pk'] ref = Reference.objects.create(**args)