feedback/views.py
author nishanth
Tue, 29 Jun 2010 16:12:29 +0530
changeset 103 ee9261c5ba18
parent 97 87d522d28a28
permissions -rwxr-xr-x
the list_attendees page looks better now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
     1
from django.shortcuts import render_to_response, redirect
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
     2
62
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 56
diff changeset
     3
from ws_app.reg.models import Event
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
     4
62
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 56
diff changeset
     5
from ws_app.feedback.models import Feedback, FeedLog
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 56
diff changeset
     6
from ws_app.feedback.forms import FeedbackForm
b7e47cc39342 renamed the project to ws_app and modified imports accordingly .
nishanth
parents: 56
diff changeset
     7
from ws_app.feedback.utils import make_day_report
5
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
     8
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
     9
from django.http import HttpResponse
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    10
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 5
diff changeset
    11
def submit_feedback(request, event_key):
5
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    12
    """ see if the ip address has already submitted a feedback.
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    13
    if not, collect the feedback.
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    14
    """
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    15
55
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    16
    user = request.user
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    17
    if not (user.is_authenticated() and user.is_active):
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    18
        raise Http404
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    19
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    20
    try:
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    21
        event = Event.objects.get(key=event_key)
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    22
    except Event.DoesNotExist:
35
79dc44b6edd4 made a few redirects to 404
nishanth
parents: 11
diff changeset
    23
        raise Http404
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    24
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    25
    if event.feedback_status == "0":
35
79dc44b6edd4 made a few redirects to 404
nishanth
parents: 11
diff changeset
    26
        raise Http404
55
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    27
    
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    28
    try:
55
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    29
        FeedLog.objects.get(user=user,day=event.feedback_status,event=event)
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    30
        return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event})
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    31
    except FeedLog.DoesNotExist:
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    32
        new_feedback = Feedback(event=event)
5
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    33
    
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    34
    if request.method == "POST":
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    35
        form = FeedbackForm(request.POST)
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    36
        if form.is_valid():
11
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    37
            data = form.cleaned_data
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    38
            new_feedback.topics = data['topics']  
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    39
            new_feedback.depth = data['depth']
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    40
            new_feedback.methodology = data['methodology']
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    41
            new_feedback.pace = data['pace']
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    42
            new_feedback.applicability = data['applicability']
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    43
            new_feedback.problems = data['problems']
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    44
            new_feedback.exercises = data['exercises']
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    45
            new_feedback.comments = data['comments']
334550460bd7 added the view event functionality and submitting feedback according to the status .
nishanth
parents: 10
diff changeset
    46
            new_feedback.save()
55
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    47
        
56
3858a9d0f376 removed the field feedback_submitted_by from event model and added the code to create feedlog record when a new feedback is taken.
nishanth
parents: 55
diff changeset
    48
            FeedLog(user=user, event=event, day=event.feedback_status).save()
55
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    49
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    50
            return render_to_response('feedback.html', {'user':user, 'submitted':True, 'event':event})
5
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    51
        else:
55
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    52
            return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event})
5
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    53
    else:
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    54
        form = FeedbackForm()
55
53ff84c9192d added a model in feedback for logging users who have already submitted feedback and made changes in corresponding views .
nishanth
parents: 44
diff changeset
    55
        return render_to_response('feedback.html',{'user':user, 'form':form, 'event':event})
5
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    56
10
c52d170969f0 quite a few changes. modified models and feedback views .
nishanth
parents: 5
diff changeset
    57
def list_feedbacks(request, event_key):
5
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    58
    """ print a list of all the feedbacks collected.
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    59
    """
37e4027fba48 submit and list feedback done
nishanth
parents: 0
diff changeset
    60
36
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    61
    user = request.user
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    62
    
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    63
    try:
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    64
        event = Event.objects.get(key__iexact=event_key)
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    65
    except Event.DoesNotExist:
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    66
        raise Http404
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    67
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    68
    if not user in event.organizers.all():
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    69
        raise Http404
cd0f61fa31f1 removed quiz links from view event template .
nishanth
parents: 35
diff changeset
    70
38
b63b78017225 added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents: 36
diff changeset
    71
    no_of_days = (event.stop_date - event.start_date).days
39
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    72
    days = range(1,no_of_days+2)
38
b63b78017225 added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents: 36
diff changeset
    73
39
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    74
    feeds_list = []
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    75
    for day in days:
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    76
        day_feeds = Feedback.objects.filter(event=event,day=day)
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    77
        if day_feeds.count():
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    78
            day_list = []
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    79
            for feed in day_feeds:
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    80
                day_list.append(" ".join((feed.topics, feed.depth, feed.methodology, feed.pace,
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    81
                                feed.applicability, feed.problems, feed.exercises, feed.comments)))
41
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    82
            feeds_list.extend(["Day %s"%day, day_list])
38
b63b78017225 added date tags in view event template and open_feedback template is now a lil better .
nishanth
parents: 36
diff changeset
    83
39
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    84
    return render_to_response('list_feedbacks.html',{'user':user, 'event':event, 'feeds_list':feeds_list})
61d558a69b0d implemented listing of feedbacks.
nishanth
parents: 38
diff changeset
    85
41
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    86
def view_report(request, event_key):
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    87
    """ compile the report and display it.
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    88
    """
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    89
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    90
    user = request.user
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    91
    
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    92
    try:
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    93
        event = Event.objects.get(key__iexact=event_key)
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    94
    except Event.DoesNotExist:
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    95
        raise Http404
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    96
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    97
    if not user in event.organizers.all():
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    98
        raise Http404
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
    99
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   100
    no_of_days = (event.stop_date - event.start_date).days
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   101
    days = range(1,no_of_days+2)
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   102
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   103
    workshop_report = []
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   104
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   105
    for day in days:
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   106
        day_num = str(day)
97
87d522d28a28 now comments are also displayed on view report page.
nishanth
parents: 96
diff changeset
   107
        day_feeds = event.feedback.filter(day=day_num)
44
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 41
diff changeset
   108
        day_report = make_day_report(day_feeds) 
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 41
diff changeset
   109
        if day_report:
97
87d522d28a28 now comments are also displayed on view report page.
nishanth
parents: 96
diff changeset
   110
            day_comments = [ feed.comments for feed in day_feeds if feed.comments ]
87d522d28a28 now comments are also displayed on view report page.
nishanth
parents: 96
diff changeset
   111
            day_report.extend(["General comments:",day_comments])
44
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 41
diff changeset
   112
            workshop_report.extend( [ "Day %s"%day_num, day_report] )
41
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   113
ab0a8a72b069 added view report functionality. have to make it look better.
nishanth
parents: 39
diff changeset
   114
    return render_to_response("show_report.html", {"user":user, "event":event, "workshop_report":workshop_report})