Example #1
0
def propose_talk(request):
    ctx = {}
    if request.method == 'POST':
        form = TalkProposalForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            prop = TalkProposal.objects.propose(strip_tags(data['location']),
                                                data['email'],
                                                phone=data['phone'],
                                                name=data['name'])
            ctx['created'] = prop
            messages.success(request, 'Thank you, {}!'.format(prop.requestor))
            messages.info(
                request,
                'Somebody from Extinction Rebellion will contact you soon to arrange a talk at {}'
                .format(prop.location))
            set_last_contact(request, prop.requestor)
            return redirect(reverse('extinctionr.actions:talk-proposal'))
    else:
        contact = get_last_contact(request)
        initial = {}
        if contact:
            initial['email'] = contact.email
            initial['name'] = str(contact)
            initial['phone'] = contact.phone
        form = TalkProposalForm(initial=initial)
    ctx['form'] = form
    return render(request, 'talkproposal.html', ctx)
Example #2
0
def propose_talk(request):
    ctx = {}
    if request.method == "POST":
        form = TalkProposalForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            prop = TalkProposal.objects.propose(
                strip_tags(data["location"]),
                data["email"],
                phone=data["phone"],
                name=data["name"],
            )
            ctx["created"] = prop
            messages.success(request, "Thank you, {}!".format(prop.requestor))
            messages.info(
                request,
                "Somebody from Extinction Rebellion will contact you soon to arrange a talk at {}".format(
                    prop.location
                ),
            )
            set_last_contact(request, prop.requestor)
            return redirect(reverse("extinctionr.actions:talk-proposal"))
    else:
        contact = get_last_contact(request)
        initial = {}
        if contact:
            initial["email"] = contact.email
            initial["name"] = str(contact)
            initial["phone"] = contact.phone
        form = TalkProposalForm(initial=initial)
    ctx["form"] = form
    return render(request, "talkproposal.html", ctx)
Example #3
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     circle = context['object']
     if self.request.user.is_authenticated:
         is_lead = circle.can_manage(self.request.user)
         # only members of the group can see the contact info of the coordinators
         context['is_member'] = context['can_see_leads'] = circle.is_member(self.request.user)
         context['can_see_members'] = is_lead or self.request.user.has_perm('circles.view_circle')
         # context['can_see_leads'] = self.request.user.is_authenticated
         context['is_lead'] = is_lead
         context['members'] = sorted(circle.recursive_members.items(), key=lambda m: (m[0].last_name.lower(), m[0].first_name.lower()))
         context['pending'] = circle.membershiprequest_set.filter(confirmed_by=None)
         context['form'] = ContactForm(circle, initial={'role': 'member'})
         context['jobs'] = CircleJob.objects.filter(circle=circle)
         context['can_edit_member'] = self.request.user.has_perm('circles.circlemember_change')
         # if they're logged in, this is not relevant
         if 'circle_requests' in self.request.session:
             del self.request.session['circle_requests']
     if not context.get('is_lead', None):
         initial = {'circle_id': circle.id}
         last_contact = get_last_contact(self.request)
         if last_contact:
             initial['email'] = last_contact.email
             initial['name'] = str(last_contact)
         if not context.get('is_member'):
             context['request_form'] = MembershipRequestForm(initial=initial)
     if not (context.get('is_lead', None) or context.get('is_member', None)):
         context['is_pending'] = circle.is_pending(self.request)
     return context
Example #4
0
def show_action(request, slug):
    action = get_object_or_404(Action, slug=slug)
    ctx = {'action': action}
    if request.user.is_authenticated:
        ctx['attendees'] = Attendee.objects.filter(
            action=action).select_related('contact').order_by(
                '-mutual_commitment', '-promised', 'pk')
        ctx['promised'] = ctx['attendees'].filter(promised__isnull=False)
        ctx['default_to_email'] = settings.DEFAULT_FROM_EMAIL
    if action.when < now() and action.public:
        # don't allow signups for public actions that already happened
        ctx['already_happened'] = True
        form = None
    elif request.method == 'POST':
        form = SignupForm(request.POST, action=action)
        if form.is_valid():
            data = form.cleaned_data
            commit = abs(data['commit'] or 0)
            atten = action.signup(data['email'],
                                  data['role'],
                                  name=data['name'][:100],
                                  promised=data['promised'],
                                  commit=commit,
                                  notes=data['notes'])
            next_url = data['next'] or request.headers.get('referer', '/')
            messages.success(
                request,
                "Thank you for signing up for {}!".format(action.html_title))
            if commit:
                messages.info(
                    request,
                    "We will notify you once at least %d others commit" %
                    commit)
            set_last_contact(request, atten.contact)
            return redirect(next_url)
    else:
        contact = get_contact(
            email=request.user.email
        ) if request.user.is_authenticated else get_last_contact(request)
        initial = {}
        if contact:
            initial['email'] = contact.email
            initial['name'] = str(contact)
        form = SignupForm(action=action, initial=initial)
    ctx['form'] = form
    ctx['has_roles'] = list(action.available_role_choices)
    ctx['photos'] = list(action.photos.all())
    resp = render(request, 'action.html', ctx)
    resp['Vary'] = 'Cookie'
    resp['Last-Modified'] = http_date(action.modified.timestamp())
    if request.user.is_authenticated:
        resp['Cache-Control'] = 'private'
    return resp
Example #5
0
def show_action(request, slug):
    action = get_object_or_404(Action, slug=slug)
    ctx = {"action": action}
    if request.user.is_authenticated:
        ctx["attendees"] = (
            Attendee.objects.filter(action=action)
            .select_related("contact")
            .order_by("-mutual_commitment", "-promised", "pk")
        )
        ctx["promised"] = ctx["attendees"].filter(promised__isnull=False)
        ctx["default_to_email"] = settings.DEFAULT_FROM_EMAIL
    if action.when < now() and action.public:
        # don't allow signups for public actions that already happened
        ctx["already_happened"] = True
        form = None
    elif request.method == "POST":
        form = SignupForm(request.POST, action=action)
        if form.is_valid():
            data = form.cleaned_data
            commit = abs(data["commit"] or 0)
            attendee = action.signup(
                data["email"],
                data["role"],
                name=data["name"][:100],
                promised=data["promised"],
                commit=commit,
                notes=data["notes"],
            )
            next_url = data["next"] or request.headers.get("referer", "/")
            messages.success(
                request, "Thank you for signing up for {}!".format(action.html_title)
            )
            if commit:
                messages.info(
                    request,
                    "We will notify you once at least %d others commit" % commit,
                )
            set_last_contact(request, attendee.contact)
            ical_data = str(actions_to_ical([action]))
            # Send confirmation email.
            confirm_rsvp(action, attendee, ical_data)
            return redirect(next_url)
    else:
        contact = (
            get_contact(email=request.user.email)
            if request.user.is_authenticated
            else get_last_contact(request)
        )
        initial = {}
        if contact:
            initial["email"] = contact.email
            if contact.first_name:
                initial["name"] = str(contact)
        form = SignupForm(action=action, initial=initial)
    ctx["form"] = form
    ctx["has_roles"] = list(action.available_role_choices)
    ctx["photos"] = list(action.photos.all())
    if action.image:
        ctx["image"] = action.image
    resp = render(request, "action.html", ctx)
    resp["Vary"] = "Cookie"
    resp["Last-Modified"] = http_date(action.modified.timestamp())
    if request.user.is_authenticated:
        resp["Cache-Control"] = "private"
    return resp