Beispiel #1
0
def new_user_email_signup(request, location_slug=None):
	if not request.method == 'POST':
		return HttpResponseRedirect('/404')
	print request.POST

	location = get_location(location_slug)
	# create new user
	form = NewUserForm(request.POST)
	if form.is_valid():
		new_user = form.save()
		new_user.save()
		notifications = new_user.event_notifications
		notifications.location_weekly.add(location)
		notifications.save()

		password = request.POST.get('password1')
		new_user = authenticate(username=new_user.username, password=password)
		login(request, new_user)
		messages.add_message(request, messages.INFO, 'Thanks! We\'ll send you weekly event updates for this location. You can update your preferences at any time on your <a href="/people/%s">profile</a> page' % new_user.username)
		return HttpResponse(status=200)
	else:
		errors = json.dumps({"errors": form.errors})
		return HttpResponse(json.dumps(errors))

	return HttpResponse(status=500); 
Beispiel #2
0
def new_user_email_signup(request, location_slug=None):
    if not request.method == 'POST':
        return HttpResponseRedirect('/404')
    print request.POST

    location = get_location(location_slug)
    # create new user
    form = NewUserForm(request.POST)
    if form.is_valid():
        new_user = form.save()
        new_user.save()
        notifications = new_user.event_notifications
        notifications.location_weekly.add(location)
        notifications.save()

        password = request.POST.get('password1')
        new_user = authenticate(username=new_user.username, password=password)
        login(request, new_user)
        messages.add_message(
            request, messages.INFO,
            'Thanks! We\'ll send you weekly event updates for this location. You can update your preferences at any time on your <a href="/people/%s">profile</a> page'
            % new_user.username)
        return HttpResponse(status=200)
    else:
        errors = json.dumps({"errors": form.errors})
        return HttpResponse(json.dumps(errors))

    return HttpResponse(status=500)
Beispiel #3
0
def rsvp_new_user(request, event_id, event_slug, location_slug=None):
	location = get_object_or_404(Location, slug=location_slug)
	if not request.method == 'POST':
		return HttpResponseRedirect('/404')

	print 'in rsvp_new_user'
	print request.POST
	# get email signup info and remove from form, since we tacked this field on
	# but it's not part of the user model. 
	weekly_updates = request.POST.get('weekly-email-notifications')
	notify_new = request.POST.get('new-event-notifications')
	if weekly_updates == 'on':
		weekly_updates = True
	else:
		weekly_updates = False
	print 'weekly updates?'
	print weekly_updates
	if notify_new == 'on':
		notify_new = True
	else:
		notify_new = False

	# create new user
	form = NewUserForm(request.POST)
	if form.is_valid():
		new_user = form.save()
		new_user.save()
		notifications = new_user.event_notifications
		if weekly_updates:
			# since the signup was related to a specific location we assume
			# they wanted weekly emails about the same location
			notifications.location_weekly.add(location)
		if notify_new:
			# since the signup was related to a specific location we assume
			# they wanted weekly emails about the same location
			notifications.location_publish.add(location)
		notifications.save()

		password = request.POST.get('password1')
		new_user = authenticate(username=new_user.username, password=password)
		login(request, new_user)
		# RSVP new user to the event
		event = Event.objects.get(id=event_id)
		event.attendees.add(new_user)
		print (event.attendees.all())
		event.save()
		messages.add_message(request, messages.INFO, 'Thanks! Your account has been created. Check your email for login info and how to update your preferences.')
		return HttpResponse(status=200)
	else:
		errors = json.dumps({"errors": form.errors})
		return HttpResponse(json.dumps(errors))

	return HttpResponse(status=500); 
Beispiel #4
0
def rsvp_new_user(request, event_id, event_slug, location_slug=None):
    location = get_location(location_slug)
    if not request.method == 'POST':
        return HttpResponseRedirect('/404')

    print 'in rsvp_new_user'
    print request.POST
    # get email signup info and remove from form, since we tacked this field on
    # but it's not part of the user model.
    weekly_updates = request.POST.get('email-notifications')
    if weekly_updates == 'on':
        weekly_updates = True
    else:
        weekly_updates = False
    print 'weekly updates?'
    print weekly_updates

    # create new user
    form = NewUserForm(request.POST)
    if form.is_valid():
        new_user = form.save()
        new_user.save()
        notifications = new_user.event_notifications
        if weekly_updates:
            # since the signup was related to a specific location we assume
            # they wanted weekly emails about the same location
            notifications.location_weekly.add(location)
        notifications.save()

        password = request.POST.get('password1')
        new_user = authenticate(username=new_user.username, password=password)
        login(request, new_user)
        # RSVP new user to the event
        event = Event.objects.get(id=event_id)
        event.attendees.add(new_user)
        print(event.attendees.all())
        event.save()
        messages.add_message(
            request, messages.INFO,
            'Thanks! Your account has been created. Check your email for login info and how to update your preferences.'
        )
        return HttpResponse(status=200)
    else:
        errors = json.dumps({"errors": form.errors})
        return HttpResponse(json.dumps(errors))

    return HttpResponse(status=500)
Beispiel #5
0
def view_event(request, event_id, event_slug, location_slug=None):
    # XXX should we double check the associated location here? currently the
    # assumption is that if an event is being viewed under a specific location
    # that that will be reflected in the URL path.
    try:
        event = Event.objects.get(id=event_id)
    except:
        print 'event not found'
        return HttpResponseRedirect('/404')

    location = get_location(location_slug)
    # if the slug has changed, redirect the viewer to the correct url (one
    # where the url matches the current slug)
    if event.slug != event_slug:
        print 'event slug has changed'
        # there's some tomfoolery here since we don't know for sure if the app
        # is being used in a project that specifies the location as part of the
        # url. probably a better way to do this...
        return HttpResponseRedirect(
            reverse('gather_view_event',
                    args=(event.location.slug, event.id, event.slug)))

    # is the event in the past?
    today = timezone.now()
    print event.end
    if event.end < today:
        past = True
    else:
        past = False

    # set up for those without accounts to RSVP
    if request.user.is_authenticated():
        current_user = request.user
        new_user_form = None
        login_form = None
        location_event_admin = EventAdminGroup.objects.get(location=location)
        if request.user in location_event_admin.users.all():
            user_is_event_admin = True
        else:
            user_is_event_admin = False
    else:
        current_user = None
        new_user_form = NewUserForm()
        login_form = AuthenticationForm()
        user_is_event_admin = False

    # this is counter-intuitive - private events are viewable to those who have
    # the link. so private events are indeed shown to anyone (once they are approved).
    if (event.status == 'live'
            and event.private) or event.is_viewable(current_user):
        if current_user and current_user in event.organizers.get_query_set():
            user_is_organizer = True
        else:
            user_is_organizer = False
        num_attendees = len(event.attendees.all())
        # only meaningful if event.limit > 0
        spots_remaining = event.limit - num_attendees
        event_email = 'event%d@%s.%s' % (event.id, event.location.slug,
                                         settings.LIST_DOMAIN)
        domain = Site.objects.get_current().domain
        return render(
            request, 'gather_event_view.html', {
                'event': event,
                'current_user': current_user,
                'user_is_organizer': user_is_organizer,
                'new_user_form': new_user_form,
                "event_email": event_email,
                "domain": domain,
                'login_form': login_form,
                "spots_remaining": spots_remaining,
                'user_is_event_admin': user_is_event_admin,
                "num_attendees": num_attendees,
                'in_the_past': past,
                'endorsements': event.endorsements.all(),
                'location': location
            })

    else:
        return HttpResponseRedirect('/404')