Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command to export reviewer's votes #650

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a383ac2
Python 3.5 type strings
the-xperimentalist Mar 22, 2020
b4ddc51
Added command to export as excel file
the-xperimentalist Mar 22, 2020
300ed87
Merge branch 'master' of https://github.com/prasoonmayank/junction
the-xperimentalist Mar 22, 2020
3822dd3
Change export to csv
the-xperimentalist Mar 22, 2020
75dce2e
Remove unused import
the-xperimentalist Mar 22, 2020
bc5a473
Message text change
the-xperimentalist Mar 22, 2020
2280969
Working command
the-xperimentalist Mar 24, 2020
b44eb7a
Converted from usage to csv
the-xperimentalist Mar 24, 2020
4e48be2
Remove pandas from requirements
the-xperimentalist Mar 24, 2020
664f133
Remove env file
the-xperimentalist Mar 25, 2020
5ad9437
Resolved comments and run linter
the-xperimentalist Apr 4, 2020
e7f2495
Removed return
the-xperimentalist Apr 4, 2020
dc85222
Merge branch 'master' of https://github.com/pythonindia/junction
the-xperimentalist Apr 4, 2020
fc3cb1c
Lint code based upon latest changes
the-xperimentalist Apr 5, 2020
9d87dba
Merge branch 'master' into master
the-xperimentalist Apr 15, 2020
ba50508
Fix lint issues
the-xperimentalist Apr 19, 2020
625637c
Merge branch 'master' of https://github.com/prasoonmayank/junction
the-xperimentalist Apr 19, 2020
99076ae
Resolved comments
the-xperimentalist Apr 24, 2020
b3470b5
Merge branch 'master' into master
the-xperimentalist May 2, 2020
79c0fbe
Merge branch 'master' into master
the-xperimentalist May 4, 2020
c8790fb
Merge branch 'master' into master
the-xperimentalist May 30, 2020
3bcc98f
Resolved some comments
the-xperimentalist May 30, 2020
13bf0c1
Merge branch 'master' into master
the-xperimentalist Aug 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
80 changes: 80 additions & 0 deletions junction/proposals/management/commands/export_conf_proposals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
import csv
from os.path import join
from settings.common import ROOT_DIR

from django.shortcuts import get_object_or_404
from django.core.exceptions import PermissionDenied
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

from junction.conferences.models import Conference
from junction.proposals.models import (
Proposal,
ProposalSectionReviewerVoteValue,
)
from junction.base.constants import (
ProposalReviewVote,
ProposalStatus,
ProposalReviewStatus,
)
from junction.proposals.permissions import is_conference_moderator

class Command(BaseCommand):

def add_arguments(self, parser):
parser.add_argument('--conference_slug', default=None, help='Enter the conference slug where to export reviewer votes from')

parser.add_argument('--user_id', default=None, help='Enter your user id')

def handle(self, *args, **options):

try:
conference = get_object_or_404(Conference, slug=self.options.get('conference_slug'))
the-xperimentalist marked this conversation as resolved.
Show resolved Hide resolved
user = User.objects.get(id=self.options.get('user_id'))

if not is_conference_moderator(user=user, conference=conference):
raise PermissionDenied
the-xperimentalist marked this conversation as resolved.
Show resolved Hide resolved

proposal_sections = conference.proposal_sections.all()
proposals_qs = Proposal.objects.select_related('proposal_type', 'proposal_section', 'conference', 'author').filter(conference=conference, status=ProposalStatus.PUBLIC)
proposals_qs = sorted(proposals_qs, key=lambda x: x.get_reviewer_votes_sum(), reverse=True)
vote_values_list = ProposalSectionReviewerVoteValue.objects.order_by('-vote_value')
vote_values_list = [v.vote_value for v in vote_values_list]
vote_values_desc = tuple(i.description for i in ProposalSectionReviewerVoteValue.objects.order_by('-vote_value'))
header = ('Proposal Type', 'Title', 'Sum of reviewer votes', 'No. of reviewer votes') + ('Public votes count', 'Vote comments')+ tuple(vote_values_desc)

csv_contents = []

for section in proposal_sections:
section_proposals = [p for p in proposals_qs if p.proposal_section == section]

for index, p in enumerate(section_proposals, 1):
vote_details = tuple(p.get_reviewer_votes_count_by_value(v) for v in vote_values_list)
vote_comment = '\n'.join([comment.comment for comment in p.proposalcomment_set.filter(vote=True, deleted=False)])
row = {header[0]: p.proposal_type.name,
header[1]: p.title,
header[2]: p.get_reviewer_votes_sum(),
header[3]: p.get_reviewer_votes_count(),
header[4]: p.get_voutes_count(),
header[5]: vote_comment}
for i in range(len(tuple(vote_values_desc))):
row[tuple(vote_values_desc)[i]] = vote_details[i]

csv_contents.append(row)

csv_file_name = "%s-%s" % (user.name, conference.name)
csv_file_location = join(ROOT_DIR, 'csvs', csv_file_name)

with open(csv_file_location, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=header)

writer.writeheader()
for row in csv_contents:
writer.writerow(row)

self.stdout.write("Successfully created the csv file")
except User.DoesNotExist:
self.stdout.write("Invalid user")
except Conference.DoesNotExist:
the-xperimentalist marked this conversation as resolved.
Show resolved Hide resolved
self.stdout.write("Invalid conference")