From 7dd4f7e70ac8c9c14fdf046fde3fe3b290be1700 Mon Sep 17 00:00:00 2001 From: Levi Date: Sun, 10 Apr 2016 16:12:43 -0500 Subject: [PATCH] Moved contact form model in order to be reusable by ungleich app, Created unit test for digitalglarus contact page, Created ungleich contact page, Created unit test for ungleich contact page, Created unit test for forms . --- digitalglarus/admin.py | 5 +- .../migrations/0006_delete_message.py | 18 +++++ digitalglarus/models.py | 13 +--- digitalglarus/templates/contact.html | 2 +- digitalglarus/test_views.py | 23 ++++++ digitalglarus/views.py | 9 +-- dynamicweb/settings/base.py | 3 + dynamicweb/urls.py | 1 + ungleich/models.py | 1 + ungleich/urls.py | 8 +- ungleich/views.py | 7 +- ungleich_page/__init__.py | 0 ungleich_page/admin.py | 3 + ungleich_page/apps.py | 5 ++ ungleich_page/migrations/__init__.py | 0 ungleich_page/models.py | 3 + .../templates/ungleich_page/_footer.html | 40 ++++++++++ .../templates/ungleich_page/_header_base.html | 17 ++++ .../templates/ungleich_page/_menu.html | 36 +++++++++ .../ungleich_page/base_ungleich.html | 78 +++++++++++++++++++ .../templates/ungleich_page/contact.html | 38 +++++++++ .../templates/ungleich_page/index.html | 3 + .../templates/ungleich_page/page.html | 5 ++ ungleich_page/test_views.py | 23 ++++++ {digitalglarus => ungleich_page}/tests.py | 0 ungleich_page/urls.py | 6 ++ ungleich_page/views.py | 25 ++++++ utils/__init__.py | 0 utils/admin.py | 3 + utils/apps.py | 5 ++ {digitalglarus => utils}/forms.py | 4 +- utils/migrations/0001_initial.py | 27 +++++++ utils/migrations/__init__.py | 0 utils/models.py | 14 ++++ utils/test_forms.py | 25 ++++++ utils/tests.py | 3 + utils/views.py | 3 + 37 files changed, 425 insertions(+), 31 deletions(-) create mode 100644 digitalglarus/migrations/0006_delete_message.py create mode 100644 digitalglarus/test_views.py create mode 100644 ungleich_page/__init__.py create mode 100644 ungleich_page/admin.py create mode 100644 ungleich_page/apps.py create mode 100644 ungleich_page/migrations/__init__.py create mode 100644 ungleich_page/models.py create mode 100644 ungleich_page/templates/ungleich_page/_footer.html create mode 100644 ungleich_page/templates/ungleich_page/_header_base.html create mode 100644 ungleich_page/templates/ungleich_page/_menu.html create mode 100644 ungleich_page/templates/ungleich_page/base_ungleich.html create mode 100644 ungleich_page/templates/ungleich_page/contact.html create mode 100644 ungleich_page/templates/ungleich_page/index.html create mode 100644 ungleich_page/templates/ungleich_page/page.html create mode 100644 ungleich_page/test_views.py rename {digitalglarus => ungleich_page}/tests.py (100%) create mode 100644 ungleich_page/urls.py create mode 100644 ungleich_page/views.py create mode 100644 utils/__init__.py create mode 100644 utils/admin.py create mode 100644 utils/apps.py rename {digitalglarus => utils}/forms.py (94%) create mode 100644 utils/migrations/0001_initial.py create mode 100644 utils/migrations/__init__.py create mode 100644 utils/models.py create mode 100644 utils/test_forms.py create mode 100644 utils/tests.py create mode 100644 utils/views.py diff --git a/digitalglarus/admin.py b/digitalglarus/admin.py index 92dea7a0..0c84adb1 100644 --- a/digitalglarus/admin.py +++ b/digitalglarus/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import Message, Supporter, DGGallery, DGPicture +from .models import Supporter, DGGallery, DGPicture +from utils.models import ContactMessage # class DGPictureInline(admin.StackedInline): model = DGPicture @@ -8,5 +9,5 @@ class DGGalleryAdmin(admin.ModelAdmin): inlines = [DGPictureInline] admin.site.register(DGGallery, DGGalleryAdmin) -admin.site.register(Message) +admin.site.register(ContactMessage) admin.site.register(Supporter) \ No newline at end of file diff --git a/digitalglarus/migrations/0006_delete_message.py b/digitalglarus/migrations/0006_delete_message.py new file mode 100644 index 00000000..6cc3e674 --- /dev/null +++ b/digitalglarus/migrations/0006_delete_message.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2016-04-10 17:10 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('digitalglarus', '0005_auto_20160407_0519'), + ] + + operations = [ + migrations.DeleteModel( + name='Message', + ), + ] diff --git a/digitalglarus/models.py b/digitalglarus/models.py index 6c24ae0d..19962a2f 100644 --- a/digitalglarus/models.py +++ b/digitalglarus/models.py @@ -3,21 +3,10 @@ from cms.models import CMSPlugin from filer.fields.image import FilerImageField -class Message(models.Model): - name = models.CharField(max_length=200) - email = models.EmailField() - phone_number = models.CharField(max_length=200) - message = models.TextField() - received_date = models.DateTimeField(auto_now_add=True) - - def __str__(self): - return "%s - %s - %s" % (self.name, self.email, self.received_date) - - class Supporter(models.Model): name = models.CharField(max_length=200) description = models.TextField(null=True, blank=True) - + def __str__(self): return "%s" % (self.name) diff --git a/digitalglarus/templates/contact.html b/digitalglarus/templates/contact.html index bb7447c0..ba12c5ae 100755 --- a/digitalglarus/templates/contact.html +++ b/digitalglarus/templates/contact.html @@ -40,7 +40,7 @@

{% static_placeholder "digital_glarus_contact_form_text" %}

-
+ {% csrf_token %}
diff --git a/digitalglarus/test_views.py b/digitalglarus/test_views.py new file mode 100644 index 00000000..1c5824f5 --- /dev/null +++ b/digitalglarus/test_views.py @@ -0,0 +1,23 @@ +from django.test import TestCase +from django.core.urlresolvers import reverse +from django.core.urlresolvers import resolve + + +class ContactViewTest(TestCase): + + def setUp(self): + self.url = reverse('digitalglarus:contact') + self.data = { + 'name': 'test', + 'email': 'test@gmail.com', + 'phone_number': '32123123123123', + 'message': 'This is a message', + } + + def url_resolve_to_view_correctly(self): + found = resolve(self.url) + self.assertEqual(found.func.__name__, self.view.__name__) + + def test_any_user_should_contact_us(self): + response = self.client.post(self.url, self.data, follow=True) + self.assertEqual(response.status_code, 200) diff --git a/digitalglarus/views.py b/digitalglarus/views.py index 64c6f791..86838336 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -3,23 +3,22 @@ import datetime from django.shortcuts import get_object_or_404, render from django.forms import ModelForm from django.http import HttpResponseRedirect -from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse_lazy from django.utils.translation import get_language from djangocms_blog.models import Post -from django.core.urlresolvers import resolve from django.contrib import messages from django.utils.translation import ugettext as _ -from .models import Message, Supporter -from .forms import ContactUsForm +from .models import Supporter +from utils.forms import ContactUsForm from django.views.generic.edit import FormView class ContactView(FormView): template_name = 'contact.html' form_class = ContactUsForm - success_url = '/digitalglarus/contact/' + success_url = reverse_lazy('digitalglarus:contact') success_message = _('Message Successfully Sent') def form_valid(self, form): diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index c2461e99..1783ad12 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -52,6 +52,8 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', 'django.contrib.sites', 'easy_thumbnails', + 'utils', + 'ungleich_page', 'mptt', 'parler', 'taggit', @@ -125,6 +127,7 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'dynamicweb.urls' + TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', diff --git a/dynamicweb/urls.py b/dynamicweb/urls.py index fe2054ce..0b1bad0b 100644 --- a/dynamicweb/urls.py +++ b/dynamicweb/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ urlpatterns += i18n_patterns('', # url(r'^$',include('ungleich.urls')), url(r'^blog/',include('ungleich.urls',namespace='ungleich')), + url(r'^',include('ungleich_page.urls',namespace='ungleich_page')), url(r'^login/',include(membership_urls)), url(r'^admin/', include(admin.site.urls)), url(r'^digitalglarus/', include('digitalglarus.urls', diff --git a/ungleich/models.py b/ungleich/models.py index a3c531e7..fb76704b 100644 --- a/ungleich/models.py +++ b/ungleich/models.py @@ -7,6 +7,7 @@ from filer.fields.image import FilerImageField # Create your models here. + class UngleichPage(PageExtension): #image_header = models.ImageField(upload_to='image_header') image = FilerImageField(null=True, blank=True, diff --git a/ungleich/urls.py b/ungleich/urls.py index 8004657e..afdef4de 100644 --- a/ungleich/urls.py +++ b/ungleich/urls.py @@ -2,8 +2,8 @@ from django.conf.urls import url from . import views urlpatterns = [ - url(r'^$',views.PostListViewUngleich.as_view()), + url(r'^$', views.PostListViewUngleich.as_view()), # url(r'^$',views.PostListView.as_view()), - url(r'^(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$',views.details) - -] \ No newline at end of file + url(r'^(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$', + views.details) +] diff --git a/ungleich/views.py b/ungleich/views.py index 1970e54b..9c06d4fa 100644 --- a/ungleich/views.py +++ b/ungleich/views.py @@ -1,14 +1,11 @@ from django.shortcuts import render from django.utils.translation import get_language from djangocms_blog.models import Post -from django.views.generic import ListView -from djangocms_blog.views import PostListView,BaseBlogView -from django.core.paginator import Paginator -from django.core.paginator import PageNotAnInteger -from django.core.paginator import EmptyPage +from djangocms_blog.views import PostListView from djangocms_blog.settings import get_setting + def blog(request): posts = Post.objects.all() print(posts) diff --git a/ungleich_page/__init__.py b/ungleich_page/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ungleich_page/admin.py b/ungleich_page/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/ungleich_page/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/ungleich_page/apps.py b/ungleich_page/apps.py new file mode 100644 index 00000000..4385d1cd --- /dev/null +++ b/ungleich_page/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class UngleichPageConfig(AppConfig): + name = 'ungleich_page' diff --git a/ungleich_page/migrations/__init__.py b/ungleich_page/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ungleich_page/models.py b/ungleich_page/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/ungleich_page/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/ungleich_page/templates/ungleich_page/_footer.html b/ungleich_page/templates/ungleich_page/_footer.html new file mode 100644 index 00000000..f03fc2b7 --- /dev/null +++ b/ungleich_page/templates/ungleich_page/_footer.html @@ -0,0 +1,40 @@ +{% load cms_tags %} +
+ + diff --git a/ungleich_page/templates/ungleich_page/_header_base.html b/ungleich_page/templates/ungleich_page/_header_base.html new file mode 100644 index 00000000..4facf0f1 --- /dev/null +++ b/ungleich_page/templates/ungleich_page/_header_base.html @@ -0,0 +1,17 @@ +{% load cms_tags staticfiles %} + + +
+ +
+
+
+
+

{{ page_title }}

+
+ {{page_subtitle}} +
+
+
+
+
diff --git a/ungleich_page/templates/ungleich_page/_menu.html b/ungleich_page/templates/ungleich_page/_menu.html new file mode 100644 index 00000000..05acc787 --- /dev/null +++ b/ungleich_page/templates/ungleich_page/_menu.html @@ -0,0 +1,36 @@ +{% load menu_tags staticfiles cms_tags %} + + diff --git a/ungleich_page/templates/ungleich_page/base_ungleich.html b/ungleich_page/templates/ungleich_page/base_ungleich.html new file mode 100644 index 00000000..49ceefe9 --- /dev/null +++ b/ungleich_page/templates/ungleich_page/base_ungleich.html @@ -0,0 +1,78 @@ +{% load cms_tags menu_tags sekizai_tags staticfiles bootstrap3 %} + + + + + {% block title %} + {% page_attribute "page_title" %} + {% endblock %} + + {% addtoblock "external-css" %} + {% bootstrap_css %} + + + + + + + + + {% endaddtoblock %} + + {% addtoblock "css" %} + + {% endaddtoblock %} + {% block meta %} + + + {% include 'meta.html' %} + {% endblock %} + {% render_block "external-css" %} + {% render_block "css" postprocessor "compressor.contrib.sekizai.compress" %} + + + {% cms_toolbar %} + {% show_menu 0 0 0 1 "cms/ungleichch/_menu.html" %} + + + {% block base_header %} + {% include "ungleich_page/_header_base.html" %} + {% endblock %} +
+
+
+ {% block base_content %} + {% placeholder "default" %} + {% endblock %} +
+
+
+ + {% include "cms/ungleichch/_footer.html" %} + {% addtoblock "external-js" %} + {% bootstrap_javascript %} + {% endaddtoblock %} + {% addtoblock "js" %} + + +