Exemplo n.º 1
0
def reviewer_profile_comment(request, class_num, sub, topics, id):
    context = RequestContext(request)
    comment = Comment.objects.filter(subject_id=id)
    reviewer = Reviewer.objects.get(user=request.user)

    if request.method == 'POST':
        print "we have a new comment"
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():
            comments = comment_form.save(commit=False)
            subject = Subject.objects.get(pk=id)
            comments.subject = subject
            comments.user = reviewer
            comments.save()
            url = reverse('webapp.views.reviewer_profile_comment',
                          kwargs={
                              'class_num': class_num,
                              'sub': sub,
                              'topics': topics,
                              'id': id
                          })
            return HttpResponseRedirect(url)
            # return HttpResponseRedirect(reverse('/reviewer/profile/comments/%s/%s/' % sub_id % rev_id))
        else:
            if comment_form.errors:
                print comment_form.errors
    else:
        comment_form = CommentForm()
    context_dict = {
        'comment_form': comment_form,
        'comment': comment,
        'reviewer': reviewer
    }
    return render_to_response("reviewer_comment.html", context_dict, context)
Exemplo n.º 2
0
def reviewer_profile_comment(request, class_num, sub, topics, id):
    """
    Arguments:

    `request`: Request from user.

    `class_num`: Class in which the contributor has contributed.

    `sub`: Subject in which the contributor has contributed.

    `topics`: Topic on which reviewer commented.

    `id`: Id of the reviewer.

    This function takes the request of user and directs it to the
    profile page which consists of the contributor's contributions in a
    specific subject of a specific class.
    
    """
    context = RequestContext(request)
    comment = Comment.objects.filter(subject_id=id).order_by('-submit_date')
    reviewer = Reviewer.objects.get(user=request.user)
    if request.method == 'POST':
        print "we have a new comment"
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():
            comments = comment_form.save(commit=False)
            subject = Subject.objects.get(pk=id)
            comments.subject = subject
            comments.user = reviewer
            comments.save()
            url = reverse('webapp.views.reviewer_profile_comment',
                          kwargs={
                              'class_num': class_num,
                              'sub': sub,
                              'topics': topics,
                              'id': id
                          })
            return HttpResponseRedirect(url)
        else:
            if comment_form.errors:
                print comment_form.errors
    else:
        comment_form = CommentForm()
        context_dict = {
            'comment_form': comment_form,
            'comment': comment,
            'reviewer': reviewer,
        }
        return render_to_response("reviewer_comment.html", context_dict,
                                  context)
Exemplo n.º 3
0
def reviewer_profile_comment(request, class_num, sub, topics, id):
    """
    Arguments:

    `request`: Request from user.

    `class_num`: Class in which the contributor has contributed.

    `sub`: Subject in which the contributor has contributed.

    `topics`: Topic on which reviewer commented.

    `id`: Id of the reviewer.

    This function takes the request of user and directs it to the
    profile page which consists of the contributor's contributions in a
    specific subject of a specific class.
    
    """
    context = RequestContext(request)
    comment = Comment.objects.filter(subject_id=id).order_by('-submit_date')
    reviewer = Reviewer.objects.get(user=request.user)
    if request.method == 'POST':
        print "we have a new comment"
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():
            comments = comment_form.save(commit=False)
            subject = Subject.objects.get(pk=id)
            comments.subject = subject
            comments.user = reviewer
            comments.save()
            url = reverse('webapp.views.reviewer_profile_comment', kwargs={
                'class_num': class_num, 'sub': sub, 'topics': topics, 'id': id}
            )
            return HttpResponseRedirect(url)
        else:
            if comment_form.errors:
                print comment_form.errors
    else:
        comment_form = CommentForm()
        context_dict = {
            'comment_form': comment_form,
            'comment': comment,
            'reviewer': reviewer,
        }
        return render_to_response("reviewer_comment.html",
                                  context_dict, context)
Exemplo n.º 4
0
def website_detail(request, website_slug):
    website = RatingWebsite.objects.get(slug=website_slug)
    ratings = Rating.objects.filter(website=website).order_by('-published')[:5]
    comments = Comment.objects.filter(website=website).order_by('-published')

    current_rating = 0

    if request.user.is_authenticated:
        # try to get the instance of user's rating for this website
        try:
            current_rating = Rating.objects.get(user=request.user,
                                                website=website).rating
        except Rating.DoesNotExist:
            pass

    if request.method == 'POST' and request.user.is_authenticated:
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.user = request.user
            comment.website = website

            comment.save()
            messages.success(request, 'Comment saved.')
            return redirect('website_detail', website_slug)

    elif request.user.is_authenticated:
        comment_form = CommentForm()
    else:
        comment_form = None

    context_dict = {
        'website': website,
        'ratings': ratings,
        'comments': comments,
        'current_rating': current_rating,
        'comment_form': comment_form
    }
    return render(request, 'webapp/website_details.html', context_dict)
Exemplo n.º 5
0
def reviewer_profile_comment(request,class_num,sub,topics,id):
	context = RequestContext(request)
	comment = Comment.objects.filter(subject_id = id)
	reviewer = Reviewer.objects.get(user = request.user)
	
	if request.method == 'POST':
		print  "we have a new comment"
		comment_form = CommentForm(data = request.POST)
		if comment_form.is_valid():
			comments = comment_form.save(commit=False)
			subject = Subject.objects.get(pk = id)
			comments.subject = subject
			comments.user = reviewer
			comments.save()
			url = reverse('webapp.views.reviewer_profile_comment', kwargs={'class_num' : class_num ,'sub':sub,'topics':topics,'id':id})
			return HttpResponseRedirect(url) 
			# return HttpResponseRedirect(reverse('/reviewer/profile/comments/%s/%s/' % sub_id % rev_id))
		else:
			if comment_form.errors:
				print comment_form.errors
	else:	
		comment_form = CommentForm()
        context_dict = {'comment_form': comment_form, 'comment' : comment,'reviewer':reviewer}
	return render_to_response("reviewer_comment.html",context_dict,context)
Exemplo n.º 6
0
def event(request, event_name):
    context_dict = {}
    try:
        l = visits[event]
    except:
        l = []
    try:
        event = Event.objects.get(slug=event_name)
    except:
        event = None

    if request.method == 'POST':
        profile = UserProfile.objects.get(user=request.user)
        try:
            fan = FanProfile.objects.get(profile=profile)
        except:
            pass
        if 'achievement' in request.POST:
            try:
                name = '+25xp for going to a gig %s' % event.name
                achievement = Achievement.objects.create(fan=fan, name=name)
                fan.xp += 25
                fan.save()
                visits[event] = l + [request.user]
            except:
                pass
        else:
            comment_form = None
            try:
                comment_form = CommentForm(data=request.POST)
            except:
                pass

            if comment_form:
                comment = comment_form.save(commit=False)
                comment.event = event
                comment.user = profile
                comment.save()
                try:
                    name = '+10xp for writing a comment about a gig %s' % event.name
                    achievement = Achievement.objects.create(fan=fan,
                                                             name=name)
                    fan.xp += 10
                    fan.save()
                except:
                    pass
    if event:
        event.views += 1
        event.save()
        try:
            comments = Comment.objects.filter(event=event).order_by('date')
            context_dict['comments'] = comments
        except:
            pass
        context_dict['event'] = event
    else:
        return HttpResponseRedirect('/create_event/')
    try:
        context_dict['visited'] = visits[event]
    except:
        pass
    return render(request, 'webapp/event.html', context_dict)