Split page views into seperate files
This commit is contained in:
parent
3cb504d4ed
commit
55fe1910f6
8 changed files with 72 additions and 69 deletions
|
@ -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<project>.+)/$', 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<project>.+)/$', views.projects.ProjectView.as_view(), name="projects"),
|
||||
url(r'^$', views.core.IndexView.as_view(), name='index')
|
||||
]
|
||||
|
|
|
@ -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)
|
1
project/pages/views/__init__.py
Normal file
1
project/pages/views/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from . import about, core, projects
|
28
project/pages/views/about.py
Normal file
28
project/pages/views/about.py
Normal file
|
@ -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"
|
24
project/pages/views/core.py
Normal file
24
project/pages/views/core.py
Normal file
|
@ -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)
|
11
project/pages/views/projects.py
Normal file
11
project/pages/views/projects.py
Normal file
|
@ -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)
|
|
@ -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 = [
|
||||
|
|
2
runtests
2
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:
|
||||
|
|
Reference in a new issue