From 55fe1910f62b4bd8d3d7dbbe72096dadb4f79653 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 26 Jan 2016 18:25:20 +0000 Subject: [PATCH] Split page views into seperate files --- project/pages/urls.py | 12 +++---- project/pages/views.py | 61 --------------------------------- project/pages/views/__init__.py | 1 + project/pages/views/about.py | 28 +++++++++++++++ project/pages/views/core.py | 24 +++++++++++++ project/pages/views/projects.py | 11 ++++++ project/urls.py | 2 +- runtests | 2 +- 8 files changed, 72 insertions(+), 69 deletions(-) delete mode 100644 project/pages/views.py create mode 100644 project/pages/views/__init__.py create mode 100644 project/pages/views/about.py create mode 100644 project/pages/views/core.py create mode 100644 project/pages/views/projects.py diff --git a/project/pages/urls.py b/project/pages/urls.py index 05e1064..f5b0c9b 100644 --- a/project/pages/urls.py +++ b/project/pages/urls.py @@ -3,10 +3,10 @@ from . import views urlpatterns = [ - url(r'^about/website/$', views.AboutWebsiteView.as_view(), name='about-website'), - url(r'^about/me/$', views.AboutMeView.as_view(), name='about-me'), - url(r'^about/$', views.AboutIndexView.as_view(), name='about'), - url(r'^projects/all/$', views.AllProjectsView.as_view(), name="all-projects"), - url(r'^projects/(?P.+)/$', views.ProjectsView.as_view(), name="projects"), - url(r'^$', views.IndexView.as_view(), name='index') + url(r'^about/website/$', views.about.WebsiteView.as_view(), name='about-website'), + url(r'^about/me/$', views.about.MeView.as_view(), name='about-me'), + url(r'^about/$', views.about.IndexView.as_view(), name='about'), + url(r'^projects/all/$', views.projects.AllView.as_view(), name="all-projects"), + url(r'^projects/(?P.+)/$', views.projects.ProjectView.as_view(), name="projects"), + url(r'^$', views.core.IndexView.as_view(), name='index') ] diff --git a/project/pages/views.py b/project/pages/views.py deleted file mode 100644 index f9bbb88..0000000 --- a/project/pages/views.py +++ /dev/null @@ -1,61 +0,0 @@ -from project.common.views import CustomTemplate, CustomFormTemplate, MarkdownView -from project.common.forms import ContactForm - - -class IndexView(CustomTemplate): - template_name = 'index.html' - html_title = "Homepage" - body_class = "index" - - -class NoJavascriptView(CustomTemplate): - template_name = 'core/no-js.html' - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context['js_redirect'] = False - return context - - -class Custom404View(CustomTemplate): - template_name = 'core/404.html' - - def get(self, request, *args, **kwargs): - context = self.get_context_data(**kwargs) - return self.render_to_response(context, status=404) - - -class AboutWebsiteView(CustomTemplate): - template_name = 'about/website.html' - html_title = "About website" - - -class AboutIndexView(CustomFormTemplate): - template_name = 'about/index.html' - html_title = "About" - success_url = '/about/?sent' - form_class = ContactForm - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context['sent'] = 'sent' not in self.request.GET - return context - - def form_valid(self, form): - form.send_email() - return super().form_valid(form) - - -class AboutMeView(CustomTemplate): - template_name = 'about/me.html' - html_title = "About Me" - - -class AllProjectsView(CustomTemplate): - template_name = 'projects/all.html' - - -class ProjectsView(MarkdownView): - def dispatch(self, request, *args, **kwargs): - self.markdown = 'projects/{0}.md'.format(kwargs['project']) - return super().dispatch(request, *args, **kwargs) diff --git a/project/pages/views/__init__.py b/project/pages/views/__init__.py new file mode 100644 index 0000000..a58b58c --- /dev/null +++ b/project/pages/views/__init__.py @@ -0,0 +1 @@ +from . import about, core, projects diff --git a/project/pages/views/about.py b/project/pages/views/about.py new file mode 100644 index 0000000..238ff9e --- /dev/null +++ b/project/pages/views/about.py @@ -0,0 +1,28 @@ +from project.common.views import CustomTemplate, CustomFormTemplate +from project.common.forms import ContactForm + + +class WebsiteView(CustomTemplate): + template_name = 'about/website.html' + html_title = "About website" + + +class IndexView(CustomFormTemplate): + template_name = 'about/index.html' + html_title = "About" + success_url = '/about/?sent' + form_class = ContactForm + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['sent'] = 'sent' not in self.request.GET + return context + + def form_valid(self, form): + form.send_email() + return super().form_valid(form) + + +class MeView(CustomTemplate): + template_name = 'about/me.html' + html_title = "About Me" diff --git a/project/pages/views/core.py b/project/pages/views/core.py new file mode 100644 index 0000000..b02b82f --- /dev/null +++ b/project/pages/views/core.py @@ -0,0 +1,24 @@ +from project.common.views import CustomTemplate + + +class IndexView(CustomTemplate): + template_name = 'index.html' + html_title = "Homepage" + body_class = "index" + + +class NoJavascriptView(CustomTemplate): + template_name = 'core/no-js.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['js_redirect'] = False + return context + + +class Custom404View(CustomTemplate): + template_name = 'core/404.html' + + def get(self, request, *args, **kwargs): + context = self.get_context_data(**kwargs) + return self.render_to_response(context, status=404) diff --git a/project/pages/views/projects.py b/project/pages/views/projects.py new file mode 100644 index 0000000..6cb5cd6 --- /dev/null +++ b/project/pages/views/projects.py @@ -0,0 +1,11 @@ +from project.common.views import CustomTemplate, MarkdownView + + +class AllView(CustomTemplate): + template_name = 'projects/all.html' + + +class ProjectView(MarkdownView): + def dispatch(self, request, *args, **kwargs): + self.markdown = 'projects/{0}.md'.format(kwargs['project']) + return super().dispatch(request, *args, **kwargs) diff --git a/project/urls.py b/project/urls.py index e45472c..cdd8c78 100644 --- a/project/urls.py +++ b/project/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import include, url from django_client_reverse import urls as reverse_urls -from project.pages.views import Custom404View, NoJavascriptView +from project.pages.views.core import Custom404View, NoJavascriptView urlpatterns = [ diff --git a/runtests b/runtests index cf6baf7..335b6de 100755 --- a/runtests +++ b/runtests @@ -48,7 +48,7 @@ print(Fore.GREEN + "Coverage Complete.") FLAKE8_IGNORE = '--ignore=E128,E501,E401' try: - subprocess.check_output([os.path.join(bin_dir, 'flake8'), 'project', FLAKE8_IGNORE, '--exclude=migrations,settings,wsgi.py']) + subprocess.check_output([os.path.join(bin_dir, 'flake8'), 'project', FLAKE8_IGNORE, '--exclude=migrations,settings,wsgi.py,__init__.py']) subprocess.check_output([os.path.join(bin_dir, 'flake8'), 'scripts', FLAKE8_IGNORE]) subprocess.check_output([os.path.join(bin_dir, 'flake8'), sys.argv[0], FLAKE8_IGNORE]) except subprocess.CalledProcessError as e: