make the form work

Signed-off-by: Nico Schottelius <nico@freiheit.schottelius.org>
This commit is contained in:
Nico Schottelius 2015-05-02 22:42:08 +02:00
parent 4f832fac5a
commit 1bd69c8b83
3 changed files with 20 additions and 30 deletions

View file

@ -41,35 +41,30 @@
</h2> </h2>
<hr> <hr>
<p>If you want further information on Digital Glarus, please send us a message using the form below.</p> <p>If you want further information on Digital Glarus, please send us a message using the form below.</p>
<form action="{% url 'digital_glarus:index' %}" method="post" role="form"> <form action="{% url 'digital_glarus:contact' %}" method="post" role="form">
<div class="row">
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
{% csrf_token %} {% csrf_token %}
{{ form }} <div class="row">
<input type="submit" value="Send Message" /> <div class="form-group col-lg-4">
<!-- <div class="form-group col-lg-4">
<label>Name</label> <label>Name</label>
<input type="text" class="form-control"> <input type="text" class="form-control" name="name">
</div> </div>
<div class="form-group col-lg-4"> <div class="form-group col-lg-4">
<label>Email Address</label> <label>Email Address</label>
<input type="email" class="form-control"> <input type="email" class="form-control" name="email">
</div> </div>
<div class="form-group col-lg-4"> <div class="form-group col-lg-4">
<label>Phone Number</label> <label>Phone Number</label>
<input type="tel" class="form-control"> <input type="tel" class="form-control" name="phone_number">
</div> </div>
<div class="clearfix"></div> <div class="clearfix"></div>
<div class="form-group col-lg-12"> <div class="form-group col-lg-12">
<label>Message</label> <label>Message</label>
<textarea class="form-control" rows="6"></textarea> <textarea class="form-control" rows="6" name="message"></textarea>
</div> </div>
<div class="form-group col-lg-12"> <div class="form-group col-lg-12">
<input type="hidden" name="save" value="contact"> <input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-default">Submit</button> <button type="submit" class="btn btn-default">Submit</button>
</div> --> </div>
</div> </div>
</form> </form>
</div> </div>

View file

@ -6,6 +6,5 @@ urlpatterns = [
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
url(r'about$', views.about, name='about'), url(r'about$', views.about, name='about'),
url(r'contact$', views.contact, name='contact'), url(r'contact$', views.contact, name='contact'),
url(r'send_message', views.send_message, name='send_message'),
url(r'^(?P<message_id>[0-9]+)/$', views.detail, name='detail'), url(r'^(?P<message_id>[0-9]+)/$', views.detail, name='detail'),
] ]

View file

@ -7,6 +7,12 @@ from django.core.urlresolvers import reverse
from .models import Message 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): def detail(request, message_id):
p = get_object_or_404(Message, pk=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) return render(request, 'digital_glarus/detail.html', context)
def about(request): def about(request):
pass return render(request, 'digital_glarus/about.html')
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' ]
def index(request): def index(request):
return render(request, 'digital_glarus/index.html')
def contact(request):
if request.method == 'POST': if request.method == 'POST':
message = Message(received_date=datetime.datetime.now()) message = Message(received_date=datetime.datetime.now())
form = MessageForm(request.POST, instance=message) form = MessageForm(request.POST, instance=message)
if form.is_valid(): if form.is_valid():
form.save() form.save()
return HttpResponseRedirect(reverse("digital_glarus:index")) return HttpResponseRedirect(reverse("digital_glarus:contact"))
form = MessageForm() form = MessageForm()
message_list = Message.objects.order_by('-received_date')[:5]
context = { context = {
'message_list': message_list,
'form': form, 'form': form,
} }
return render(request, 'digital_glarus/index.html', context) return render(request, 'digital_glarus/contact.html', context)