Clean up imports

This commit is contained in:
Anna Sidwell 2019-08-20 00:01:58 +02:00
parent 3e5b41de1d
commit dcb8f4beec
2 changed files with 21 additions and 26 deletions

View File

@ -20,11 +20,6 @@ from django.views.generic.edit import UpdateView
from . import forms from . import forms
from . import models from . import models
from .forms import LongCaseStudyForm
from .forms import ShortCaseStudyForm
from .models import CaseStudy
from .models import CaseStudyDraft
from .models import SpatialRefSys
from apps.files.models import File from apps.files.models import File
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -85,9 +80,9 @@ def delete_user_draft(user_id):
""" Delete the draft of a given user """ """ Delete the draft of a given user """
try: try:
draft = CaseStudyDraft.objects.get(author=user_id) draft = models.CaseStudyDraft.objects.get(author=user_id)
draft.delete() draft.delete()
except CaseStudyDraft.DoesNotExist: except models.CaseStudyDraft.DoesNotExist:
pass pass
@ -120,7 +115,7 @@ class BaseCreateForm(LoginRequiredMixin, FilesHandlerMixin, CreateView):
template_name = "map/form-case_study.html" template_name = "map/form-case_study.html"
success_url = reverse_lazy("form-success") success_url = reverse_lazy("form-success")
model = CaseStudy model = models.CaseStudy
def form_valid(self, form): def form_valid(self, form):
self.handle_files(form) self.handle_files(form)
@ -139,14 +134,14 @@ class BaseCreateForm(LoginRequiredMixin, FilesHandlerMixin, CreateView):
class CreateShortCaseStudy(BaseCreateForm): class CreateShortCaseStudy(BaseCreateForm):
"""View for short version of case study form.""" """View for short version of case study form."""
form_class = ShortCaseStudyForm form_class = forms.ShortCaseStudyForm
form_type = "short" form_type = "short"
class CreateLongCaseStudy(BaseCreateForm): class CreateLongCaseStudy(BaseCreateForm):
"""View for long version of case study form.""" """View for long version of case study form."""
form_class = LongCaseStudyForm form_class = forms.LongCaseStudyForm
form_type = "long" form_type = "long"
@ -156,7 +151,7 @@ class CreateCaseStudySuccess(TemplateView):
class ViewCaseStudyDetail(DetailView): class ViewCaseStudyDetail(DetailView):
template_name = "map/detail.html" template_name = "map/detail.html"
model = CaseStudy model = models.CaseStudy
context_object_name = "case_study" context_object_name = "case_study"
@ -165,7 +160,7 @@ class BaseEditForm(LoginRequiredMixin, FilesHandlerMixin, UpdateView):
template_name = "map/form-case_study.html" template_name = "map/form-case_study.html"
success_url = reverse_lazy("form-success") success_url = reverse_lazy("form-success")
model = CaseStudy model = models.CaseStudy
def form_valid(self, form): def form_valid(self, form):
self.handle_files(form) self.handle_files(form)
@ -174,7 +169,7 @@ class BaseEditForm(LoginRequiredMixin, FilesHandlerMixin, UpdateView):
class EditCaseStudy(UserPassesTestMixin, BaseEditForm): class EditCaseStudy(UserPassesTestMixin, BaseEditForm):
form_class = ShortCaseStudyForm form_class = forms.ShortCaseStudyForm
def test_func(self): def test_func(self):
if settings.FFCAN_EDIT is False: if settings.FFCAN_EDIT is False:
@ -191,7 +186,7 @@ class EditCaseStudy(UserPassesTestMixin, BaseEditForm):
class SpatialRefSysAutocomplete(autocomplete.Select2QuerySetView): class SpatialRefSysAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self): def get_queryset(self):
qs = SpatialRefSys.objects.all() qs = models.SpatialRefSys.objects.all()
if self.q: if self.q:
qs = qs.filter( qs = qs.filter(
@ -215,14 +210,14 @@ class DraftsAPI(LoginRequiredMixin, View):
def put(self, request): def put(self, request):
try: try:
draft = CaseStudyDraft.objects.get(author=request.user) draft = models.CaseStudyDraft.objects.get(author=request.user)
draft.data = request.body.decode() draft.data = request.body.decode()
draft.save() draft.save()
return HttpResponse(status=200) # OK return HttpResponse(status=200) # OK
except models.CaseStudyDraft.DoesNotExist: except models.CaseStudyDraft.DoesNotExist:
# If it doesn't exist, create it # If it doesn't exist, create it
CaseStudyDraft.objects.create( models.CaseStudyDraft.objects.create(
author=request.user, data=request.body.decode() author=request.user, data=request.body.decode()
) )
return HttpResponse(status=201) # Created return HttpResponse(status=201) # Created

View File

@ -1,5 +1,6 @@
from django.conf.urls import include from django.urls import include
from django.conf.urls import url from django.conf.urls import url
from django.urls import path
from django.conf.urls.i18n import i18n_patterns from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin from django.contrib import admin
@ -7,17 +8,16 @@ from .views import LanguageDropdownView
urlpatterns = [ urlpatterns = [
url(r"^api/", include("apps.api.urls")), path("api/", include("apps.api.urls")),
url(r"^admin/", admin.site.urls), path("admin/", admin.site.urls),
url(r"^avatar/", include("avatar.urls")), path("avatar/", include("avatar.urls")),
url(r"^cas/", include("cas_server.urls", namespace="cas_server")), path("cas/", include("cas_server.urls", namespace="cas_server")),
url(r"^files/", include("apps.files.urls")), path("files/", include("apps.files.urls")),
url(r"^set_language/(?P<language>[^/]+)$", LanguageDropdownView.as_view()), url(r"^set_language/(?P<language>[^/]+)$", LanguageDropdownView.as_view()),
# url(r'^contact/', include('apps.contact.urls'), name="contact"),
] ]
urlpatterns += i18n_patterns( urlpatterns += i18n_patterns(
url(r"^accounts/profile/", include("apps.profiles.urls", namespace="profile")), path("accounts/profile/", include("apps.profiles.urls", namespace="profile")),
url(r"^accounts/", include("registration.backends.default.urls")), path("accounts/", include("registration.backends.default.urls")),
url(r"", include("apps.map.urls"), name="map"), path("", include("apps.map.urls"), name="map"),
) )