Tag new case studies with their language

This commit is contained in:
Anna Sidwell 2019-03-04 20:37:39 +00:00
parent 0c594487a9
commit 3c45e38fd5
2 changed files with 16 additions and 5 deletions

View File

@ -7,6 +7,7 @@ from django.db.models import Q
from django.http import Http404, HttpResponse
from django.urls import reverse
from django.urls import reverse_lazy
from django.utils.translation import get_language
from django.views import View
from django.views.generic import DetailView
from django.views.generic.base import TemplateView
@ -100,15 +101,12 @@ class FilesHandlerMixin:
'images_files', []
))
def form_valid(self, form):
def handle_files(self, form):
self.remove_bad_fields(form)
self.object.author = self.request.user
self.object = form.save()
self.add_file_refs(form)
self.object.save()
return super().form_valid(form)
class BaseCreateForm(LoginRequiredMixin, FilesHandlerMixin, CreateView):
"""View for base case study form."""
@ -117,11 +115,17 @@ class BaseCreateForm(LoginRequiredMixin, FilesHandlerMixin, CreateView):
model = CaseStudy
def form_valid(self, form):
super().form_valid(form)
self.handle_files(form)
self.object.author = self.request.user
self.object.language = get_language()
self.object.save()
send_email(self.object.id)
delete_user_draft(self.request.user)
return super().form_valid(form)
class CreateShortCaseStudy(BaseCreateForm):
"""View for short version of case study form."""
@ -149,6 +153,11 @@ class BaseEditForm(LoginRequiredMixin, FilesHandlerMixin, UpdateView):
success_url = reverse_lazy('form-success')
model = CaseStudy
def form_valid(self, form):
self.handle_files(form)
return super().form_valid(form)
class EditCaseStudy(UserPassesTestMixin, BaseEditForm):
form_class = ShortCaseStudyForm

View File

@ -29,6 +29,7 @@
<thead>
<tr>
<th>Name
<th>Language
<th>Approved
<th>Actions
</thead>
@ -36,6 +37,7 @@
{% for case in case_studies %}
<tr>
<td>{{ case.entry_name }}
<td>{% if case.language %}{{ case.language }}{% else %}-{% endif %}
<td>{% if case.approved %}Yes{% else %}No{% endif %}
<td>
<a href="{% url 'detail' case.slug %}">View</a> |