Changeset - cc032da2887a
[Not reviewed]
0 3 0
Luke Hatcher - 12 years ago 2012-10-03 22:41:35
lukeman@gmail.com
include user rating in reviews
3 files changed with 9 insertions and 4 deletions:
0 comments (0 inline, 0 general)
symposion/reviews/views.py
Show inline comments
 
import re
 

	
 
from django.core.mail import send_mass_mail
 
from django.db.models import Q
 
from django.http import HttpResponseBadRequest, HttpResponseNotAllowed
 
from django.shortcuts import render, redirect, get_object_or_404
 
from django.template import Context, Template
 
from django.views.decorators.http import require_POST
 

	
 
from django.contrib.auth.decorators import login_required
 

	
 
from symposion.conf import settings
 
from symposion.proposals.models import ProposalBase, ProposalSection
 
from symposion.teams.models import Team
 
from symposion.utils.mail import send_email
 

	
 
from symposion.reviews.forms import ReviewForm, SpeakerCommentForm
 
from symposion.reviews.forms import BulkPresentationForm
 
from symposion.reviews.models import (
 
    ReviewAssignment, Review, LatestVote, ProposalResult, NotificationTemplate,
 
    ResultNotification
 
)
 

	
 

	
 
def access_not_permitted(request):
 
    return render(request, "reviews/access_not_permitted.html")
 

	
 

	
 
def proposals_generator(request, queryset, user_pk=None, check_speaker=True):
 
    
 
    for obj in queryset:
 
        # @@@ this sucks; we can do better
 
        if check_speaker:
 
            if request.user in [s.user for s in obj.speakers()]:
 
                continue
 
        
 
        try:
 
            obj.result
 
        except ProposalResult.DoesNotExist:
 
            ProposalResult.objects.get_or_create(proposal=obj)
 
        
 
        obj.comment_count = obj.result.comment_count
 
        obj.total_votes = obj.result.vote_count
 
        obj.plus_one = obj.result.plus_one
 
        obj.plus_zero = obj.result.plus_zero
 
        obj.minus_zero = obj.result.minus_zero
 
        obj.minus_one = obj.result.minus_one
 
        lookup_params = dict(proposal=obj)
 
        
 
        if user_pk:
 
            lookup_params["user__pk"] = user_pk
 
        else:
 
            lookup_params["user"] = request.user
 
        
 
        try:
 
            obj.latest_vote = LatestVote.objects.get(**lookup_params).css_class()
 
            obj.user_vote = LatestVote.objects.get(**lookup_params).vote
 
            obj.user_vote_css = LatestVote.objects.get(**lookup_params).css_class()
 
        except LatestVote.DoesNotExist:
 
            obj.latest_vote = "no-vote"
 
            obj.user_vote = None
 
            obj.user_vote_css = "no-vote"
 
        
 
        yield obj
 

	
 

	
 
@login_required
 
def review_section(request, section_slug, assigned=False):
 
    
 
    if not request.user.has_perm("reviews.can_review_%s" % section_slug):
 
        return access_not_permitted(request)
 
    
 
    section = get_object_or_404(ProposalSection, section__slug=section_slug)
 
    queryset = ProposalBase.objects.filter(kind__section=section)
 
    
 
    if assigned:
 
        assignments = ReviewAssignment.objects.filter(user=request.user).values_list("proposal__id")
 
        queryset = queryset.filter(id__in=assignments)
 
    
 
    queryset = queryset.select_related("result").select_subclasses()
 
    
 
    proposals = proposals_generator(request, queryset)
 
    
 
    ctx = {
 
        "proposals": proposals,
 
        "section": section,
 
    }
 
    
 
    return render(request, "reviews/review_list.html", ctx)
 

	
 

	
 
@login_required
 
def review_list(request, section_slug, user_pk):
 
    
 
    # if they're not a reviewer admin and they aren't the person whose
 
    # review list is being asked for, don't let them in
 
    if not request.user.has_perm("reviews.can_manage_%s" % section_slug):
 
        if not request.user.pk == user_pk:
 
            return access_not_permitted(request)
 
    
 
    queryset = ProposalBase.objects.select_related("speaker__user", "result")
 
    reviewed = LatestVote.objects.filter(user__pk=user_pk).values_list("proposal", flat=True)
 
    queryset = queryset.filter(pk__in=reviewed)
 
    proposals = queryset.order_by("submitted")
 
    
 
    admin = request.user.has_perm("reviews.can_manage_%s" % section_slug)
 
    
 
    proposals = proposals_generator(request, proposals, user_pk=user_pk, check_speaker=not admin)
 
    
 
    ctx = {
 
        "proposals": proposals,
 
    }
 
    return render(request, "reviews/review_list.html", ctx)
 

	
 

	
 
@login_required
 
def review_admin(request, section_slug):
 
    
 
    if not request.user.has_perm("reviews.can_manage_%s" % section_slug):
 
        return access_not_permitted(request)
 
    
 
    def reviewers():
 
        already_seen = set()
 
        
 
        for team in Team.objects.filter(permissions__codename="can_review_%s" % section_slug):
 
            for membership in team.memberships.filter(Q(state="member") | Q(state="manager")):
symposion/templates/reviews/_review_table.html
Show inline comments
 
{% load i18n %}
 

	
 
<table class="table table-striped table-bordered table-reviews">
 
    <thead>
 
        <th>#</th>
 
        <th>{% trans "Speaker / Title" %}</th>
 
        <th>{% trans "Category" %}</th>
 
        <th><i class="icon-comment-alt"></i></th>
 
        <th>{% trans "+1" %}</th>
 
        <th>{% trans "+0" %}</th>
 
        <th>{% trans "-0" %}</th>
 
        <th>{% trans "-1" %}</th>
 
        <th><a href="#" class="tip" title="{% trans "Your Rating" %}"><i class="icon-user"></i></a></th>
 
    </thead>
 
    
 
    <tbody>
 
        {% for proposal in proposals %}
 
            <tr>
 
            <tr class="{{ proposal.user_vote_css }}">
 
                <td>{{ proposal.number }}</td>
 
                <td>
 
                    <a href="{% url review_detail proposal.pk %}">
 
                        <small><strong>{{ proposal.speaker }}</strong></small>
 
                        <br />
 
                        {{ proposal.title }}
 
                    </a>
 
                </td>
 
                <td>{{ proposal.track }}</td>
 
                <td>{{ proposal.comment_count }}</td>
 
                <td>{{ proposal.plus_one }}</td>
 
                <td>{{ proposal.plus_zero }}</td>
 
                <td>{{ proposal.minus_zero }}</td>
 
                <td>{{ proposal.minus_one }}</td>
 
                <td>{{ proposal.user_vote|default:"" }}</td>
 
            </tr>
 
        {% endfor %}
 
    </tbody>
 
</table>
symposion/templates/reviews/base.html
Show inline comments
...
 
@@ -36,81 +36,82 @@
 
        table.table thead .sorting,
 
        table.table thead .sorting_asc,
 
        table.table thead .sorting_desc,
 
        table.table thead .sorting_asc_disabled,
 
        table.table thead .sorting_desc_disabled {
 
            cursor: pointer;
 
            *cursor: hand;
 
        }
 

	
 
        table.dataTable th:active {
 
            outline: none;
 
        }
 
    </style>
 
{% endblock %}
 

	
 
{% block body_class %}reviews{% endblock %}
 

	
 
{% block body_outer %}
 
    <div class="row">
 
        <div class="span2">
 
            {% block sidebar %}
 
                <ul class="nav nav-list well">
 
                    {% for section in review_sections %}
 
                        <li class="nav-header">
 
                            {{ section }}
 
                        </li>
 
                        <li>
 
                            <a href="{% url review_section section.section.slug %}">
 
                                {% trans "All Reviews" %}
 
                            </a>
 
                        </li>
 
                        {% comment %}
 
                        <li>
 
                            <a href="{% url review_section_assignments section.section.slug %}">
 
                                {% trans "Your Assignments" %}
 
                            </a>
 
                        </li>
 
                        {% endcomment %}
 
                        <li>
 
                            <a href="{% url review_status section.section.slug %}">
 
                                {% trans "Voting Status" %}
 
                            </a>
 
                        </li>
 
                        {% if request.user.is_staff %}
 
                            <li>
 
                                <a href="{% url result_notification section.section.slug 'accepted' %}">Result Notification</a>
 
                            </li>
 
                        {% endif %}
 
                    {% endfor %}
 
                </ul>
 
            {% endblock %}
 
        </div>
 
        <div class="span10">
 
            {% block body %}
 
            {% endblock %}
 
        </div>
 
    </div>
 
{% endblock %}
 

	
 
{% block extra_script %}
 
    <script src="{{ STATIC_URL }}datatables/js/jquery.dataTables.min.js" type="text/javascript"></script>
 
    <script src="{{ STATIC_URL }}tabletools/js/TableTools.min.js" type="text/javascript"></script>
 
    <script src="{{ STATIC_URL }}datatables/js/dataTables.bootstrap.js" type="text/javascript"></script>
 
    <script type="text/javascript">
 
        $(function() {            
 
        $(function() {
 
            $(".tip").tooltip();
 
            $("table.table-reviews").dataTable({
 
                "sDom": "<'row'<'span3'l><'span3'T><'span4'f>r>t<'row'<'span3'i><'span5'p>>",
 
                "sPaginationType": "bootstrap",
 
                "bStateSave": true,
 
                "oTableTools": {
 
                    "aButtons": [
 
                        "copy",
 
                        "csv",
 
                        "print"
 
                    ],
 
                    "sSwfPath": "{{ STATIC_URL }}tabletools/swf/copy_csv_xls.swf"
 
                }
 
            });
 
        });
 
    </script>
 
{% endblock %}
0 comments (0 inline, 0 general)