def handle(self, *args, **options): if options['kind'] not in SLUGS: print( 'ERROR: Unknown Proposal Kind: {}\n Must be one of: {}'. format(options['kind'], ', '.join(SLUGS))) return False to_bump = defaultdict(list) unsubmitted = get_proposal_model(options['kind']).objects.filter( submitted=False, cancelled=False) for unsub in unsubmitted: path = reverse('proposal_detail', args=[unsub.id]) url = 'https://{domain}{path}'.format(domain=DOMAIN, path=path) to_bump[unsub.speaker.email].append(unsub) for email, proposals in to_bump.items(): send_email( to=[email], kind='proposal_bump', context={ 'proposal_kind': options['kind'], 'user': proposals[0].speaker.user, 'proposals': proposals, }, )
def check_one_kind(self, kind_slug, factory): section_slug = kind_slug + "s" speaker = SpeakerFactory(user=self.create_user()) section = Section.objects.get(conference=current_conference(), slug=section_slug) kind, __ = ProposalKind.objects.get_or_create(slug=kind_slug, section=section) proposal = factory( kind=kind, speaker=speaker, ) # Create a new user to be the reviewer, because nobody # can review their own proposals. reviewer = self.create_user(username="******", email="*****@*****.**") ct = ContentType.objects.get_for_model(Review) perm = Permission.objects.get(content_type=ct, codename="can_review_%s" % section_slug) reviewer.user_permissions.add(perm) perm = Permission.objects.get(content_type=ct, codename="can_manage_%s" % section_slug) reviewer.user_permissions.add(perm) self.login(username="******") url = reverse('review_section', args=(section_slug, )) data = {'status': PyConProposal.STATUS_REJECTED, 'pk': proposal.pk} rsp = self.client.post(url, data, follow=False) self.assertRedirects(rsp, url) model = get_proposal_model(kind_slug) assert model prop = model.objects.get(pk=proposal.pk) self.assertEqual(PyConProposal.STATUS_REJECTED, prop.overall_status)
def check_one_kind(self, kind_slug, factory): section_slug = kind_slug + "s" speaker = SpeakerFactory(user=self.create_user()) section = Section.objects.get(conference=current_conference(), slug=section_slug) kind, __ = ProposalKind.objects.get_or_create(slug=kind_slug, section=section) proposal = factory( kind=kind, speaker=speaker, ) # Create a new user to be the reviewer, because nobody # can review their own proposals. reviewer = self.create_user(username="******", email="*****@*****.**") ct = ContentType.objects.get_for_model(Review) perm = Permission.objects.get(content_type=ct, codename="can_review_%s" % section_slug) reviewer.user_permissions.add(perm) perm = Permission.objects.get(content_type=ct, codename="can_manage_%s" % section_slug) reviewer.user_permissions.add(perm) self.login(username="******") url = reverse('review_section', args=(section_slug,)) data = { 'status': PyConProposal.STATUS_REJECTED, 'pk': proposal.pk } rsp = self.client.post(url, data, follow=False) self.assertRedirects(rsp, url) model = get_proposal_model(kind_slug) assert model prop = model.objects.get(pk=proposal.pk) self.assertEqual(PyConProposal.STATUS_REJECTED, prop.overall_status)
def handle(self, *args, **options): if options['kind'] not in SLUGS: print('ERROR: Unknown Proposal Kind: {}\n Must be one of: {}'.format(options['kind'], ', '.join(SLUGS))) return False to_apply = defaultdict(list) to_confirm = defaultdict(list) accepted = get_proposal_model(options['kind']).objects.filter(overall_status=PyConProposal.STATUS_ACCEPTED) for proposal in accepted: if proposal.speaker.financial_support and has_application(proposal.speaker.user): application = FinancialAidApplication.objects.get(user=proposal.speaker.user) application.application_type = APPLICATION_TYPE_SPEAKER application.presenting = True application.save() path = reverse('speaker_grant_edit') url = 'https://{domain}{path}'.format(domain=DOMAIN, path=path) to_confirm[proposal.speaker.email].append(proposal) if proposal.speaker.financial_support and not has_application(proposal.speaker.user): path = reverse('speaker_grant_apply') url = 'https://{domain}{path}'.format(domain=DOMAIN, path=path) to_apply[proposal.speaker.email].append(proposal) for email, proposals in to_apply.items(): notified = Email.objects.filter( recipients='; '.join(['*****@*****.**', email]), subject='Speaker assistance for your {}.'.format(options['kind'].title()) ).exists() if notified: continue send_email_message( 'speaker_grant_apply', from_='*****@*****.**', to=['*****@*****.**', email], context={ 'proposal_kind': options['kind'], 'user': proposals[0].speaker.user, 'domain': DOMAIN, 'proposal': proposals[0], }, ) for email, proposals in to_confirm.items(): notified = Email.objects.filter( recipients='; '.join(['*****@*****.**', email]), subject='Speaker assistance for your {}.'.format(options['kind'].title()) ).exists() if notified: continue send_email_message( 'speaker_grant_confirm', from_='*****@*****.**', to=['*****@*****.**', email], context={ 'proposal_kind': options['kind'], 'user': proposals[0].speaker.user, 'domain': DOMAIN, 'proposal': proposals[0], }, )
def all_proposals(self): proposals = [] if self.proposals: for p in self.proposals.all(): proposals.append(p) if self.additionalspeakers: for p in self.additionalspeakers.all(): proposals.append(p) return [get_proposal_model(p.kind.slug).objects.get(id=p.id) for p in proposals]
def all_proposals(self): proposals = [] if self.proposals: for p in self.proposals.all(): proposals.append(p) if self.additionalspeakers: for p in self.additionalspeakers.all(): proposals.append(p) return [ get_proposal_model(p.kind.slug).objects.get(id=p.id) for p in proposals ]
def handle(self, *args, **options): if options['kind'] not in SLUGS: print('ERROR: Unknown Proposal Kind: {}\n Must be one of: {}'.format(options['kind'], ', '.join(SLUGS))) return False to_bump = defaultdict(list) unsubmitted = get_proposal_model(options['kind']).objects.filter(submitted=False, cancelled=False) for unsub in unsubmitted: path = reverse('proposal_detail', args=[unsub.id]) url = 'https://{domain}{path}'.format(domain=DOMAIN, path=path) to_bump[unsub.speaker.email].append(unsub) for email, proposals in to_bump.items(): send_email( to=[email], kind='proposal_bump', context={ 'proposal_kind': options['kind'], 'user': proposals[0].speaker.user, 'proposals': proposals, }, )
def proposals_list(request, queryset, user_pk=None, check_speaker=True): """ Returns a list of proposal objects filtered from the queryset. Ensures that each proposal has a result object associated with it. :param boolean check_speaker: If True, omits any proposals for which the current user is a speaker. """ queryset = queryset.select_related('kind', 'result__group', 'speaker__user') if user_pk is None: user_pk = request.user.pk if check_speaker: # Exclude the ones where the current user is speaking queryset = queryset.exclude(speaker__user=request.user) addl_speaker_proposals = AdditionalSpeaker.objects.filter( speaker__user=request.user, status__in=[ AdditionalSpeaker.SPEAKING_STATUS_PENDING, AdditionalSpeaker.SPEAKING_STATUS_ACCEPTED ], ).values_list('proposalbase_id', flat=True) queryset = queryset.exclude(pk__in=addl_speaker_proposals) latest_votes = { vote.proposal_id: vote for vote in LatestVote.objects.filter(user__pk=user_pk, proposal__in=queryset) } category_by_id = { cat.pk: cat for cat in PyConProposalCategory.objects.all() } result_list = [] for obj in queryset: # Force obj to be the most specific type, if it isn't already obj_model = get_proposal_model(obj.kind.slug) if not isinstance(obj, obj_model): obj = getattr(obj, obj_model._meta.model_name.lower()) 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 if obj.pk in latest_votes: obj.user_vote = latest_votes[obj.pk].vote obj.user_vote_css = latest_votes[obj.pk].css_class() else: obj.user_vote = None obj.user_vote_css = "no-vote" # We can't do select_related('category') on the initial queryset # because not all models have a category field, so we # stick a reference to a category onto the record IFFI this # model type has a category. try: obj._meta.get_field('category') except FieldDoesNotExist: pass else: if obj.category_id in category_by_id: obj.category = category_by_id[obj.category_id] result_list.append(obj) return result_list
def proposals_list(request, queryset, user_pk=None, check_speaker=True): """ Returns a list of proposal objects filtered from the queryset. Ensures that each proposal has a result object associated with it. :param boolean check_speaker: If True, omits any proposals for which the current user is a speaker. """ queryset = queryset.select_related('kind', 'result__group', 'speaker__user') if user_pk is None: user_pk = request.user.pk if check_speaker: # Exclude the ones where the current user is speaking queryset = queryset.exclude(speaker__user=request.user) addl_speaker_proposals = AdditionalSpeaker.objects.filter( speaker__user=request.user, status__in=[AdditionalSpeaker.SPEAKING_STATUS_PENDING, AdditionalSpeaker.SPEAKING_STATUS_ACCEPTED], ).values_list('proposalbase_id', flat=True) queryset = queryset.exclude(pk__in=addl_speaker_proposals) latest_votes = { vote.proposal_id: vote for vote in LatestVote.objects.filter(user__pk=user_pk, proposal__in=queryset) } category_by_id = { cat.pk: cat for cat in PyConProposalCategory.objects.all() } result_list = [] for obj in queryset: # Force obj to be the most specific type, if it isn't already obj_model = get_proposal_model(obj.kind.slug) if not isinstance(obj, obj_model): obj = getattr(obj, obj_model._meta.model_name.lower()) 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 if obj.pk in latest_votes: obj.user_vote = latest_votes[obj.pk].vote obj.user_vote_css = latest_votes[obj.pk].css_class() else: obj.user_vote = None obj.user_vote_css = "no-vote" # We can't do select_related('category') on the initial queryset # because not all models have a category field, so we # stick a reference to a category onto the record IFFI this # model type has a category. try: obj._meta.get_field('category') except FieldDoesNotExist: pass else: if obj.category_id in category_by_id: obj.category = category_by_id[obj.category_id] result_list.append(obj) return result_list