Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 189
Added command to export reviewer's votes#650
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
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
a383ac2b4ddc51300ed873822dd375dce2ebc5a4732280969b44eb7a4e48be2664f1335ad9437e7f2495dc85222fc3cb1c9d87dbaba50508625637c99076aeb3470b579c0fbec8790fb3bcc98f13bf0c1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -91,3 +91,6 @@ qr_files/ | ||
| .vscode/ | ||
| tmp/ | ||
| # generated by command to create csv | ||
| csvs/ | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,105 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| import csv | ||||
| import os | ||||
| import sys | ||||
| from django.contrib.auth.models import User | ||||
| from django.core.management.base import BaseCommand | ||||
| from settings.common import ROOT_DIR | ||||
| from junction.base.constants import ProposalStatus | ||||
| from junction.conferences.models import Conference | ||||
| from junction.proposals.models import Proposal, ProposalSectionReviewerVoteValue | ||||
| 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 whose reviewer votes are to be exported from", | ||||
| ) | ||||
| parser.add_argument("--user_id", default=None, help="Enter your user id") | ||||
| def handle(self, *args, **options): | ||||
| try: | ||||
| conference = Conference.objects.get(slug=options.get("conference_slug")) | ||||
| user = User.objects.get(id=options.get("user_id")) | ||||
| except User.DoesNotExist: | ||||
| self.stdout.write("Invalid user") | ||||
| sys.exit(1) | ||||
| except Conference.DoesNotExist: | ||||
the-xperimentalist marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||||
| self.stdout.write("Invalid conference") | ||||
| sys.exit(1) | ||||
| if not is_conference_moderator(user=user, conference=conference): | ||||
| self.stdout.write("The user id is not a conference moderator") | ||||
| sys.exit(1) | ||||
| 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 | ||||
| ) | ||||
| proposal_vote_values = ProposalSectionReviewerVoteValue.objects.order_by( | ||||
| "-vote_value" | ||||
| ) | ||||
| vote_values_list = [v.vote_value for v in proposal_vote_values] | ||||
| vote_values_desc = tuple(i.description for i in proposal_vote_values) | ||||
| 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, | ||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think instead of junction/junction/proposals/dashboard.py Line 326 in e8cefd7
Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using dictwriter would be a lot more accurate, right? Always ensuring which values go for which fields? Probably, never creating confusion for future devs on which key belongs to which key? Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please rename the | ||||
| header[1]: p.title, | ||||
| header[2]: p.get_reviewer_votes_sum(), | ||||
| header[3]: p.get_reviewer_votes_count(), | ||||
| header[4]: p.get_votes_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.csv" % (user.username, conference.name) | ||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no section name in the filename. This will overwrite the file each time as it is opened in | ||||
| csv_base_dir = os.path.join(ROOT_DIR, "csvs") | ||||
| if not os.path.exists(csv_base_dir): | ||||
| os.makedirs(csv_base_dir) | ||||
| csv_file_location = os.path.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") | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the need of userid ? The command is supposed to be used by the admin from the console so the admin must be logged in to the application server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but there are multiple admin users, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes whoever has login access can use this command. No need to check for user id. Usually whoever is managing junction is also the one managing the server. Also user id's are not user friendly