Files
@ 73f2cc1d1ce9
Branch filter:
Location: symposion_app/symposion/reviews/views.py - annotation
73f2cc1d1ce9
23.9 KiB
text/x-python
Merge pull request #68 from jamezpolley/lca2017
Handle slots with no Proposal
Handle slots with no Proposal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | 6811708b334d d4230feab05f 6811708b334d d4230feab05f 733c4adc530b 3d68af979659 6811708b334d 5fefff0a3dbd 3d68af979659 bd2fd5338d8d 3d68af979659 3d68af979659 11f697d13757 11f697d13757 11f697d13757 11f697d13757 3d68af979659 0aca96152f65 3d68af979659 0aca96152f65 0aca96152f65 3d68af979659 3d68af979659 1c727a989bfb 733c4adc530b 699b32b938d2 1c727a989bfb 3d68af979659 3d68af979659 3d68af979659 11f697d13757 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 47a6f212f217 3d68af979659 f1f29c6f61de 3d68af979659 3d68af979659 f1f29c6f61de 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 cc032da2887a cc032da2887a 3d68af979659 cc032da2887a cc032da2887a 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 29fa7c63a9e5 36ab6d599ffc 36ab6d599ffc 3d68af979659 6c1cfd1a53be 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 5b853f930082 36ab6d599ffc 3d68af979659 36ab6d599ffc 36ab6d599ffc 3d68af979659 36ab6d599ffc 6c1cfd1a53be 6c1cfd1a53be 6c1cfd1a53be 0ad89365e9b3 6c1cfd1a53be 6c1cfd1a53be 0ad89365e9b3 6c1cfd1a53be 0ad89365e9b3 78d13a9ffa45 78d13a9ffa45 6c1cfd1a53be 36ab6d599ffc d43d42bbc35b d43d42bbc35b d43d42bbc35b 36ab6d599ffc 3d68af979659 3d68af979659 c7dd6e6f8d2e 0ad89365e9b3 3d68af979659 36ab6d599ffc 11f697d13757 3d68af979659 36ab6d599ffc 6811708b334d 6811708b334d 6811708b334d 6811708b334d 6811708b334d 2a6c19244936 2a6c19244936 2a6c19244936 2a6c19244936 6811708b334d 6811708b334d 6811708b334d 6811708b334d c0f47070323e d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 6811708b334d 6811708b334d 6811708b334d 6811708b334d 6811708b334d 6811708b334d 6811708b334d 6811708b334d 6ebd0f09057b 7b6843ca1e09 7b6843ca1e09 6811708b334d d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 d9b1583dfe61 6ebd0f09057b 6811708b334d 6811708b334d 6811708b334d 6811708b334d f12633039065 f12633039065 f12633039065 f12633039065 f12633039065 6811708b334d 6811708b334d 2a6c19244936 6811708b334d 6811708b334d d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f d4230feab05f 29fa7c63a9e5 29fa7c63a9e5 07198b2ecfd6 29fa7c63a9e5 29fa7c63a9e5 5735c7745e44 efd6ff88f811 5735c7745e44 5735c7745e44 5735c7745e44 5735c7745e44 5735c7745e44 5735c7745e44 5735c7745e44 5735c7745e44 5735c7745e44 29fa7c63a9e5 d4230feab05f d4230feab05f 5735c7745e44 d4230feab05f d4230feab05f d4230feab05f 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 d56bcea2e683 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 36ab6d599ffc 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 24f8ac875711 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 32c2d697b0f0 32c2d697b0f0 32c2d697b0f0 32c2d697b0f0 5735c7745e44 3217f43af2c5 9ae17146df49 9ae17146df49 3217f43af2c5 3f5ee591b6b4 3f5ee591b6b4 3217f43af2c5 3217f43af2c5 3d68af979659 3217f43af2c5 3217f43af2c5 3d68af979659 3217f43af2c5 3217f43af2c5 3d68af979659 3217f43af2c5 3217f43af2c5 f1f29c6f61de 3217f43af2c5 3217f43af2c5 3217f43af2c5 3217f43af2c5 3217f43af2c5 3217f43af2c5 9ae17146df49 9ae17146df49 9ae17146df49 9ae17146df49 20ad44236bb5 20ad44236bb5 9ae17146df49 36ab6d599ffc 3d68af979659 36ab6d599ffc cc6db4ed8882 b9b27abdce37 cc6db4ed8882 3d68af979659 3d68af979659 faa30b8866bf 3d68af979659 11f697d13757 3d68af979659 3d68af979659 f557337433d5 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc ce122994ccad 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 9223c8fc9092 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 9223c8fc9092 9223c8fc9092 9223c8fc9092 9223c8fc9092 9223c8fc9092 9223c8fc9092 9223c8fc9092 3d68af979659 3d68af979659 ce122994ccad 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 04228555827f 3d68af979659 3d68af979659 04228555827f 3d68af979659 3d68af979659 04228555827f 04228555827f 8f5291b539b1 8f5291b539b1 3d68af979659 699b32b938d2 699b32b938d2 699b32b938d2 699b32b938d2 699b32b938d2 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 f1f29c6f61de 3d68af979659 3d68af979659 f1f29c6f61de 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc 11f697d13757 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 ce122994ccad ce122994ccad 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 14dea7eafa5f 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 1cb22cea953d 1cb22cea953d 36ab6d599ffc 3d68af979659 0aca96152f65 0aca96152f65 3d68af979659 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 29fa7c63a9e5 36ab6d599ffc 3d68af979659 36ab6d599ffc 6ee3ff5d4599 54991cd4d187 54991cd4d187 6ee3ff5d4599 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 6ee3ff5d4599 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 11f697d13757 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 11f697d13757 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 36ab6d599ffc 36ab6d599ffc 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 3d68af979659 04228555827f 3d68af979659 14d127a122af 3d68af979659 3d68af979659 36ab6d599ffc 11f697d13757 3d68af979659 3d68af979659 3dd746836545 3dd746836545 3dd746836545 3dd746836545 3dd746836545 3dd746836545 36ab6d599ffc 3dd746836545 aa8db3c919a1 36ab6d599ffc 3dd746836545 3dd746836545 5fefff0a3dbd 3dd746836545 aa8db3c919a1 3dd746836545 11f697d13757 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 36ab6d599ffc aafc4e003eac aafc4e003eac 36ab6d599ffc 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 36ab6d599ffc b754bb9addf2 b754bb9addf2 b754bb9addf2 b754bb9addf2 b754bb9addf2 36ab6d599ffc 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 1f9ceed0e1f2 5fefff0a3dbd b754bb9addf2 5fefff0a3dbd 11f697d13757 5fefff0a3dbd 5fefff0a3dbd aafc4e003eac 5fefff0a3dbd 5fefff0a3dbd 5fefff0a3dbd 36ab6d599ffc aafc4e003eac aafc4e003eac 36ab6d599ffc ecfabd5b7093 df0ea0655cf3 36ab6d599ffc df0ea0655cf3 b754bb9addf2 df0ea0655cf3 df0ea0655cf3 36ab6d599ffc df0ea0655cf3 df0ea0655cf3 df0ea0655cf3 df0ea0655cf3 df0ea0655cf3 df0ea0655cf3 df0ea0655cf3 36ab6d599ffc b754bb9addf2 b754bb9addf2 b754bb9addf2 b754bb9addf2 b754bb9addf2 36ab6d599ffc 733c4adc530b 36ab6d599ffc 733c4adc530b 733c4adc530b 733c4adc530b 733c4adc530b 733c4adc530b ecfabd5b7093 c7608fb0d5fa 420d8ec870bd 420d8ec870bd c7608fb0d5fa 420d8ec870bd 420d8ec870bd bd2fd5338d8d bd2fd5338d8d c7608fb0d5fa bd2fd5338d8d bd2fd5338d8d 733c4adc530b 733c4adc530b 36ab6d599ffc 733c4adc530b 36ab6d599ffc df0ea0655cf3 | import csv
import random
import StringIO
from django.core.mail import send_mass_mail
from django.db.models import Q
from django.http import HttpResponse
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 account.decorators import login_required
# @@@ switch to pinax-teams
from symposion.teams.models import Team
from symposion.conf import settings
from symposion.proposals.models import ProposalBase, ProposalSection
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, promote_proposal
)
def access_not_permitted(request):
return render(request, "symposion/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.score = obj.result.score
obj.total_votes = obj.result.vote_count
obj.plus_two = obj.result.plus_two
obj.plus_one = obj.result.plus_one
obj.minus_one = obj.result.minus_one
obj.minus_two = obj.result.minus_two
lookup_params = dict(proposal=obj)
if user_pk:
lookup_params["user__pk"] = user_pk
else:
lookup_params["user"] = request.user
try:
obj.user_vote = LatestVote.objects.get(**lookup_params).vote
obj.user_vote_css = LatestVote.objects.get(**lookup_params).css_class()
except LatestVote.DoesNotExist:
obj.user_vote = None
obj.user_vote_css = "no-vote"
yield obj
VOTE_THRESHOLD = settings.SYMPOSION_VOTE_THRESHOLD
POSITIVE = "positive"
NEGATIVE = "negative"
INDIFFERENT = "indifferent"
CONTROVERSIAL = "controversial"
TOO_FEW = "too_few"
REVIEW_STATUS_FILTERS = {
# proposals with at least VOTE_THRESHOLD reviews and at least one +2 and no -2s, sorted by
# the 'score'
POSITIVE: lambda qs: qs.filter(result__vote_count__gte=VOTE_THRESHOLD, result__plus_two__gt=0,
result__minus_two=0).order_by("-result__score"),
# proposals with at least VOTE_THRESHOLD reviews and at least one -2 and no +2s, reverse
# sorted by the 'score'
NEGATIVE: lambda qs: qs.filter(result__vote_count__gte=VOTE_THRESHOLD, result__minus_two__gt=0,
result__plus_two=0).order_by("result__score"),
# proposals with at least VOTE_THRESHOLD reviews and neither a +2 or a -2, sorted by total
# votes (lowest first)
INDIFFERENT: lambda qs: qs.filter(result__vote_count__gte=VOTE_THRESHOLD, result__minus_two=0,
result__plus_two=0).order_by("result__vote_count"),
# proposals with at least VOTE_THRESHOLD reviews and both a +2 and -2, sorted by total
# votes (highest first)
CONTROVERSIAL: lambda qs: qs.filter(result__vote_count__gte=VOTE_THRESHOLD,
result__plus_two__gt=0, result__minus_two__gt=0)
.order_by("-result__vote_count"),
# proposals with fewer than VOTE_THRESHOLD reviews
TOO_FEW: lambda qs: qs.filter(result__vote_count__lt=VOTE_THRESHOLD)
.order_by("result__vote_count"),
}
# Returns a list of all proposals, proposals reviewed by the user, or the proposals the user has
# yet to review depending on the link user clicks in dashboard
@login_required
def review_section(request, section_slug, assigned=False, reviewed="all"):
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.section)
if assigned:
assignments = ReviewAssignment.objects.filter(user=request.user)\
.values_list("proposal__id")
queryset = queryset.filter(id__in=assignments)
# passing reviewed in from reviews.urls and out to review_list for
# appropriate template header rendering
if reviewed == "all":
queryset = queryset.select_related("result").select_subclasses()
reviewed = "all_reviews"
elif reviewed == "reviewed":
queryset = queryset.filter(reviews__user=request.user)
reviewed = "user_reviewed"
else:
queryset = queryset.exclude(reviews__user=request.user).exclude(
speaker__user=request.user)
reviewed = "user_not_reviewed"
# lca2017 #21 -- chairs want to be able to see their own proposals in the list
check_speaker = not request.user.has_perm("reviews.can_manage_%s" % section_slug)
proposals = proposals_generator(request, queryset, check_speaker=check_speaker)
ctx = {
"proposals": proposals,
"section": section,
"reviewed": reviewed,
}
return render(request, "symposion/reviews/review_list.html", ctx)
@login_required
def review_all_proposals_csv(request):
''' Returns a CSV representation of all of the proposals this user has
permisison to review. '''
response = HttpResponse("text/csv")
response['Content-Disposition'] = 'attachment; filename="proposals.csv"'
writer = csv.writer(response, quoting=csv.QUOTE_NONNUMERIC)
queryset = ProposalBase.objects.filter()
# The fields from each proposal object to report in the csv
fields = [
"id", "proposal_type", "speaker_name","speaker_email", "title",
"submitted", "other_speakers", "speaker_travel",
"speaker_accommodation", "cancelled", "status", "score", "total_votes",
"minus_two", "minus_one", "plus_one", "plus_two",
]
# Fields are the heading
writer.writerow(fields)
for proposal in proposals_generator(request, queryset, check_speaker=False):
proposal.speaker_name = proposal.speaker.name
section_slug = proposal.kind.section.slug
kind_slug = proposal.kind.slug
proposal.proposal_type = kind_slug
proposal.other_speakers = ", ".join(
speaker.name
for speaker in proposal.additional_speakers.all()
)
proposal.speaker_travel = ", ".join(
str(bool(speaker.travel_assistance))
for speaker in proposal.speakers()
)
proposal.speaker_accommodation = ", ".join(
str(bool(speaker.accommodation_assistance))
for speaker in proposal.speakers()
)
if not request.user.has_perm("reviews.can_review_%s" % section_slug):
continue
csv_line = [getattr(proposal, field) for field in fields]
# Enusre that unicode items are handled properly.
for i, item in enumerate(csv_line):
if isinstance(item, unicode):
csv_line[i] = item.encode("utf8")
writer.writerow(csv_line)
return response
@login_required
def review_random_proposal(request, section_slug):
# lca2017 #16 view for random proposal
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.section)
# Remove ones already reviewed
queryset = queryset.exclude(reviews__user=request.user)
# Remove talks the reviewer can't vote on -- their own.
queryset = queryset.exclude(speaker__user=request.user)
queryset = queryset.exclude(additional_speakers__user=request.user)
if len(queryset) == 0:
return redirect("review_section", section_slug=section_slug, reviewed="all")
# Direct reviewers to underreviewed proposals
too_few_set = REVIEW_STATUS_FILTERS[TOO_FEW](queryset)
controversial_set = REVIEW_STATUS_FILTERS[CONTROVERSIAL](queryset)
if len(too_few_set) > 0:
proposals = too_few_set.all()
elif len(controversial_set) > 0 and random.random() < 0.2:
proposals = controversial_set.all()
else:
# Select a proposal with less than the median number of total votes
proposals = proposals_generator(request, queryset, check_speaker=False)
proposals = list(proposals)
proposals.sort(key = lambda proposal: proposal.total_votes)
# The first half is the median or less.
# The +1 means we round _up_.
proposals = proposals[:(len(proposals) + 1) / 2]
# Realistically, there shouldn't be all that many proposals to choose
# from, so this should be cheap.
chosen = random.choice(proposals)
return redirect("review_detail", pk=chosen.pk)
@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(kind__section__slug=section_slug)
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, "symposion/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")):
user = membership.user
if user.pk in already_seen:
continue
already_seen.add(user.pk)
user.comment_count = Review.objects.filter(
user=user,
proposal__kind__section__slug=section_slug,
).count()
user_votes = LatestVote.objects.filter(
user=user,
proposal__kind__section__slug=section_slug,
)
print section_slug
print [vote.proposal.kind.section.slug for vote in user_votes]
user.total_votes = user_votes.exclude(
vote=LatestVote.VOTES.ABSTAIN,
).count()
user.plus_two = user_votes.filter(
vote=LatestVote.VOTES.PLUS_TWO,
).count()
user.plus_one = user_votes.filter(
vote=LatestVote.VOTES.PLUS_ONE,
).count()
user.minus_one = user_votes.filter(
vote=LatestVote.VOTES.MINUS_ONE,
).count()
user.minus_two = user_votes.filter(
vote=LatestVote.VOTES.MINUS_TWO,
).count()
user.abstain = user_votes.filter(
vote=LatestVote.VOTES.ABSTAIN,
).count()
if user.total_votes == 0:
user.average = "-"
else:
user.average = (
((user.plus_two * 2) + user.plus_one) -
((user.minus_two * 2) + user.minus_one)
) / (user.total_votes * 1.0)
yield user
reviewers_sorted = list(reviewers())
reviewers_sorted.sort(key= lambda reviewer: 0 - reviewer.total_votes)
ctx = {
"section_slug": section_slug,
"reviewers": reviewers_sorted,
}
return render(request, "symposion/reviews/review_admin.html", ctx)
# FIXME: This view is too complex according to flake8
@login_required
def review_detail(request, pk):
proposals = ProposalBase.objects.select_related("result").select_subclasses()
proposal = get_object_or_404(proposals, pk=pk)
if not request.user.has_perm("reviews.can_review_%s" % proposal.kind.section.slug):
return access_not_permitted(request)
speakers = [s.user for s in proposal.speakers()]
if not request.user.is_superuser and request.user in speakers:
return access_not_permitted(request)
admin = request.user.has_perm("reviews.can_manage_%s" % proposal.kind.section.slug)
try:
latest_vote = LatestVote.objects.get(proposal=proposal, user=request.user)
except LatestVote.DoesNotExist:
latest_vote = None
if request.method == "POST":
if request.user in speakers:
return access_not_permitted(request)
if "vote_submit" in request.POST or "vote_submit_and_random" in request.POST:
review_form = ReviewForm(request.POST)
if review_form.is_valid():
review = review_form.save(commit=False)
review.user = request.user
review.proposal = proposal
review.save()
if "vote_submit_and_random" in request.POST:
next_page = redirect("user_random", proposal.kind.section.slug)
next_page["Location"] += "#invalid_fragment" # Hack.
else:
next_page = redirect(request.path)
return next_page
else:
message_form = SpeakerCommentForm()
elif "message_submit" in request.POST and admin:
message_form = SpeakerCommentForm(request.POST)
if message_form.is_valid():
message = message_form.save(commit=False)
message.user = request.user
message.proposal = proposal
message.save()
for speaker in speakers:
if speaker and speaker.email:
ctx = {
"proposal": proposal,
"message": message,
"reviewer": False,
}
send_email(
[speaker.email], "proposal_new_message",
context=ctx
)
return redirect(request.path)
else:
initial = {}
if latest_vote:
initial["vote"] = latest_vote.vote
if request.user in speakers:
review_form = None
else:
review_form = ReviewForm(initial=initial)
elif "result_submit" in request.POST:
if admin:
result = request.POST["result_submit"]
if result == "accept":
proposal.result.status = "accepted"
proposal.result.save()
elif result == "reject":
proposal.result.status = "rejected"
proposal.result.save()
elif result == "undecide":
proposal.result.status = "undecided"
proposal.result.save()
elif result == "standby":
proposal.result.status = "standby"
proposal.result.save()
return redirect(request.path)
elif "publish_changes" in request.POST:
if admin and proposal.result.status == "accepted":
promote_proposal(proposal)
return redirect(request.path)
else:
initial = {}
if latest_vote:
initial["vote"] = latest_vote.vote
if request.user in speakers:
review_form = None
else:
review_form = ReviewForm(initial=initial)
message_form = SpeakerCommentForm()
proposal.comment_count = proposal.result.comment_count
proposal.total_votes = proposal.result.vote_count
proposal.plus_two = proposal.result.plus_two
proposal.plus_one = proposal.result.plus_one
proposal.minus_one = proposal.result.minus_one
proposal.minus_two = proposal.result.minus_two
reviews = Review.objects.filter(proposal=proposal).order_by("-submitted_at")
messages = proposal.messages.order_by("submitted_at")
return render(request, "symposion/reviews/review_detail.html", {
"proposal": proposal,
"latest_vote": latest_vote,
"reviews": reviews,
"review_messages": messages,
"review_form": review_form,
"message_form": message_form,
"is_manager": admin
})
@login_required
@require_POST
def review_delete(request, pk):
review = get_object_or_404(Review, pk=pk)
section_slug = review.section
if not request.user.has_perm("reviews.can_manage_%s" % section_slug):
return access_not_permitted(request)
review = get_object_or_404(Review, pk=pk)
review.delete()
return redirect("review_detail", pk=review.proposal.pk)
@login_required
def review_status(request, section_slug=None, key=None):
if not request.user.has_perm("reviews.can_review_%s" % section_slug):
return access_not_permitted(request)
ctx = {
"section_slug": section_slug,
"vote_threshold": VOTE_THRESHOLD,
}
queryset = ProposalBase.objects.select_related("speaker__user", "result").select_subclasses()
if section_slug:
queryset = queryset.filter(kind__section__slug=section_slug)
proposals = dict((key, filt(queryset)) for key, filt in REVIEW_STATUS_FILTERS.items())
admin = request.user.has_perm("reviews.can_manage_%s" % section_slug)
for status in proposals:
if key and key != status:
continue
proposals[status] = list(proposals_generator(request, proposals[status], check_speaker=not admin))
if key:
ctx.update({
"key": key,
"proposals": proposals[key],
})
else:
ctx["proposals"] = proposals
return render(request, "symposion/reviews/review_stats.html", ctx)
@login_required
def review_assignments(request):
if not request.user.groups.filter(name="reviewers").exists():
return access_not_permitted(request)
assignments = ReviewAssignment.objects.filter(
user=request.user,
opted_out=False
)
return render(request, "symposion/reviews/review_assignment.html", {
"assignments": assignments,
})
@login_required
@require_POST
def review_assignment_opt_out(request, pk):
review_assignment = get_object_or_404(
ReviewAssignment, pk=pk, user=request.user)
if not review_assignment.opted_out:
review_assignment.opted_out = True
review_assignment.save()
ReviewAssignment.create_assignments(
review_assignment.proposal, origin=ReviewAssignment.AUTO_ASSIGNED_LATER)
return redirect("review_assignments")
@login_required
def review_bulk_accept(request, section_slug):
if not request.user.has_perm("reviews.can_manage_%s" % section_slug):
return access_not_permitted(request)
if request.method == "POST":
form = BulkPresentationForm(request.POST)
if form.is_valid():
talk_ids = form.cleaned_data["talk_ids"].split(",")
talks = ProposalBase.objects.filter(id__in=talk_ids).select_related("result")
for talk in talks:
talk.result.status = "accepted"
talk.result.save()
return redirect("review_section", section_slug=section_slug)
else:
form = BulkPresentationForm()
return render(request, "symposion/reviews/review_bulk_accept.html", {
"form": form,
})
@login_required
def result_notification(request, section_slug, status):
if not request.user.has_perm("reviews.can_manage_%s" % section_slug):
return access_not_permitted(request)
proposals = ProposalBase.objects.filter(kind__section__slug=section_slug, result__status=status).select_related("speaker__user", "result").select_subclasses()
notification_templates = NotificationTemplate.objects.all()
ctx = {
"section_slug": section_slug,
"status": status,
"proposals": proposals,
"notification_templates": notification_templates,
}
return render(request, "symposion/reviews/result_notification.html", ctx)
@login_required
def result_notification_prepare(request, section_slug, status):
if request.method != "POST":
return HttpResponseNotAllowed(["POST"])
if not request.user.has_perm("reviews.can_manage_%s" % section_slug):
return access_not_permitted(request)
proposal_pks = []
try:
for pk in request.POST.getlist("_selected_action"):
proposal_pks.append(int(pk))
except ValueError:
return HttpResponseBadRequest()
proposals = ProposalBase.objects.filter(
kind__section__slug=section_slug,
result__status=status,
)
proposals = proposals.filter(pk__in=proposal_pks)
proposals = proposals.select_related("speaker__user", "result")
proposals = proposals.select_subclasses()
notification_template_pk = request.POST.get("notification_template", "")
if notification_template_pk:
notification_template = NotificationTemplate.objects.get(pk=notification_template_pk)
else:
notification_template = None
ctx = {
"section_slug": section_slug,
"status": status,
"notification_template": notification_template,
"proposals": proposals,
"proposal_pks": ",".join([str(pk) for pk in proposal_pks]),
}
return render(request, "symposion/reviews/result_notification_prepare.html", ctx)
@login_required
def result_notification_send(request, section_slug, status):
if request.method != "POST":
return HttpResponseNotAllowed(["POST"])
if not request.user.has_perm("reviews.can_manage_%s" % section_slug):
return access_not_permitted(request)
if not all([k in request.POST for k in ["proposal_pks", "from_address", "subject", "body"]]):
return HttpResponseBadRequest()
try:
proposal_pks = [int(pk) for pk in request.POST["proposal_pks"].split(",")]
except ValueError:
return HttpResponseBadRequest()
proposals = ProposalBase.objects.filter(
kind__section__slug=section_slug,
result__status=status,
)
proposals = proposals.filter(pk__in=proposal_pks)
proposals = proposals.select_related("speaker__user", "result")
proposals = proposals.select_subclasses()
notification_template_pk = request.POST.get("notification_template", "")
if notification_template_pk:
notification_template = NotificationTemplate.objects.get(pk=notification_template_pk)
else:
notification_template = None
emails = []
for proposal in proposals:
rn = ResultNotification()
rn.proposal = proposal
rn.template = notification_template
rn.to_address = proposal.speaker_email
rn.from_address = request.POST["from_address"]
proposal_context = proposal.notification_email_context()
rn.subject = Template(request.POST["subject"]).render(
Context({
"proposal": proposal_context
})
)
rn.body = Template(request.POST["body"]).render(
Context({
"proposal": proposal_context
})
)
rn.save()
emails.append(rn.email_args)
send_mass_mail(emails)
return redirect("result_notification", section_slug=section_slug, status=status)
|