# Create your views here.
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from models import Message, Report
# from forms import SendMessageForm
from django.http import HttpResponseRedirect
# from django.forms.models import inlineformset_factory
# from django.views import generic

# ALL VIEW FUNCTIONS MUST RETURN HttpResponse() as it is
# HttpRequest() we send to them (urls -> funct_from_here -> func does sth)


def home(request):
    pass


def search(request):
    error = False
    if 'q' in request.GET:
        q = request.GET['q']
        if not q:
            error = True
        else:
            messages = Message.objects.filter(destination__icontains=q)
            return render(request, 'search_result.html',
                          {'messages': messages, 'query': q})
    return render(request, 'search_form.html',
                  {'error': error})


# def message(request):
#     if request.method == 'POST':
#         form = SendMessageForm(request.POST)
#         if form.is_valid():
#             cd = form.cleaned_data
#             Message.objects.create(**cd)
#             return HttpResponseRedirect('/message/thanks/')
#     else:
#         form = SendMessageForm(
#             initial={'message_type': 'text'})
#     return render(request, 'send_message.html', {'form': form})


def create_report(request):
    msg_id = request.GET.get('msg_id')
    if msg_id:
        report_dict = {
            'message': get_object_or_404(Message, id=msg_id),
            'source': request.GET['source'],
            'dest': request.GET['dest'],
            'status': request.GET['status'],
            'code': request.GET['code'],
            'description': request.GET['description'],
            'timestamp': request.GET['timestamp']}

        Report.objects.create(**report_dict)
    return HttpResponse()

@@ -1,30 +1,4 @@
-# Create your views here.%0A
 from
@@ -80,1254 +80,44 @@
 _404
-, render%0Afrom models import Message, Report%0A# from forms import SendMessageForm%0Afrom django.http import HttpResponseRedirect%0A# from django.forms.models import inlineformset_factory%0A# from django.views import generic%0A%0A# ALL VIEW FUNCTIONS MUST RETURN HttpResponse() as it is%0A# HttpRequest() we send to them (urls -%3E funct_from_here -%3E func does sth)%0A%0A%0Adef home(request):%0A    pass%0A%0A%0Adef search(request):%0A    error = False%0A    if 'q' in request.GET:%0A        q = request.GET%5B'q'%5D%0A        if not q:%0A            error = True%0A        else:%0A            messages = Message.objects.filter(destination__icontains=q)%0A            return render(request, 'search_result.html',%0A                          %7B'messages': messages, 'query': q%7D)%0A    return render(request, 'search_form.html',%0A                  %7B'error': error%7D)%0A%0A%0A# def message(request):%0A#     if request.method == 'POST':%0A#         form = SendMessageForm(request.POST)%0A#         if form.is_valid():%0A#             cd = form.cleaned_data%0A#             Message.objects.create(**cd)%0A#             return Http
+%0A%0Afrom models import Message, 
 Re
-s
 po
-nseRedirect('/message/thanks/')%0A#     else:%0A#         form = SendMessageForm(%0A#             initial=%7B'message_type': 'text'%7D)%0A#     return render(request, 'send_message.html', %7B'form': form%7D)
+rt
 %0A%0A%0Ad

Remove obsolete views