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 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 15:42:04 +00:00
|
|
|
def send_message(request):
|
|
|
|
pass
|
2015-05-02 15:15:20 +00:00
|
|
|
|
2015-05-02 18:41:11 +00:00
|
|
|
class MessageForm(ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Message
|
|
|
|
fields = ['name', 'email', 'phone_number', 'message' ]
|
|
|
|
|
2015-05-02 15:15:20 +00:00
|
|
|
def index(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()
|
|
|
|
return HttpResponseRedirect(reverse("digital_glarus:index"))
|
|
|
|
|
|
|
|
form = MessageForm()
|
2015-05-02 15:42:04 +00:00
|
|
|
message_list = Message.objects.order_by('-received_date')[:5]
|
2015-05-02 18:41:11 +00:00
|
|
|
|
|
|
|
context = {
|
|
|
|
'message_list': message_list,
|
|
|
|
'form': form,
|
|
|
|
}
|
|
|
|
|
2015-05-02 15:42:04 +00:00
|
|
|
return render(request, 'digital_glarus/index.html', context)
|