From ca25436440a75c5cff6a364283e47bf78b9385bb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 2 May 2015 22:42:08 +0200 Subject: [PATCH] make the form work Signed-off-by: Nico Schottelius --- .../templates/digital_glarus/contact.html | 21 ++++++-------- digital_glarus/urls.py | 1 - digital_glarus/views.py | 28 ++++++++----------- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/digital_glarus/templates/digital_glarus/contact.html b/digital_glarus/templates/digital_glarus/contact.html index dc6626e5..25eda953 100755 --- a/digital_glarus/templates/digital_glarus/contact.html +++ b/digital_glarus/templates/digital_glarus/contact.html @@ -41,35 +41,30 @@

If you want further information on Digital Glarus, please send us a message using the form below.

-
+ + {% csrf_token %}
-{% if error_message %}

{{ error_message }}

{% endif %} - - {% csrf_token %} - {{ form }} - - - +
diff --git a/digital_glarus/urls.py b/digital_glarus/urls.py index b647659e..ca15fab5 100644 --- a/digital_glarus/urls.py +++ b/digital_glarus/urls.py @@ -6,6 +6,5 @@ urlpatterns = [ url(r'^$', views.index, name='index'), url(r'about$', views.about, name='about'), url(r'contact$', views.contact, name='contact'), - url(r'send_message', views.send_message, name='send_message'), url(r'^(?P[0-9]+)/$', views.detail, name='detail'), ] diff --git a/digital_glarus/views.py b/digital_glarus/views.py index e8428601..18e72e43 100644 --- a/digital_glarus/views.py +++ b/digital_glarus/views.py @@ -7,6 +7,12 @@ from django.core.urlresolvers import reverse from .models import Message +class MessageForm(ModelForm): + required_css_class = 'form-control' + class Meta: + model = Message + fields = ['name', 'email', 'phone_number', 'message' ] + def detail(request, message_id): p = get_object_or_404(Message, pk=message_id) @@ -15,34 +21,24 @@ def detail(request, message_id): return render(request, 'digital_glarus/detail.html', context) def about(request): - pass - -def contact(request): - return render(request, 'digital_glarus/contact.html') - -def send_message(request): - pass - -class MessageForm(ModelForm): - class Meta: - model = Message - fields = ['name', 'email', 'phone_number', 'message' ] + return render(request, 'digital_glarus/about.html') def index(request): + return render(request, 'digital_glarus/index.html') + +def contact(request): if request.method == 'POST': message = Message(received_date=datetime.datetime.now()) form = MessageForm(request.POST, instance=message) if form.is_valid(): form.save() - return HttpResponseRedirect(reverse("digital_glarus:index")) + return HttpResponseRedirect(reverse("digital_glarus:contact")) form = MessageForm() - message_list = Message.objects.order_by('-received_date')[:5] context = { - 'message_list': message_list, 'form': form, } - return render(request, 'digital_glarus/index.html', context) + return render(request, 'digital_glarus/contact.html', context)