Merge pull request #26 from levivm/develop
Moved contact form model in order to be reusable by ungleich app, Cre…
This commit is contained in:
commit
534d086836
37 changed files with 425 additions and 31 deletions
|
@ -1,5 +1,6 @@
|
||||||
from django.contrib import admin
|
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):
|
class DGPictureInline(admin.StackedInline):
|
||||||
model = DGPicture
|
model = DGPicture
|
||||||
|
@ -8,5 +9,5 @@ class DGGalleryAdmin(admin.ModelAdmin):
|
||||||
inlines = [DGPictureInline]
|
inlines = [DGPictureInline]
|
||||||
|
|
||||||
admin.site.register(DGGallery, DGGalleryAdmin)
|
admin.site.register(DGGallery, DGGalleryAdmin)
|
||||||
admin.site.register(Message)
|
admin.site.register(ContactMessage)
|
||||||
admin.site.register(Supporter)
|
admin.site.register(Supporter)
|
18
digitalglarus/migrations/0006_delete_message.py
Normal file
18
digitalglarus/migrations/0006_delete_message.py
Normal file
|
@ -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',
|
||||||
|
),
|
||||||
|
]
|
|
@ -3,21 +3,10 @@ from cms.models import CMSPlugin
|
||||||
from filer.fields.image import FilerImageField
|
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):
|
class Supporter(models.Model):
|
||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
description = models.TextField(null=True, blank=True)
|
description = models.TextField(null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s" % (self.name)
|
return "%s" % (self.name)
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</h2>
|
</h2>
|
||||||
<hr>
|
<hr>
|
||||||
<p>{% static_placeholder "digital_glarus_contact_form_text" %}</p>
|
<p>{% static_placeholder "digital_glarus_contact_form_text" %}</p>
|
||||||
<form action="" method="post" >
|
<form action="{% url 'digitalglarus:contact' %}" method="post" >
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div autofocus class="form-group col-lg-4 {% if form.name.errors %}has-error text-danger{% endif %}">
|
<div autofocus class="form-group col-lg-4 {% if form.name.errors %}has-error text-danger{% endif %}">
|
||||||
|
|
23
digitalglarus/test_views.py
Normal file
23
digitalglarus/test_views.py
Normal file
|
@ -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)
|
|
@ -3,23 +3,22 @@ import datetime
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
from django.http import HttpResponseRedirect
|
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 django.utils.translation import get_language
|
||||||
from djangocms_blog.models import Post
|
from djangocms_blog.models import Post
|
||||||
from django.core.urlresolvers import resolve
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
|
||||||
from .models import Message, Supporter
|
from .models import Supporter
|
||||||
from .forms import ContactUsForm
|
from utils.forms import ContactUsForm
|
||||||
from django.views.generic.edit import FormView
|
from django.views.generic.edit import FormView
|
||||||
|
|
||||||
|
|
||||||
class ContactView(FormView):
|
class ContactView(FormView):
|
||||||
template_name = 'contact.html'
|
template_name = 'contact.html'
|
||||||
form_class = ContactUsForm
|
form_class = ContactUsForm
|
||||||
success_url = '/digitalglarus/contact/'
|
success_url = reverse_lazy('digitalglarus:contact')
|
||||||
success_message = _('Message Successfully Sent')
|
success_message = _('Message Successfully Sent')
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
|
|
@ -52,6 +52,8 @@ INSTALLED_APPS = (
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'django.contrib.sites',
|
'django.contrib.sites',
|
||||||
'easy_thumbnails',
|
'easy_thumbnails',
|
||||||
|
'utils',
|
||||||
|
'ungleich_page',
|
||||||
'mptt',
|
'mptt',
|
||||||
'parler',
|
'parler',
|
||||||
'taggit',
|
'taggit',
|
||||||
|
@ -125,6 +127,7 @@ MIDDLEWARE_CLASSES = (
|
||||||
|
|
||||||
ROOT_URLCONF = 'dynamicweb.urls'
|
ROOT_URLCONF = 'dynamicweb.urls'
|
||||||
|
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
|
|
@ -20,6 +20,7 @@ urlpatterns = [
|
||||||
urlpatterns += i18n_patterns('',
|
urlpatterns += i18n_patterns('',
|
||||||
# url(r'^$',include('ungleich.urls')),
|
# url(r'^$',include('ungleich.urls')),
|
||||||
url(r'^blog/',include('ungleich.urls',namespace='ungleich')),
|
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'^login/',include(membership_urls)),
|
||||||
url(r'^admin/', include(admin.site.urls)),
|
url(r'^admin/', include(admin.site.urls)),
|
||||||
url(r'^digitalglarus/', include('digitalglarus.urls',
|
url(r'^digitalglarus/', include('digitalglarus.urls',
|
||||||
|
|
|
@ -7,6 +7,7 @@ from filer.fields.image import FilerImageField
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
class UngleichPage(PageExtension):
|
class UngleichPage(PageExtension):
|
||||||
#image_header = models.ImageField(upload_to='image_header')
|
#image_header = models.ImageField(upload_to='image_header')
|
||||||
image = FilerImageField(null=True, blank=True,
|
image = FilerImageField(null=True, blank=True,
|
||||||
|
|
|
@ -2,8 +2,8 @@ from django.conf.urls import url
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$',views.PostListViewUngleich.as_view()),
|
url(r'^$', views.PostListViewUngleich.as_view()),
|
||||||
# url(r'^$',views.PostListView.as_view()),
|
# url(r'^$',views.PostListView.as_view()),
|
||||||
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>\w[-\w]*)/$',views.details)
|
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<slug>\w[-\w]*)/$',
|
||||||
|
views.details)
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.utils.translation import get_language
|
from django.utils.translation import get_language
|
||||||
from djangocms_blog.models import Post
|
from djangocms_blog.models import Post
|
||||||
from django.views.generic import ListView
|
from djangocms_blog.views import PostListView
|
||||||
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.settings import get_setting
|
from djangocms_blog.settings import get_setting
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def blog(request):
|
def blog(request):
|
||||||
posts = Post.objects.all()
|
posts = Post.objects.all()
|
||||||
print(posts)
|
print(posts)
|
||||||
|
|
0
ungleich_page/__init__.py
Normal file
0
ungleich_page/__init__.py
Normal file
3
ungleich_page/admin.py
Normal file
3
ungleich_page/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
ungleich_page/apps.py
Normal file
5
ungleich_page/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class UngleichPageConfig(AppConfig):
|
||||||
|
name = 'ungleich_page'
|
0
ungleich_page/migrations/__init__.py
Normal file
0
ungleich_page/migrations/__init__.py
Normal file
3
ungleich_page/models.py
Normal file
3
ungleich_page/models.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
40
ungleich_page/templates/ungleich_page/_footer.html
Normal file
40
ungleich_page/templates/ungleich_page/_footer.html
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
{% load cms_tags %}
|
||||||
|
<hr />
|
||||||
|
<!-- Footer -->
|
||||||
|
<footer>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||||
|
<ul class="list-inline text-center">
|
||||||
|
<li>
|
||||||
|
<a href="https://twitter.com/ungleich">
|
||||||
|
<span class="fa-stack fa-lg">
|
||||||
|
<i class="fa fa-circle fa-stack-2x"></i>
|
||||||
|
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://www.linkedin.com/company/ungleich-gmbh">
|
||||||
|
<span class="fa-stack fa-lg">
|
||||||
|
<i class="fa fa-circle fa-stack-2x"></i>
|
||||||
|
<i class="fa fa-linkedin fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://github.com/ungleich">
|
||||||
|
<span class="fa-stack fa-lg">
|
||||||
|
<i class="fa fa-circle fa-stack-2x"></i>
|
||||||
|
<i class="fa fa-github fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p class="copyright text-muted text-centered">
|
||||||
|
{% static_placeholder "footer_copyright" %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
17
ungleich_page/templates/ungleich_page/_header_base.html
Normal file
17
ungleich_page/templates/ungleich_page/_header_base.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{% load cms_tags staticfiles %}
|
||||||
|
<!-- Page Header -->
|
||||||
|
<!-- Set your background image for this header on the line below. -->
|
||||||
|
<header class="intro-header" style="background-image: url('{% static 'blog.ungleich.ch/img/home-bg.jpg' %}');">
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||||
|
<div class="site-heading">
|
||||||
|
<h1> {{ page_title }} </h1>
|
||||||
|
<hr class="small">
|
||||||
|
<span class="subheading"> {{page_subtitle}} </span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
36
ungleich_page/templates/ungleich_page/_menu.html
Normal file
36
ungleich_page/templates/ungleich_page/_menu.html
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
{% load menu_tags staticfiles cms_tags %}
|
||||||
|
<!-- Navigation -->
|
||||||
|
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<!-- Brand and toggle get grouped for better mobile display -->
|
||||||
|
<div class="navbar-header page-scroll">
|
||||||
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
|
||||||
|
<span class="sr-only">Toggle navigation</span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
</button>
|
||||||
|
<a class="navbar-brand" href="/">
|
||||||
|
<img src="{% static "blog.ungleich.ch/img/logo_white.svg" %}" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Collect the nav links, forms, and other content for toggling -->
|
||||||
|
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
|
||||||
|
<ul class="nav navbar-nav navbar-right">
|
||||||
|
{% for child in children %}
|
||||||
|
<li class="child{% if child.selected %} selected{% endif %}{% if child.ancestor %} ancestor{% endif %}{% if child.sibling %} sibling{% endif %}{% if child.descendant %} descendant{% endif %}">
|
||||||
|
<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
|
||||||
|
{% if child.children %}
|
||||||
|
<ul>
|
||||||
|
{% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<!-- /.navbar-collapse -->
|
||||||
|
</div>
|
||||||
|
<!-- /.container -->
|
||||||
|
</nav>
|
78
ungleich_page/templates/ungleich_page/base_ungleich.html
Normal file
78
ungleich_page/templates/ungleich_page/base_ungleich.html
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
{% load cms_tags menu_tags sekizai_tags staticfiles bootstrap3 %}
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>
|
||||||
|
{% block title %}
|
||||||
|
{% page_attribute "page_title" %}
|
||||||
|
{% endblock %}
|
||||||
|
</title>
|
||||||
|
{% addtoblock "external-css" %}
|
||||||
|
{% bootstrap_css %}
|
||||||
|
|
||||||
|
<link href='//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css' rel="stylesheet" type="text/css">
|
||||||
|
<link href='//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
|
||||||
|
<link href='//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800'
|
||||||
|
rel='stylesheet' type='text/css'>
|
||||||
|
|
||||||
|
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||||
|
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||||
|
<!--[if lt IE 9]>
|
||||||
|
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||||
|
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||||
|
<![endif]-->
|
||||||
|
{% endaddtoblock %}
|
||||||
|
|
||||||
|
{% addtoblock "css" %}
|
||||||
|
<link href="{% static 'blog.ungleich.ch/css/clean-blog.css' %}" type="text/css"
|
||||||
|
rel="stylesheet" medial="all" />
|
||||||
|
{% endaddtoblock %}
|
||||||
|
{% block meta %}
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="description" content="{% page_attribute 'meta_description' %}">
|
||||||
|
{% include 'meta.html' %}
|
||||||
|
{% endblock %}
|
||||||
|
{% render_block "external-css" %}
|
||||||
|
{% render_block "css" postprocessor "compressor.contrib.sekizai.compress" %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% cms_toolbar %}
|
||||||
|
{% show_menu 0 0 0 1 "cms/ungleichch/_menu.html" %}
|
||||||
|
<!-- body -->
|
||||||
|
<!-- Main Content -->
|
||||||
|
{% block base_header %}
|
||||||
|
{% include "ungleich_page/_header_base.html" %}
|
||||||
|
{% endblock %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
|
||||||
|
{% block base_content %}
|
||||||
|
{% placeholder "default" %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- end body -->
|
||||||
|
{% include "cms/ungleichch/_footer.html" %}
|
||||||
|
{% addtoblock "external-js" %}
|
||||||
|
{% bootstrap_javascript %}
|
||||||
|
{% endaddtoblock %}
|
||||||
|
{% addtoblock "js" %}
|
||||||
|
<script>
|
||||||
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||||
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||||
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||||
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||||
|
|
||||||
|
ga('create', 'UA-62285904-4', 'auto');
|
||||||
|
ga('send', 'pageview');
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script src="{% static 'blog.ungleich.ch/vendor/js/jquery.min.js' %}" type="text/javascript" />
|
||||||
|
<script src="{% static 'blog.ungleich.ch/js/navbar-scroll-up.js' %}" type="text/javascript" />
|
||||||
|
{% endaddtoblock %}
|
||||||
|
{% render_block "js" postprocessor "compressor.contrib.sekizai.compress" %}
|
||||||
|
{% render_block "external-js" %}
|
||||||
|
</body>
|
||||||
|
</html>
|
38
ungleich_page/templates/ungleich_page/contact.html
Normal file
38
ungleich_page/templates/ungleich_page/contact.html
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
{% extends "ungleich_page/base_ungleich.html" %}
|
||||||
|
|
||||||
|
{% block base_content %}
|
||||||
|
<form action="{% url 'ungleich_page:contact' %}" method="post" >
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="row">
|
||||||
|
<div autofocus class="form-group col-lg-4 {% if form.name.errors %}has-error text-danger{% endif %}">
|
||||||
|
{{ form.name.label_tag }}
|
||||||
|
{{ form.name }}
|
||||||
|
{{ form.name.errors|striptags}}
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-4 {% if form.email.errors %}has-error text-danger {% endif %}">
|
||||||
|
{{ form.email.label_tag }}
|
||||||
|
{{ form.email }}
|
||||||
|
{{ form.email.errors|striptags}}
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-lg-4 {% if form.phone_number.errors %}has-error text-danger {% endif %}">
|
||||||
|
{{ form.phone_number.label_tag }}
|
||||||
|
{{ form.phone_number }}
|
||||||
|
{{ form.phone_number.errors|striptags}}
|
||||||
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
<div class="form-group col-lg-12 {% if form.message.errors %}has-error text-danger {% endif %}">
|
||||||
|
{{ form.message.label_tag }}
|
||||||
|
{{ form.message }}
|
||||||
|
{{ form.message.errors|striptags}}
|
||||||
|
</div>
|
||||||
|
{{ form.non_field_errors }}
|
||||||
|
<div class="form-group col-lg-12">
|
||||||
|
<input type="hidden" name="save" value="contact">
|
||||||
|
<button type="submit" class="btn btn-default" {% if form.name.errors %} autofocus {% endif %}>Submit</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
{% endblock %}
|
3
ungleich_page/templates/ungleich_page/index.html
Normal file
3
ungleich_page/templates/ungleich_page/index.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{% extends "base_glarus.html" %}
|
||||||
|
{% block base_content %}
|
||||||
|
{% endblock %}
|
5
ungleich_page/templates/ungleich_page/page.html
Normal file
5
ungleich_page/templates/ungleich_page/page.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{% extends "base_ungleich.html" %}
|
||||||
|
{% load cms_tags %}
|
||||||
|
{% block base_content %}
|
||||||
|
{% placeholder "page_content" %}
|
||||||
|
{% endblock %}
|
23
ungleich_page/test_views.py
Normal file
23
ungleich_page/test_views.py
Normal file
|
@ -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('ungleich_page: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)
|
6
ungleich_page/urls.py
Normal file
6
ungleich_page/urls.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.conf.urls import url
|
||||||
|
from .views import ContactView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r'contact/?$', ContactView.as_view(), name='contact'),
|
||||||
|
]
|
25
ungleich_page/views.py
Normal file
25
ungleich_page/views.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from django.contrib import messages
|
||||||
|
|
||||||
|
from django.views.generic.edit import FormView
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
from django.core.urlresolvers import reverse_lazy
|
||||||
|
from utils.forms import ContactUsForm
|
||||||
|
|
||||||
|
|
||||||
|
class ContactView(FormView):
|
||||||
|
template_name = 'ungleich_page/contact.html'
|
||||||
|
form_class = ContactUsForm
|
||||||
|
success_url = reverse_lazy('digitalglarus:contact')
|
||||||
|
success_message = _('Message Successfully Sent')
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.save()
|
||||||
|
form.send_email()
|
||||||
|
messages.add_message(self.request, messages.SUCCESS, self.success_message)
|
||||||
|
return super(ContactView, self).form_valid(form)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(ContactView, self).get_context_data(**kwargs)
|
||||||
|
context['page_title'] = _('Contact Us')
|
||||||
|
context['page_subtitle'] = _('If you have any question, just send us an email.')
|
||||||
|
return context
|
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
3
utils/admin.py
Normal file
3
utils/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
utils/apps.py
Normal file
5
utils/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class UtilsConfig(AppConfig):
|
||||||
|
name = 'utils'
|
|
@ -1,5 +1,5 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from .models import Message
|
from .models import ContactMessage
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.core.mail import EmailMultiAlternatives
|
from django.core.mail import EmailMultiAlternatives
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
@ -9,7 +9,7 @@ class ContactUsForm(forms.ModelForm):
|
||||||
error_css_class = 'autofocus'
|
error_css_class = 'autofocus'
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Message
|
model = ContactMessage
|
||||||
fields = ['name', 'email', 'phone_number', 'message']
|
fields = ['name', 'email', 'phone_number', 'message']
|
||||||
widgets = {
|
widgets = {
|
||||||
'name': forms.TextInput(attrs={'class': u'form-control'}),
|
'name': forms.TextInput(attrs={'class': u'form-control'}),
|
27
utils/migrations/0001_initial.py
Normal file
27
utils/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9.4 on 2016-04-10 17:04
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ContactMessage',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=200)),
|
||||||
|
('email', models.EmailField(max_length=254)),
|
||||||
|
('phone_number', models.CharField(max_length=200)),
|
||||||
|
('message', models.TextField()),
|
||||||
|
('received_date', models.DateTimeField(auto_now_add=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
0
utils/migrations/__init__.py
Normal file
0
utils/migrations/__init__.py
Normal file
14
utils/models.py
Normal file
14
utils/models.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class ContactMessage(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)
|
25
utils/test_forms.py
Normal file
25
utils/test_forms.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
from .forms import ContactUsForm
|
||||||
|
|
||||||
|
|
||||||
|
class ContactUsFormTest(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.completed_data = {
|
||||||
|
'name': 'test',
|
||||||
|
'email': 'test@gmail.com',
|
||||||
|
'phone_number': '32123123123123',
|
||||||
|
'message': 'This is a message',
|
||||||
|
}
|
||||||
|
|
||||||
|
self.incompleted_data = {
|
||||||
|
'name': 'test',
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_valid_form(self):
|
||||||
|
form = ContactUsForm(data=self.completed_data)
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
|
||||||
|
def test_invalid_form(self):
|
||||||
|
form = ContactUsForm(data=self.incompleted_data)
|
||||||
|
self.assertFalse(form.is_valid())
|
3
utils/tests.py
Normal file
3
utils/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
utils/views.py
Normal file
3
utils/views.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
Loading…
Reference in a new issue