make the form work
Signed-off-by: Nico Schottelius <nico@freiheit.schottelius.org>
This commit is contained in:
parent
5fe7987b8a
commit
ca25436440
3 changed files with 20 additions and 30 deletions
|
@ -41,35 +41,30 @@
|
|||
</h2>
|
||||
<hr>
|
||||
<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">
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
|
||||
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit" value="Send Message" />
|
||||
|
||||
<!-- <div class="form-group col-lg-4">
|
||||
<div class="form-group col-lg-4">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control">
|
||||
<input type="text" class="form-control" name="name">
|
||||
</div>
|
||||
<div class="form-group col-lg-4">
|
||||
<label>Email Address</label>
|
||||
<input type="email" class="form-control">
|
||||
<input type="email" class="form-control" name="email">
|
||||
</div>
|
||||
<div class="form-group col-lg-4">
|
||||
<label>Phone Number</label>
|
||||
<input type="tel" class="form-control">
|
||||
<input type="tel" class="form-control" name="phone_number">
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="form-group col-lg-12">
|
||||
<label>Message</label>
|
||||
<textarea class="form-control" rows="6"></textarea>
|
||||
<textarea class="form-control" rows="6" name="message"></textarea>
|
||||
</div>
|
||||
<div class="form-group col-lg-12">
|
||||
<input type="hidden" name="save" value="contact">
|
||||
<button type="submit" class="btn btn-default">Submit</button>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -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<message_id>[0-9]+)/$', views.detail, name='detail'),
|
||||
]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue