コード例 #1
0
ファイル: views.py プロジェクト: DjangoBD/symposion
def team_detail(request, slug):
    team = get_object_or_404(Team, slug=slug)
    state = team.get_state_for_user(request.user)
    if team.access == "invitation" and state is None and not request.user.is_staff:
        raise Http404()

    if can_invite(team, request.user):
        if request.method == "POST":
            form = TeamInvitationForm(request.POST, team=team)
            if form.is_valid():
                form.invite()
                send_email([form.user.email], "teams_user_invited", context={"team": team})
                messages.success(request, _("Invitation created."))
                return redirect("team_detail", slug=slug)
        else:
            form = TeamInvitationForm(team=team)
    else:
        form = None

    return render(request, "symposion/teams/team_detail.html", {
        "team": team,
        "state": state,
        "invite_form": form,
        "can_join": can_join(team, request.user),
        "can_leave": can_leave(team, request.user),
        "can_apply": can_apply(team, request.user),
    })
コード例 #2
0
    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,
                },
            )
コード例 #3
0
def team_detail(request, slug):
    team = get_object_or_404(Team, slug=slug)
    state = team.get_state_for_user(request.user)
    if team.access == "invitation" and state is None and not request.user.is_staff:
        raise Http404()

    if can_invite(team, request.user):
        if request.method == "POST":
            form = TeamInvitationForm(request.POST, team=team)
            if form.is_valid():
                form.invite()
                send_email([form.user.email],
                           "teams_user_invited",
                           context={"team": team})
                messages.success(request, "Invitation created.")
                return redirect("team_detail", slug=slug)
        else:
            form = TeamInvitationForm(team=team)
    else:
        form = None

    return render(
        request, "teams/team_detail.html", {
            "team": team,
            "state": state,
            "invite_form": form,
            "can_join": can_join(team, request.user),
            "can_leave": can_leave(team, request.user),
            "can_apply": can_apply(team, request.user),
        })
コード例 #4
0
ファイル: views.py プロジェクト: pyconjp/pyconjp-website
def proposal_edit(request, pk):
    queryset = ProposalBase.objects.select_related("speaker")
    proposal = get_object_or_404(queryset, pk=pk)
    proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)

    if request.user != proposal.speaker.user:
        raise Http404()

    if not proposal.can_edit():
        ctx = {"title": "Proposal editing closed", "body": "Proposal editing is closed for this session type."}
        return render(request, "proposals/proposal_error.html", ctx)

    form_class = get_form(settings.PROPOSAL_FORMS[proposal.kind.slug])

    if request.method == "POST":
        form = form_class(request.POST, request.FILES, instance=proposal)
        if form.is_valid():
            form.save()
            if hasattr(proposal, "reviews"):
                users = User.objects.filter(Q(review__proposal=proposal) | Q(proposalmessage__proposal=proposal))
                users = users.exclude(id=request.user.id).distinct()
                for user in users:
                    ctx = {"user": request.user, "proposal": proposal}
                    send_email([user.email], "proposal_updated", context=ctx)
            messages.success(request, "Proposal updated.")
            return redirect("proposal_detail", proposal.pk)
    else:
        form = form_class(instance=proposal)

    return render(request, "proposals/proposal_edit.html", {"proposal": proposal, "form": form})
コード例 #5
0
    def handle(self, *args, **options):
        group = ProposalGroup.objects.get(
            name=options["proposal_group_name"], )
        reviewers = self.get_reviewers()
        if options['new_reviewers']:
            user_reviews = self.assign_new_user_reviews(group, reviewers)
        else:
            user_reviews = self.assign_user_reviews(group, reviewers)

        for user, proposal_results in user_reviews.iteritems():
            print("Sending assignments to %r" % user.email)
            for pr in proposal_results:
                ReviewAssignment.objects.get_or_create(
                    proposal=pr.proposal,
                    user=user,
                    origin=ReviewAssignment.AUTO_ASSIGNED_INITIAL,
                )
            send_email(
                [user.email],
                "new_review_assignments",
                context={
                    "user": user,
                    "proposal_results": proposal_results,
                    "proposal_group": group,
                })
コード例 #6
0
ファイル: admin.py プロジェクト: PyCon/pycon
 def save_model(self, request, obj, form, change):
     # First, save the object
     super(PresentationAdmin, self).save_model(request, obj, form, change)
     # Next, send an email to python staff
     now = datetime.datetime.now()
     send_email(
         [settings.REGISTRATION_EMAIL],
         "presentation_updated",
         context={"presentation": obj,
                  "time": now,
                  "user": request.user}
     )
コード例 #7
0
ファイル: admin.py プロジェクト: SaptakS/pune.pycon.org
 def save_model(self, request, obj, form, change):
     # First, save the object
     super(PresentationAdmin, self).save_model(request, obj, form, change)
     # Next, send an email to python staff
     now = datetime.datetime.now()
     send_email([settings.REGISTRATION_EMAIL],
                "presentation_updated",
                context={
                    "presentation": obj,
                    "time": now,
                    "user": request.user
                })
コード例 #8
0
def _send_admin_email(sender, instance, created, **kwargs):
    """
    Send an email to the sponsors mailing list when a new application is
    submitted.
    """
    if created:
        send_email(
            to=[settings.SPONSORSHIP_EMAIL],
            kind='new_sponsor',
            context={
                'sponsor': instance,
            },
        )
コード例 #9
0
ファイル: models.py プロジェクト: Diwahars/pycon
def _send_admin_email(sender, instance, created, **kwargs):
    """
    Send an email to the sponsors mailing list when a new application is
    submitted.
    """
    if created:
        send_email(
            to=['*****@*****.**'],
            kind='new_sponsor',
            context={
                'sponsor': instance,
            },
        )
コード例 #10
0
ファイル: views.py プロジェクト: issackelly/symposion
def proposal_detail(request, pk):
    queryset = Proposal.objects.select_related("speaker", "speaker__user")
    proposal = get_object_or_404(queryset, pk=pk)
    
    if request.user not in [p.user for p in proposal.speakers()]:
        raise Http404()
    
    if not settings.ACCEPTING_PROPOSALS:
        from symposion.review.forms import SpeakerCommentForm
        message_form = SpeakerCommentForm()
        if request.method == "POST":
            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()
                
                ProposalMessage = SpeakerCommentForm.Meta.model
                reviewers = User.objects.filter(
                    id__in=ProposalMessage.objects.filter(
                        proposal=proposal
                    ).exclude(
                        user=request.user
                    ).distinct().values_list("user", flat=True)
                )
                
                for reviewer in reviewers:
                    ctx = {
                        "proposal": proposal,
                        "message": message,
                        "reviewer": True,
                    }
                    send_email(
                        [reviewer.email], "proposal_new_message",
                        context = ctx
                    )
                
                return redirect(request.path)
        else:
            message_form = SpeakerCommentForm()
    else:
        message_form = None
    
    ctx = {
        "proposal": proposal,
        "message_form": message_form,
    }
    ctx = RequestContext(request, ctx)
    return render_to_response("proposals/proposal_detail.html", ctx)
コード例 #11
0
ファイル: views.py プロジェクト: wvolz/symposion
def proposal_detail(request, pk):
    queryset = ProposalBase.objects.select_related("speaker", "speaker__user")
    proposal = get_object_or_404(queryset, pk=pk)
    proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)
    
    if request.user not in [p.user for p in proposal.speakers()]:
        raise Http404()
    
    if "symposion.reviews" in settings.INSTALLED_APPS:
        from symposion.reviews.forms import SpeakerCommentForm
        message_form = SpeakerCommentForm()
        if request.method == "POST":
            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()
                
                ProposalMessage = SpeakerCommentForm.Meta.model
                reviewers = User.objects.filter(
                    id__in=ProposalMessage.objects.filter(
                        proposal=proposal
                    ).exclude(
                        user=request.user
                    ).distinct().values_list("user", flat=True)
                )
                
                for reviewer in reviewers:
                    ctx = {
                        "proposal": proposal,
                        "message": message,
                        "reviewer": True,
                    }
                    send_email(
                        [reviewer.email], "proposal_new_message",
                        context=ctx
                    )
                
                return redirect(request.path)
        else:
            message_form = SpeakerCommentForm()
    else:
        message_form = None
    
    return render(request, "proposals/proposal_detail.html", {
        "proposal": proposal,
        "message_form": message_form
    })
コード例 #12
0
ファイル: views.py プロジェクト: TheOpenBastion/symposion
def sponsor_add(request):
    if not request.user.is_staff:
        raise Http404()

    CHOICES = []
    for s in SponsorLevel.objects.all():
        CHOICES.append(( s, s.name + ': ' + ', '.join([b.benefit.name for b in BenefitLevel.objects.filter(level = s)]) ))

    if request.method == "POST":
        form = SponsorApplicationForm(request.POST, user=request.user, choices=CHOICES)

        if form.is_valid():
            sponsor = form.save(commit=False)
            sponsor.save()

            event_name = settings.EVENT_NAME
            event_website = settings.EVENT_WEBSITE
            event_email = settings.EVENT_EMAIL
            event_phone = settings.EVENT_PHONE

            message_ctx = {
                "sponsor": sponsor,
                "event_name": event_name,
                "event_website": event_website,
                "event_email": event_email,
                "event_phone": event_phone
            }

            for c in sponsor.sponsor_contacts:
                sponsor_email = c
                send_email(
                    [sponsor_email], "sponsor_signup_conf",
                    context = message_ctx
                )
            staff_members = User.objects.filter(is_staff=True)
            for staff in staff_members:
                staff_email = staff.email
                send_email(
                    [staff_email], "sponsor_signup",
                    context = message_ctx
                )
            return redirect("sponsor_detail", pk=sponsor.pk)
    else:
        form = SponsorApplicationForm(user=request.user, choices=CHOICES)

    return render_to_response("sponsorship/add.html", {
        "form": form,
    }, context_instance=RequestContext(request))
コード例 #13
0
ファイル: views.py プロジェクト: symposite/symposion
def team_apply(request, slug):
    team = get_object_or_404(Team, slug=slug)
    state = team.get_state_for_user(request.user)
    if team.access == "invitation" and state is None and not request.user.is_staff:
        raise Http404()

    if can_apply(team, request.user) and request.method == "POST":
        membership, created = Membership.objects.get_or_create(team=team, user=request.user)
        membership.state = "applied"
        membership.save()
        managers = [m.user.email for m in team.managers()]
        send_email(managers, "teams_user_applied", context={"team": team, "user": request.user})
        messages.success(request, _("Applied to join team."))
        return redirect("team_detail", slug=slug)
    else:
        return redirect("team_detail", slug=slug)
コード例 #14
0
ファイル: views.py プロジェクト: pyconau2017/symposion
def proposal_edit(request, pk):
    queryset = ProposalBase.objects.select_related("speaker")
    proposal = get_object_or_404(queryset, pk=pk)
    proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)

    if request.user != proposal.speaker.user:
        raise Http404()

    if not proposal.can_edit():
        ctx = {
            "title": "Proposal editing closed",
            "body": "Proposal editing is closed for this session type."
        }
        return render(request, "symposion/proposals/proposal_error.html", ctx)

    form_class = get_form(settings.PROPOSAL_FORMS[proposal.kind.slug])

    if request.method == "POST":
        form = form_class(request.POST, instance=proposal)
        if form.is_valid():
            form.save()
            if hasattr(proposal, "reviews"):
                # Miniconf updates should only email the admins
                if proposal.kind.slug == 'miniconf':
                    users = User.objects.filter(
                        username__in=settings.ADMIN_USERNAMES)
                else:
                    users = User.objects.filter(
                        Q(review__proposal=proposal)
                        | Q(proposalmessage__proposal=proposal))
                users = users.exclude(id=request.user.id).distinct()
                for user in users:
                    ctx = {
                        "user": request.user,
                        "proposal": proposal,
                    }
                    send_email([user.email], "proposal_updated", context=ctx)
            messages.success(request, "Proposal updated.")
            return redirect("proposal_detail", proposal.pk)
    else:
        form = form_class(instance=proposal)

    return render(request, "symposion/proposals/proposal_edit.html", {
        "proposal": proposal,
        "form": form,
    })
コード例 #15
0
def proposal_edit(request, pk):
    queryset = ProposalBase.objects.select_related("speaker")
    proposal = get_object_or_404(queryset, pk=pk)
    proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)

    if request.user != proposal.speaker.user:
        raise Http404()

    if not proposal.can_edit():
        ctx = {
            "title": "Proposal editing closed",
            "body": "Proposal editing is closed for this session type.",
        }
        return render(request, "symposion/proposals/proposal_error.html", ctx)

    try:
        form_class = get_form(settings.PROPOSAL_FORMS[proposal.kind.slug])
    except KeyError:
        form_class = get_form(settings.DEFAULT_PROPOSAL_FORM)

    if request.method == "POST":
        form = form_class(request.POST, instance=proposal)
        if form.is_valid():
            form.save()
            if hasattr(proposal, "review_votes"):
                users = User.objects.filter(
                    Q(review_votes__proposal=proposal)
                    | Q(review_feedback__proposal=proposal))
                users = users.exclude(id=request.user.id).distinct()
                for user in users:
                    ctx = {"user": request.user, "proposal": proposal}
                    send_email([user.email], "proposal_updated", context=ctx)
            messages.success(request, "Proposal updated.")
            return redirect("proposal_detail", proposal.pk)
    else:
        form = form_class(instance=proposal)

    return render(
        request,
        "symposion/proposals/proposal_edit.html",
        {
            "proposal": proposal,
            "form": form
        },
    )
コード例 #16
0
ファイル: models.py プロジェクト: PyCon/pycon
def _send_confirmation(sender, instance, created, **kwargs):
    """
    Send an email to the sponsors mailing list when a new application is
    submitted.
    """
    if created:
        send_email(
            to=[settings.SPONSORSHIP_EMAIL],
            kind='new_sponsor',
            context={
                'sponsor': instance,
            },
        )
        send_email(
            to=instance.contact_emails,
            kind='new_sponsor_confirm',
            context={'sponsor': instance}
        )
コード例 #17
0
ファイル: __init__.py プロジェクト: codeur66/conf_site
 def post(self, *args, **kwargs):
     """AJAX update an individual ProposalVote object."""
     proposal = Proposal.objects.get(pk=kwargs["pk"])
     feedback = ProposalFeedback.objects.create(
         proposal=proposal,
         author=self.request.user,
         comment=self.request.POST["comment"],
     )
     # Send email to proposal speakers.
     speaker_email_addressses = []
     for speaker in proposal.speakers():
         # Only send messages to speakers with email addresses
         # who are not the author of this message.
         if (speaker.email and speaker.user
                 and speaker.user != self.request.user
                 and speaker.email not in speaker_email_addressses):
             speaker_email_addressses.append(speaker.email)
     send_email(
         speaker_email_addressses,
         "proposal_new_message",
         context={
             "proposal": proposal,
             "message": feedback,
             "reviewer": False,
         },
     )
     # Send email to reviewers.
     reviewer_email_addresses = []
     for feedback in proposal.review_feedback.all():
         if (feedback.author.email and feedback.author != self.request.user
                 and feedback.author.email not in reviewer_email_addresses):
             reviewer_email_addresses.append(feedback.author.email)
     send_email(
         reviewer_email_addresses,
         "proposal_new_message",
         context={
             "proposal": proposal,
             "message": feedback,
             "reviewer": True,
         },
     )
     return HttpResponseRedirect(
         reverse("review_proposal_detail", args=[proposal.id]))
コード例 #18
0
def team_apply(request, slug):
    team = get_object_or_404(Team, slug=slug)
    state = team.get_state_for_user(request.user)
    if team.access == "invitation" and state is None and not request.user.is_staff:
        raise Http404()

    if can_apply(team, request.user) and request.method == "POST":
        membership, created = Membership.objects.get_or_create(
            team=team, user=request.user)
        membership.state = "applied"
        membership.save()
        managers = [m.user.email for m in team.managers()]
        send_email(managers,
                   "teams_user_applied",
                   context={
                       "team": team,
                       "user": request.user
                   })
        messages.success(request, "Applied to join team.")
        return redirect("team_detail", slug=slug)
    else:
        return redirect("team_detail", slug=slug)
コード例 #19
0
ファイル: views.py プロジェクト: pyohio/symposion
def proposal_speaker_manage(request, pk):
    queryset = ProposalBase.objects.select_related("speaker")
    proposal = get_object_or_404(queryset, pk=pk)
    proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)

    if proposal.speaker != request.user.speaker_profile:
        raise Http404()

    if request.method == "POST":
        add_speaker_form = AddSpeakerForm(request.POST, proposal=proposal)
        if add_speaker_form.is_valid():
            message_ctx = {"proposal": proposal}

            def create_speaker_token(email_address):
                # create token and look for an existing speaker to prevent
                # duplicate tokens and confusing the pending speaker
                try:
                    pending = Speaker.objects.get(Q(user=None, invite_email=email_address))
                except Speaker.DoesNotExist:
                    salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
                    token = hashlib.sha1(salt + email_address).hexdigest()
                    pending = Speaker.objects.create(invite_email=email_address, invite_token=token)
                else:
                    token = pending.invite_token
                return pending, token

            email_address = add_speaker_form.cleaned_data["email"]
            # check if email is on the site now
            users = EmailAddress.objects.get_users_for(email_address)
            if users:
                # should only be one since we enforce unique email
                user = users[0]
                message_ctx["user"] = user
                # look for speaker profile
                try:
                    speaker = user.speaker_profile
                except ObjectDoesNotExist:
                    speaker, token = create_speaker_token(email_address)
                    message_ctx["token"] = token
                    # fire off email to user to create profile
                    send_email([email_address], "speaker_no_profile", context=message_ctx)
                else:
                    # fire off email to user letting them they are loved.
                    send_email([email_address], "speaker_addition", context=message_ctx)
            else:
                speaker, token = create_speaker_token(email_address)
                message_ctx["token"] = token
                # fire off email letting user know about site and to create
                # account and speaker profile
                send_email([email_address], "speaker_invite", context=message_ctx)
            invitation, created = AdditionalSpeaker.objects.get_or_create(
                proposalbase=proposal.proposalbase_ptr, speaker=speaker
            )
            messages.success(request, "Speaker invited to proposal.")
            return redirect("proposal_speaker_manage", proposal.pk)
    else:
        add_speaker_form = AddSpeakerForm(proposal=proposal)
    ctx = {"proposal": proposal, "speakers": proposal.speakers(), "add_speaker_form": add_speaker_form}
    return render(request, "proposals/proposal_speaker_manage.html", ctx)
コード例 #20
0
ファイル: assign_reviewers.py プロジェクト: PyCon/pycon
    def handle(self, *args, **options):
        group = ProposalGroup.objects.get(
            name=options["proposal_group_name"],
        )
        reviewers = self.get_reviewers()
        if options['new_reviewers']:
            user_reviews = self.assign_new_user_reviews(group, reviewers)
        else:
            user_reviews = self.assign_user_reviews(group, reviewers)

        for user, proposal_results in user_reviews.iteritems():
            print("Sending assignments to %r" % user.email)
            for pr in proposal_results:
                ReviewAssignment.objects.get_or_create(
                    proposal=pr.proposal,
                    user=user,
                    origin=ReviewAssignment.AUTO_ASSIGNED_INITIAL,
                )
            send_email([user.email], "new_review_assignments", context={
                "user": user,
                "proposal_results": proposal_results,
                "proposal_group": group,
            })
コード例 #21
0
    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,
                },
            )
コード例 #22
0
def sponsor_apply(request):
    if request.method == "POST":
        form = SponsorApplicationForm(request.POST, user=request.user)
        if form.is_valid():
            sponsor = form.save()
            # Send email notification of successful application.
            for manager in settings.MANAGERS:
                send_email(
                    [manager[1]],
                    "sponsor_signup",
                    context={"sponsor": sponsor},
                )
            if sponsor.sponsor_benefits.all():
                # Redirect user to sponsor_detail to give extra information.
                messages.success(
                    request,
                    _("Thank you for your sponsorship "
                      "application. Please update your "
                      "benefit details below."),
                )
                return redirect("sponsor_detail", pk=sponsor.pk)
            else:
                messages.success(
                    request,
                    _("Thank you for your sponsorship "
                      "application."),
                )
                return redirect("dashboard")
    else:
        form = SponsorApplicationForm(user=request.user)

    return render(
        request=request,
        template_name="symposion/sponsorship/apply.html",
        context={"form": form},
    )
コード例 #23
0
ファイル: models.py プロジェクト: toopy/symposion
 def send_coordinator_emails(self):
     for user in User.objects.filter(groups__name=SPONSOR_COORDINATORS):
         send_email(
             [user.email], "sponsor_signup",
             context = {"sponsor": self}
         )
コード例 #24
0
ファイル: views.py プロジェクト: wenlien/PyConTW
def proposal_speaker_manage(request, pk):
    queryset = Proposal.objects.select_related("speaker")
    proposal = get_object_or_404(queryset, pk=pk)
    if proposal.speaker != request.user.speaker_profile:
        raise Http404()
    if request.method == "POST":
        add_speaker_form = AddSpeakerForm(request.POST, proposal=proposal)
        if add_speaker_form.is_valid():
            message_ctx = {
                "proposal": proposal,
            }

            def create_speaker_token(email_address):
                # create token and look for an existing speaker to prevent
                # duplicate tokens and confusing the pending speaker
                try:
                    pending = Speaker.objects.get(
                        Q(user=None, invite_email=email_address))
                except Speaker.DoesNotExist:
                    salt = sha_constructor(str(
                        random.random())).hexdigest()[:5]
                    token = sha_constructor(salt + email_address).hexdigest()
                    pending = Speaker.objects.create(
                        invite_email=email_address,
                        invite_token=token,
                    )
                else:
                    token = pending.invite_token
                return pending, token

            email_address = add_speaker_form.cleaned_data["email"]
            # check if email is on the site now
            users = EmailAddress.objects.get_users_for(email_address)
            if users:
                # should only be one since we enforce unique email
                user = users[0]
                message_ctx["user"] = user
                # look for speaker profile
                try:
                    speaker = user.speaker_profile
                except ObjectDoesNotExist:
                    speaker, token = create_speaker_token(email_address)
                    message_ctx["token"] = token
                    # fire off email to user to create profile
                    send_email([email_address],
                               "speaker_no_profile",
                               context=message_ctx)
                else:
                    # fire off email to user letting them they are loved.
                    send_email([email_address],
                               "speaker_addition",
                               context=message_ctx)
            else:
                speaker, token = create_speaker_token(email_address)
                message_ctx["token"] = token
                # fire off email letting user know about site and to create
                # account and speaker profile
                send_email([email_address],
                           "speaker_invite",
                           context=message_ctx)
            proposal.additional_speakers.add(speaker)
            messages.success(request, "Speaker added to proposal.")
            return redirect("proposal_speaker_manage", proposal.pk)
    else:
        add_speaker_form = AddSpeakerForm(proposal=proposal)
    ctx = {
        "proposal": proposal,
        "speakers": proposal.speakers(),
        "add_speaker_form": add_speaker_form,
    }
    ctx = RequestContext(request, ctx)
    return render_to_response("proposals/proposal_speaker_manage.html", ctx)
コード例 #25
0
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.is_staff

    try:
        latest_vote = LatestVote.objects.get(proposal=proposal,
                                             user=request.user)
    except LatestVote.DoesNotExist:
        latest_vote = None

    review_form = None
    message_form = None
    proposal_tags_form = None

    if request.method == "POST":
        if request.user in speakers:
            return access_not_permitted(request)

        if "vote_submit" in request.POST \
                and (is_voting_period_active(proposal) or is_review_period_active(proposal)):
            if is_voting_period_active(proposal):
                review_form = ReviewForm(request.POST)
            else:
                review_form = NonVotingReviewForm(request.POST)
            if review_form.is_valid():

                review = review_form.save(commit=False)
                review.user = request.user
                review.proposal = proposal
                review.save()

                return redirect(request.path)
            else:
                message_form = SpeakerCommentForm()
        elif "tags_submit" in request.POST:
            proposal_tags_form = ProposalTagsForm(request.POST)
            if proposal_tags_form.is_valid():

                tags = proposal_tags_form.cleaned_data['tags']
                proposal.tags.set(*tags)

                return redirect(request.path)
            else:
                message_form = SpeakerCommentForm()
                if request.user not in speakers:
                    initial = {}
                    if latest_vote:
                        initial["vote"] = latest_vote.vote

                    if is_voting_period_active(proposal):
                        review_form = ReviewForm(initial=initial)
                    elif is_review_period_active(proposal):
                        review_form = NonVotingReviewForm()
        elif "message_submit" in request.POST and is_review_period_active(
                proposal):
            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 not in speakers:
                    if is_voting_period_active(proposal):
                        review_form = ReviewForm(initial=initial)
                    elif is_review_period_active(proposal):
                        review_form = NonVotingReviewForm()
        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)
    else:
        initial = {}
        if latest_vote:
            initial["vote"] = latest_vote.vote
        if request.user not in speakers:
            if is_voting_period_active(proposal):
                review_form = ReviewForm(initial=initial)
            elif is_review_period_active(proposal):
                review_form = NonVotingReviewForm()
            tags = edit_string_for_tags(proposal.tags.all())
            proposal_tags_form = ProposalTagsForm(initial={'tags': tags})
        if is_review_period_active(proposal) and request.user not in speakers:
            message_form = SpeakerCommentForm()

    proposal.comment_count = proposal.result.comment_count
    proposal.total_votes = proposal.result.vote_count
    proposal.plus_one = proposal.result.plus_one
    proposal.plus_zero = proposal.result.plus_zero
    proposal.minus_zero = proposal.result.minus_zero
    proposal.minus_one = proposal.result.minus_one

    reviews = Review.objects.filter(
        proposal=proposal).order_by("-submitted_at")
    messages = proposal.messages.order_by("submitted_at")

    return render(
        request, "reviews/review_detail.html", {
            "proposal": proposal,
            "latest_vote": latest_vote,
            "reviews": reviews,
            "review_messages": messages,
            "review_form": review_form,
            "proposal_tags_form": proposal_tags_form,
            "message_form": message_form,
        })
コード例 #26
0
ファイル: views.py プロジェクト: mariobuikhuizen/conf_site
def proposal_speaker_manage(request, pk):
    queryset = ProposalBase.objects.select_related("speaker")
    proposal = get_object_or_404(queryset, pk=pk)
    proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)

    if proposal.speaker != request.user.speaker_profile:
        raise Http404()

    if request.method == "POST":
        add_speaker_form = AddSpeakerForm(request.POST, proposal=proposal)
        if add_speaker_form.is_valid():
            message_ctx = {"proposal": proposal}

            def create_speaker_token(email_address):
                # create token and look for an existing speaker to prevent
                # duplicate tokens and confusing the pending speaker
                try:
                    pending = Speaker.objects.get(
                        Q(user=None, invite_email=email_address))
                except Speaker.DoesNotExist:
                    token = get_random_string(5)
                    pending = Speaker.objects.create(
                        invite_email=email_address, invite_token=token)
                else:
                    token = pending.invite_token
                return pending, token

            email_address = add_speaker_form.cleaned_data["email"]
            # check if email is on the site now
            users = EmailAddress.objects.get_users_for(email_address)
            if users:
                # should only be one since we enforce unique email
                user = users[0]
                message_ctx["user"] = user
                # look for speaker profile
                try:
                    speaker = user.speaker_profile
                except ObjectDoesNotExist:
                    speaker, token = create_speaker_token(email_address)
                    message_ctx["token"] = token
                    # fire off email to user to create profile
                    send_email(
                        [email_address],
                        "speaker_no_profile",
                        context=message_ctx,
                    )
                else:
                    # fire off email to user letting them they are loved.
                    send_email(
                        [email_address],
                        "speaker_addition",
                        context=message_ctx,
                    )
            else:
                speaker, token = create_speaker_token(email_address)
                message_ctx["token"] = token
                # fire off email letting user know about site and to create
                # account and speaker profile
                send_email([email_address],
                           "speaker_invite",
                           context=message_ctx)
            invitation, created = AdditionalSpeaker.objects.get_or_create(
                proposalbase=proposal.proposalbase_ptr, speaker=speaker)
            messages.success(request, "Speaker invited to proposal.")
            return redirect("proposal_speaker_manage", proposal.pk)
    else:
        add_speaker_form = AddSpeakerForm(proposal=proposal)

    # Get invited speakers for this proposal.
    invited_speakers = AdditionalSpeaker.objects.filter(
        proposalbase=proposal.proposalbase_ptr).exclude(
            status=AdditionalSpeaker.SPEAKING_STATUS_ACCEPTED)
    ctx = {
        "proposal": proposal,
        "speakers": proposal.speakers(),
        "invited_speakers": invited_speakers,
        "add_speaker_form": add_speaker_form,
    }
    return render(request, "symposion/proposals/proposal_speaker_manage.html",
                  ctx)
コード例 #27
0
ファイル: views.py プロジェクト: TheOpenBastion/symposion
def sponsor_passes(request):
    if not request.user.is_staff:
        raise Http404()

    # Turn back if eventbrite not being used or if config data missing from settings
    if not settings.EVENTBRITE == True:
        messages.error(request, "We're sorry, Eventbrite isn't being used for this conference.")
        return redirect('dashboard')
    elif settings.EB_APP_KEY == '' or settings.EB_USER_KEY == '' or settings.EB_EVENT_ID == '':
        messages.error(request, "Eventbrite client has not been configured properly in settings. Please contact conference organizer about this issue.")
        return redirect('dashboard')
    else:
        # grab authentication credentials
        eb_event_id = settings.EB_EVENT_ID
        eb_auth_tokens = {
            'app_key': settings.EB_APP_KEY,
            'user_key': settings.EB_USER_KEY
        }

        # Make first request for basic event and ticket info
        eb_client = eventbrite.EventbriteClient(eb_auth_tokens)
        response = eb_client.event_get({
            'id': eb_event_id
            })

        # Make choices list of ticket names and prices for our form
        TICKET_CHOICES = []
        ticket_dict = {}
        tickets = response['event']['tickets']
        for tkt in tickets:
            ticket = tkt['ticket']
            # don't include donation ('type' == 1) tickets
            if ticket['type'] != 1:
                ticket_name = ticket['name']
                ticket_id = ticket['id']
                price = ticket['price']

            # Make dict of name/id pairs for discount generation
                ticket_dict[ticket_name] = ticket_id

            # Make our choices list for form
                TICKET_CHOICES.append(( ticket_name, ticket_name + ' -- $' + price ))

        # Next, make a list of *active* sponsors to add to our form
        SPONSOR_CHOICES = []
        for sponsor in Sponsor.objects.filter(active=True):
            SPONSOR_CHOICES.append((sponsor, sponsor))

        # we also need event title and url for our email
        event_title = response['event']['title']
        event_url = response['event']['url']


        # If form is valid, process form and generate discount
        if request.method == "POST":
            form = SponsorPassesForm(request.POST, tickets=TICKET_CHOICES, sponsors=SPONSOR_CHOICES)

            if form.is_valid():
                sponsor = form.cleaned_data["sponsor"]
                ticket_names = form.cleaned_data["ticket_names"]
                amount_off = form.cleaned_data["amount_off"]
                percent_off = form.cleaned_data["percent_off"]

                # match selected ticket types to ticket ids from our dict
                tickets_list = ','.join(str(v) for k, v in ticket_dict.iteritems() if k in ticket_names)


                # Eventbrite will only accept one of the following: amount_off or percent_off
                # Create variables to pass into our request one or other depending on staff input
                if amount_off != None and percent_off == None:
                    discount_n = 'amount_off'
                    discount_v = amount_off
                elif percent_off != None and amount_off == None:
                    discount_n = 'percent_off'
                    discount_v = percent_off

                # Generate discount code
                discount_code = (sponsor[:6] + '_' + event_title[:6]).replace(' ', '')

                # Alert user if discount already exists
                # Except case where no discounts exist to check against
                try:
                    response = eb_client.event_list_discounts({
                        'id': eb_event_id
                    })
                    for dsct in response['discounts']:
                        discount = dsct['discount']
                        if discount['code'] == discount_code:
                            messages.error(request, "Oops, looks like that discount code already exists")
                            return redirect("sponsor_passes")

                except EnvironmentError:
                    response = ''
                    pass

                # Send request to eventbrite to register the discount code w/params
                response = eb_client.discount_new({
                    'event_id': eb_event_id,
                    'code': discount_code,
                    discount_n : discount_v,
                    'quantity_available': int(form.cleaned_data["number_of_passes"]),
                    'tickets': tickets_list
                })

                # Auto-email to sponsor contact with discount code
                for spsr in Sponsor.objects.filter(name = sponsor):
                    contact_name = spsr.contact_name
                    contact_email = spsr.contact_email

                event_email = settings.EVENT_EMAIL
                event_phone = settings.EVENT_PHONE

                message_ctx = {
                    "event_name": event_title,
                    "sponsor": sponsor,
                    "contact_name": contact_name,
                    "discount_code": discount_code,
                    "event_url": event_url,
                    "event_contact_email": event_email,
                    "event_contact_phone": event_phone
                }
                send_email(
                    [contact_email], "sponsor_passes",
                    context = message_ctx
                )

                messages.success(request, "Discount code was generated and has been emailed to sponsor contact")

                return redirect("dashboard")
        else:
            form = SponsorPassesForm(sponsors=SPONSOR_CHOICES, tickets=TICKET_CHOICES)

        return render_to_response("sponsorship/passes.html", {
            "form": form,
        }, context_instance=RequestContext(request))
コード例 #28
0
ファイル: views.py プロジェクト: DjangoBD/symposion
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.is_staff

    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:
            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()

                return redirect(request.path)
            else:
                message_form = SpeakerCommentForm()
        elif "message_submit" in request.POST:
            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)
    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_one = proposal.result.plus_one
    proposal.plus_zero = proposal.result.plus_zero
    proposal.minus_zero = proposal.result.minus_zero
    proposal.minus_one = proposal.result.minus_one

    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
    })
コード例 #29
0
ファイル: views.py プロジェクト: wenlien/PyConTW
def review_detail(request, pk):
    proposals = Proposal.objects.select_related("result")
    proposal = get_object_or_404(proposals, pk=pk)

    admin = request.user.groups.filter(name="reviewers-admins").exists()
    speakers = [s.user for s in proposal.speakers()]

    if proposal.kind.name.lower() == "tutorial":
        if not request.user.groups.filter(name="reviewers-tutorials").exists():
            return access_not_permitted(request)
    else:
        if not request.user.groups.filter(name="reviewers").exists():
            return access_not_permitted(request)

    if not admin and request.user in speakers:
        return access_not_permitted(request)

    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 hasattr(proposal, "invited") and proposal.invited:
            return access_not_permitted(request)

        if "vote_submit" 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()

                return redirect(request.path)
            else:
                message_form = SpeakerCommentForm()
        elif "message_submit" in request.POST:
            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)
        elif "result_submit" in request.POST:
            if admin:
                result = request.POST["result_submit"]

                if result == "accept":
                    proposal.result.accepted = True
                    proposal.result.save()
                elif result == "reject":
                    proposal.result.accepted = False
                    proposal.result.save()
                elif result == "undecide":
                    proposal.result.accepted = None
                    proposal.result.save()

            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_one = proposal.result.plus_one
    proposal.plus_zero = proposal.result.plus_zero
    proposal.minus_zero = proposal.result.minus_zero
    proposal.minus_one = proposal.result.minus_one

    reviews = Review.objects.filter(
        proposal=proposal).order_by("-submitted_at")

    return render_to_response("review/review_detail.html", {
        "proposal": proposal,
        "latest_vote": latest_vote,
        "reviews": reviews,
        "review_form": review_form,
        "message_form": message_form,
    },
                              context_instance=RequestContext(request))
コード例 #30
0
def review_detail(request_review_detail, pk):

    proposals = ProposalBase.objects.select_related(
        "result").select_subclasses()
    proposal = get_object_or_404(proposals, pk=pk)

    if not request_review_detail.user.has_perm(
            "reviews.can_review_%s" % proposal.kind.section.slug):
        return render(request_review_detail,
                      "symposion/reviews/access_not_permitted.html",
                      "you do not have access to review details")

    speakers = [s.user for s in proposal.speakers()]

    if not request_review_detail.user.is_superuser and request_review_detail.user in speakers:
        return render(request_review_detail,
                      "symposion/reviews/access_not_permitted.html",
                      "you do not have access to review details for speakers")

    admin = request_review_detail.user.is_staff

    try:
        latest_vote = LatestVote.objects.get(proposal=proposal,
                                             user=request_review_detail.user)
    except LatestVote.DoesNotExist:
        latest_vote = None

    if request_review_detail.method == "POST":
        if request_review_detail.user in speakers:
            return render(
                request_review_detail,
                "symposion/reviews/access_not_permitted.html",
                "you do not have access to review details for speakers")

        if "vote_submit" in request_review_detail.POST:
            review_form = ReviewForm(request_review_detail.POST)
            if review_form.is_valid():

                review = review_form.save(commit=False)
                review.user = request_review_detail.user
                review.proposal = proposal
                review.save()

                return redirect(request_review_detail.path)
            else:
                message_form = SpeakerCommentForm()
        elif "message_submit" in request_review_detail.POST:
            message_form = SpeakerCommentForm(request_review_detail.POST)
            if message_form.is_valid():

                message = message_form.save(commit=False)
                message.user = request_review_detail.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_review_detail.path)
            else:
                initial = {}
                if latest_vote:
                    initial["vote"] = latest_vote.vote
                if request_review_detail.user in speakers:
                    review_form = None
                else:
                    review_form = ReviewForm(initial=initial)
        elif "result_submit" in request_review_detail.POST:
            if admin:
                result = request_review_detail.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_review_detail.path)
    else:
        initial = {}
        if latest_vote:
            initial["vote"] = latest_vote.vote
        if request_review_detail.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_one = proposal.result.plus_one
    proposal.plus_zero = proposal.result.plus_zero
    proposal.minus_zero = proposal.result.minus_zero
    proposal.minus_one = proposal.result.minus_one

    reviews = Review.objects.filter(
        proposal=proposal).order_by("-submitted_at")
    messages = proposal.messages.order_by("submitted_at")

    return render(
        request_review_detail, "symposion/reviews/review_detail.html", {
            "proposal": proposal,
            "latest_vote": latest_vote,
            "reviews": reviews,
            "review_messages": messages,
            "review_form": review_form,
            "message_form": message_form
        })
コード例 #31
0
def proposal_speaker_manage(request, pk):
    queryset = ProposalBase.objects.select_related("speaker")
    proposal = get_object_or_404(queryset, pk=pk)
    proposal = ProposalBase.objects.get_subclass(pk=proposal.pk)

    if proposal.speaker != request.user.speaker_profile:
        raise Http404()

    if request.method == "POST":
        add_speaker_form = AddSpeakerForm(request.POST, proposal=proposal)
        if add_speaker_form.is_valid():
            message_ctx = {
                "proposal": proposal,
            }

            def create_speaker_token(email_address):
                # create token and look for an existing speaker to prevent
                # duplicate tokens and confusing the pending speaker
                try:
                    pending = Speaker.objects.get(
                        Q(invite_email=email_address))
                except Speaker.DoesNotExist:
                    salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
                    token = hashlib.sha1(salt + email_address).hexdigest()
                    pending = Speaker.objects.create(
                        invite_email=email_address,
                        invite_token=token,
                    )
                else:
                    token = pending.invite_token
                return pending, token

            email_address = add_speaker_form.cleaned_data["email"]

            # django-selectable widget will return a User for emails that are
            # associated with a current User, else a string
            if isinstance(email_address, User):
                email_address = email_address.email

            # check if email is on the site now
            users = EmailAddress.objects.get_users_for(email_address)
            if users:
                # should only be one since we enforce unique email
                user = users[0]
                message_ctx["user"] = user
                # look for speaker profile
                try:
                    speaker = user.speaker_profile
                except ObjectDoesNotExist:
                    speaker, token = create_speaker_token(email_address)
                    message_ctx["token"] = token
                    # fire off email to user to create profile
                    send_email([email_address],
                               "speaker_no_profile",
                               context=message_ctx)
                else:
                    # fire off email to user letting them they are loved.
                    send_email([email_address],
                               "speaker_addition",
                               context=message_ctx)
            else:
                speaker, token = create_speaker_token(email_address)
                message_ctx["token"] = token
                # fire off email letting user know about site and to create
                # account and speaker profile
                send_email([email_address],
                           "speaker_invite",
                           context=message_ctx)
            invitation, created = AdditionalSpeaker.objects.get_or_create(
                proposalbase=proposal.proposalbase_ptr, speaker=speaker)
            messages.success(request, "Speaker invited to proposal.")
            return redirect("proposal_speaker_manage", proposal.pk)
    else:
        add_speaker_form = AddSpeakerForm(proposal=proposal)

    ctx = {
        "proposal": proposal,
        "speakers": proposal.speakers(),
        "add_speaker_form": add_speaker_form,
    }
    return render(request, "proposals/proposal_speaker_manage.html", ctx)
コード例 #32
0
ファイル: views.py プロジェクト: pyconau2017/symposion
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
        })
コード例 #33
0
ファイル: models.py プロジェクト: taavi/pycon
 def send_coordinator_emails(self):
     for user in User.objects.filter(groups__name=SPONSOR_COORDINATORS):
         send_email([user.email],
                    "sponsor_signup",
                    context={"sponsor": self})
コード例 #34
0
ファイル: views.py プロジェクト: CTPUG/pyconza2012-symposion
def review_detail(request, pk):
    proposals = Proposal.objects.select_related("result")
    proposal = get_object_or_404(proposals, pk=pk)
    
    admin = request.user.groups.filter(name="reviewers-admins").exists()
    speakers = [s.user for s in proposal.speakers()]
    
    if proposal.kind.name.lower() == "tutorial":
        if not request.user.groups.filter(name="reviewers-tutorials").exists():
            return access_not_permitted(request)
    else:
        if not request.user.groups.filter(name="reviewers").exists():
            return access_not_permitted(request)
    
    if not admin and request.user in speakers:
        return access_not_permitted(request)
    
    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 hasattr(proposal, "invited") and proposal.invited:
            return access_not_permitted(request)
        
        if "vote_submit" 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()
                
                return redirect(request.path)
            else:
                message_form = SpeakerCommentForm()
        elif "message_submit" in request.POST:
            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)
        elif "result_submit" in request.POST:
            if admin:
                result = request.POST["result_submit"]
                
                if result == "accept":
                    proposal.result.accepted = True
                    proposal.result.save()
                elif result == "reject":
                    proposal.result.accepted = False
                    proposal.result.save()
                elif result == "undecide":
                    proposal.result.accepted = None
                    proposal.result.save()
            
            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_one = proposal.result.plus_one
    proposal.plus_zero = proposal.result.plus_zero
    proposal.minus_zero = proposal.result.minus_zero
    proposal.minus_one = proposal.result.minus_one
    
    reviews = Review.objects.filter(proposal=proposal).order_by("-submitted_at")
    
    return render_to_response("review/review_detail.html", {
        "proposal": proposal,
        "latest_vote": latest_vote,
        "reviews": reviews,
        "review_form": review_form,
        "message_form": message_form
    }, context_instance=RequestContext(request))