feedback/views.py
author nishanth
Tue, 20 Apr 2010 09:29:40 +0530
changeset 10 7535305b1104
parent 8 182e4a773ef2
child 11 afc41af983e5
permissions -rw-r--r--
created list feedbacks page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     1
from django.shortcuts import render_to_response
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     2
from django.http import Http404
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     3
8
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
     4
from offline.settings import ADMIN_KEY
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
     5
5
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     6
from offline.event.models import Event
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     7
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     8
from offline.feedback.models import Feedback
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
     9
from offline.feedback.forms import FeedbackForm
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    10
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    11
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    12
def submit_feedback(request):
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    13
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    14
    """ see if the ip address has already submitted a feedback.
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    15
    if not, collect the feedback.
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    16
    """
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    17
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    18
    try:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    19
        event = Event.objects.all()[0]
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    20
    except IndexError:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    21
        raise Http404
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    22
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    23
    if event.feedback_status == "0":
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    24
        raise Http404
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    25
    else:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    26
        day = event.feedback_status
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    27
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    28
    ip = request.META['REMOTE_ADDR']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    29
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    30
    try:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    31
        Feedback.objects.get(event=event,day=day,user_ip=ip)
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    32
        return render_to_response('submit_feedback.html', {'submitted':True, 'event':event})
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    33
    except Feedback.DoesNotExist:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    34
        new_feedback = Feedback(event=event,day=day,user_ip=ip)
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    35
       
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    36
    if request.method == "POST":
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    37
        form = FeedbackForm(request.POST)
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    38
        if form.is_valid():
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    39
            data = form.cleaned_data
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    40
            new_feedback.topics = data['topics']  
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    41
            new_feedback.depth = data['depth']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    42
            new_feedback.methodology = data['methodology']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    43
            new_feedback.pace = data['pace']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    44
            new_feedback.applicability = data['applicability']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    45
            new_feedback.problems = data['problems']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    46
            new_feedback.exercises = data['exercises']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    47
            new_feedback.comments = data['comments']
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    48
            new_feedback.save()
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    49
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    50
            return render_to_response('submit_feedback.html', {'submitted':True, 'event':event})
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    51
        else:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    52
            return render_to_response('submit_feedback.html',{ 'form':form, 'event':event})
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    53
    else:
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    54
        form = FeedbackForm()
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    55
        return render_to_response('submit_feedback.html',{'form':form, 'event':event})
9a671f3eb24c created the add feedback functionality
nishanth
parents: 1
diff changeset
    56
8
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    57
def open_feedback(request, admin_key):
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    58
    """
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    59
    Check for key and then exiatance of event.
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    60
    """
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    61
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    62
    if not admin_key == ADMIN_KEY:
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    63
        raise Http404
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    64
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    65
    try:
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    66
        event = Event.objects.all()[0]
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    67
    except IndexError:
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    68
        raise Http404
7
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 5
diff changeset
    69
8
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    70
    if event.feedback_status == '0':
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    71
        no_of_days = (event.stop_date - event.start_date).days + 1
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    72
        if request.method == "POST":
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    73
            day = request.POST['day']
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    74
            event.feedback_status = day
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    75
            event.save()
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    76
            return render_to_response('open_feedback.html', {'success': True, 'day':day, 'event':event})
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    77
        else:
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    78
            return render_to_response('open_feedback.html', {'event': event, 'days': range(1,no_of_days+1)})
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    79
    else:
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    80
        day = event.feedback_status
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    81
        return render_to_response('open_feedback.html', {'success': True, 'day':day, 'event':event})
7
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 5
diff changeset
    82
8
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    83
def close_feedback(request, admin_key):
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    84
    """
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    85
    simply set feedback status to 0
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    86
    """
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    87
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    88
    if not admin_key == ADMIN_KEY:
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    89
        raise Http404
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    90
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    91
    try:
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    92
        event = Event.objects.all()[0]
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    93
    except IndexError:
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    94
        raise Http404
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    95
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    96
    day = event.feedback_status
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    97
    event.feedback_status = '0'
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    98
    event.save()
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
    99
    return render_to_response('close_feedback.html', {'event': event, 'day':day})
182e4a773ef2 added close and open feedback functionalities.
nishanth
parents: 7
diff changeset
   100
10
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   101
def list_feedbacks(request, admin_key):
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   102
    """ print a list of all the feedbacks collected.
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   103
    """
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   104
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   105
    if not admin_key == ADMIN_KEY:
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   106
        raise Http404
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   107
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   108
    try:
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   109
        event = Event.objects.all()[0]
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   110
    except IndexError:
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   111
        raise Http404
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   112
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   113
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   114
    no_of_days = (event.stop_date - event.start_date).days
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   115
    days = range(1,no_of_days+2)
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   116
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   117
    feeds_list = []
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   118
    for day in days:
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   119
        day_feeds = Feedback.objects.filter(event=event,day=day)
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   120
        if day_feeds.count():
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   121
            day_list = []
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   122
            for feed in day_feeds:
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   123
                day_list.append(" ".join((feed.topics, feed.depth, feed.methodology, feed.pace,
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   124
                                feed.applicability, feed.problems, feed.exercises, feed.comments)))
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   125
            feeds_list.extend(["Day %s"%day, day_list])
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   126
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   127
    return render_to_response('list_feedbacks.html',{'event':event, 'feeds_list':feeds_list})
7535305b1104 created list feedbacks page
nishanth
parents: 8
diff changeset
   128