-
Notifications
You must be signed in to change notification settings - Fork 191
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
Open
the-xperimentalist
wants to merge
23
commits into
pythonindia:master
Choose a base branch
from
the-xperimentalist:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a383ac2
Python 3.5 type strings
the-xperimentalist b4ddc51
Added command to export as excel file
the-xperimentalist 300ed87
Merge branch 'master' of https://github.com/prasoonmayank/junction
the-xperimentalist 3822dd3
Change export to csv
the-xperimentalist 75dce2e
Remove unused import
the-xperimentalist bc5a473
Message text change
the-xperimentalist 2280969
Working command
the-xperimentalist b44eb7a
Converted from usage to csv
the-xperimentalist 4e48be2
Remove pandas from requirements
the-xperimentalist 664f133
Remove env file
the-xperimentalist 5ad9437
Resolved comments and run linter
the-xperimentalist e7f2495
Removed return
the-xperimentalist dc85222
Merge branch 'master' of https://github.com/pythonindia/junction
the-xperimentalist fc3cb1c
Lint code based upon latest changes
the-xperimentalist 9d87dba
Merge branch 'master' into master
the-xperimentalist ba50508
Fix lint issues
the-xperimentalist 625637c
Merge branch 'master' of https://github.com/prasoonmayank/junction
the-xperimentalist 99076ae
Resolved comments
the-xperimentalist b3470b5
Merge branch 'master' into master
the-xperimentalist 79c0fbe
Merge branch 'master' into master
the-xperimentalist c8790fb
Merge branch 'master' into master
the-xperimentalist 3bcc98f
Resolved some comments
the-xperimentalist 13bf0c1
Merge branch 'master' into master
the-xperimentalist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
80 changes: 80 additions & 0 deletions
80
junction/proposals/management/commands/export_conf_proposals.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
import io | ||
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 xlsxwriter.workbook import Workbook | ||
|
||
from junction.conferences.models import Conference | ||
from junction.proposals.models import ( | ||
Proposal, | ||
ProposalComment, | ||
ProposalSectionReviewer, | ||
ProposalSectionReviewerVoteValue, | ||
) | ||
from junction.base.constants import ( | ||
ProposalReviewVote, | ||
ProposalStatus, | ||
ProposalReviewStatus, | ||
) | ||
|
||
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): | ||
|
||
conference = get_object_or_404(Conference, slug=self.options.get('conference_slug')) | ||
user = User.objects.get(id=self.options.get('user_id')) | ||
|
||
if not conference_is_moderator(user=user, conference=conference): | ||
the-xperimentalist marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise PermissionDenied | ||
|
||
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') + tuple(vote_values_desc) + ('Public votes count', 'Vote comments') | ||
output = io.BytesIO() | ||
|
||
with Workbook(output) as book: | ||
for section in proposal_sections: | ||
sheet = book.add_worksheet(section.name[:30]) | ||
cell_format = book.add_format({'bold': True}) | ||
sheet.write_row(0, 0, header, cell_format) | ||
|
||
section_proposals = [p for p in proposal_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 = (p.proposal_type.name, p.title, p.get_reviewer_votes_sum(), p.get_reviewer_votes_count(),) + vote_details + (p.get_voutes_count(), vote_comment,) | ||
if p.get_reviewer_votes_count_by_value(ProposalSectionReviewerVoteValue.objects.get(vote_value=ProposalReviewVote.NOT_ALLOWED).vote_value) > 0: | ||
cell_format = book.add_format({'bg_color': 'red'}) | ||
elif p.get_reviewer_votes_count_by_value(ProposalSectionReviewerVoteValue.objects.get(vote_value=ProposalReviewVote.MUST_HAVE).vote_value) > 2: | ||
cell_format = book.add_format({'bg_color': 'red'}) | ||
elif p.get_reviewer_votes_count() < 2: | ||
cell_format = book.add_format({'bg_color': 'yellow'}) | ||
else: | ||
cell_format = None | ||
|
||
sheet.write_row(index, 0, row, cell_format) | ||
|
||
output.seek(0) | ||
|
||
excel_file_name = "%s-%s" % (user.name, conference.name) | ||
excel_file_location = join(ROOT_DIR, 'excels', excel_file_name) | ||
|
||
with open(excel_file_location, 'wb') as excelfile: | ||
excelfile.write(output.read()) | ||
|
||
self.stdout.write("Successfully created the excel file") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.