示例#1
0
    def form_valid(self, form):
        data = form.cleaned_data
        person = get_contact(
            email=data['email'],
            first_name=data['first_name'],
            last_name=data['last_name'],
            postcode=data['zipcode'],
            phone=data['phone'])
        person.tags.add('self-signup')

        working_group = data['working_group']
        ip_address = self.request.META.get('HTTP_X_FORWARDED_FOR', self.request.META.get('REMOTE_ADDR', 'unknown address'))

        signup_obj = Signup(
                ip_address=ip_address,
                contact=person
        )
        signup_obj.data = data
        if working_group != 'UNKNOWN':
            circle = get_circle(data['working_group'])
            if circle and circle.request_membership(contact=person):
                messages.success(self.request, 'Requested membership in {}'.format(circle))
        signup_obj.save()
        set_last_contact(self.request, person)
        return HttpResponseRedirect('/welcome/guide')
示例#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)
示例#3
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)
示例#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
示例#5
0
def request_membership(request, pk):
    circle = get_object_or_404(Circle, pk=pk)
    if request.method == 'POST':
        form = MembershipRequestForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            contact = circle.request_membership(data['email'], data['name'])
            if contact and not request.user.is_authenticated:
                set_last_contact(request, contact)
                circle_requests = request.session.get('circle_requests', {})
                circle_requests[str(circle.id)] = True
                request.session['circle_requests'] = circle_requests
            messages.success(request, "Thank you for signing up for {}!".format(circle))
    return redirect(circle.get_absolute_url())
示例#6
0
    def form_valid(self, form):
        data = form.cleaned_data
        jwt_token = data['message']
        try:
            self.decode_token(jwt_token)
        except:  # noqa E722
            return HttpResponseRedirect('/')

        postcode = data['zipcode']
        city, state = zipcode_lookup(postcode)
        person = get_contact(email=data['email'],
                             first_name=data['first_name'],
                             last_name=data['last_name'],
                             postcode=postcode,
                             city=city,
                             state=state,
                             phone=data['phone'])

        # TODO: should we record this?
        ip_address = self.request.META.get(
            'HTTP_X_FORWARDED_FOR',
            self.request.META.get('REMOTE_ADDR', 'unknown address'))

        if data["volunteer"]:
            person.tags.add('volunteer')
            skills = data['skills']

            message = bleach.clean(data['anything_else'])
            if data["skill_other"]:
                other_skill = bleach.clean(data["skill_other_value"])
                # was going to make this another skill tag but don't want random users
                # adding tags
                message = 'otherskill: {0}\nmessage: {1}'.format(
                    other_skill, message)

            try:
                volunteer = VolunteerRequest.objects.get(
                    contact__email=person.email)
            except VolunteerRequest.DoesNotExist:
                volunteer = VolunteerRequest.objects.create(contact=person,
                                                            message=message)
            for skill in skills:
                volunteer.tags.add(skill)

        set_last_contact(self.request, person)
        return HttpResponseRedirect(reverse('extinctionr.info:thankyou'))
示例#7
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