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

View File

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