2015-05-02 18:41:11 +00:00
|
|
|
import datetime
|
2015-05-02 15:00:15 +00:00
|
|
|
|
2015-05-02 17:00:38 +00:00
|
|
|
from django.shortcuts import get_object_or_404, render
|
2015-05-02 18:41:11 +00:00
|
|
|
from django.forms import ModelForm
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.core.urlresolvers import reverse
|
2015-05-02 15:42:04 +00:00
|
|
|
|
|
|
|
from .models import Message
|
|
|
|
|
2015-05-02 20:42:08 +00:00
|
|
|
class MessageForm(ModelForm):
|
|
|
|
required_css_class = 'form-control'
|
|
|
|
class Meta:
|
|
|
|
model = Message
|
|
|
|
fields = ['name', 'email', 'phone_number', 'message' ]
|
|
|
|
|
2015-05-02 15:42:04 +00:00
|
|
|
|
2015-05-02 17:00:38 +00:00
|
|
|
def detail(request, message_id):
|
|
|
|
p = get_object_or_404(Message, pk=message_id)
|
|
|
|
|
|
|
|
context = { 'message': p, }
|
|
|
|
return render(request, 'digital_glarus/detail.html', context)
|
|
|
|
|
2015-05-02 20:02:19 +00:00
|
|
|
def about(request):
|
2015-05-02 20:42:08 +00:00
|
|
|
return render(request, 'digital_glarus/about.html')
|
2015-05-02 18:41:11 +00:00
|
|
|
|
2015-05-02 15:15:20 +00:00
|
|
|
def index(request):
|
2015-05-02 20:42:08 +00:00
|
|
|
return render(request, 'digital_glarus/index.html')
|
|
|
|
|
|
|
|
def contact(request):
|
2015-05-02 18:41:11 +00:00
|
|
|
if request.method == 'POST':
|
|
|
|
message = Message(received_date=datetime.datetime.now())
|
|
|
|
form = MessageForm(request.POST, instance=message)
|
|
|
|
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
2015-05-02 20:42:08 +00:00
|
|
|
return HttpResponseRedirect(reverse("digital_glarus:contact"))
|
2015-05-02 18:41:11 +00:00
|
|
|
|
|
|
|
form = MessageForm()
|
|
|
|
|
|
|
|
context = {
|
|
|
|
'form': form,
|
|
|
|
}
|
|
|
|
|
2015-05-02 20:42:08 +00:00
|
|
|
return render(request, 'digital_glarus/contact.html', context)
|