示例#1
0
def edit_event(request, event_id, event_slug, location_slug=None):
    location = get_object_or_404(Location, slug=location_slug)
    current_user = request.user
    other_users = User.objects.exclude(id=current_user.id)
    user_list = [u.username for u in other_users]
    event = Event.objects.get(id=event_id)
    if not (request.user.is_authenticated() and (request.user in event.organizers.all() or request.user in event.location.house_admins.all())):
        return HttpResponseRedirect("/")

    if request.method == 'POST':
        form = EventForm(request.POST, request.FILES, instance=event)
        if form.is_valid():
            event = form.save(commit=False)
            co_organizers = form.cleaned_data.get('co_organizers')
            print co_organizers
            event.organizers.add(*co_organizers)
            event.save()
            messages.add_message(request, messages.INFO, 'The event has been saved.')
            return HttpResponseRedirect(reverse('gather_view_event', args=(event.location.slug, event.id, event.slug)))
        else:
            print "form error"
            print form.errors

    else:
        # format the organizers as a string for use with the autocomplete field
        other_organizers = event.organizers.exclude(id=current_user.id)
        other_organizer_usernames = [u.username for u in other_organizers]
        other_organizer_usernames_string = ",".join(other_organizer_usernames)
        print event.organizers.all()
        form = EventForm(instance=event, initial={'co_organizers': other_organizer_usernames_string})
    return render(request, 'gather_event_edit.html', {'form': form, 'current_user': current_user, 'event_id': event_id, 'event_slug': event_slug, 'user_list': json.dumps(user_list), 'location': location})
示例#2
0
def edit_event(request, event_id, event_slug, location_slug=None):
	location = get_object_or_404(Location, slug=location_slug)
	current_user = request.user
	other_users = User.objects.exclude(id=current_user.id)
	user_list = [u.username for u in other_users]
	event = Event.objects.get(id=event_id)
	if not (request.user.is_authenticated() and (request.user in event.organizers.all() or request.user in event.location.house_admins.all())):
		return HttpResponseRedirect("/")

	if request.method == 'POST':
		form = EventForm(request.POST, request.FILES, instance=event)
		if form.is_valid():
			event = form.save(commit=False)
			co_organizers = form.cleaned_data.get('co_organizers')
			print co_organizers
			event.organizers.add(*co_organizers)
			event.save()
			messages.add_message(request, messages.INFO, 'The event has been saved.')
			return HttpResponseRedirect(reverse('gather_view_event', args=(event.location.slug, event.id, event.slug)))
		else:
			print "form error"
			print form.errors

	else:
		# format the organizers as a string for use with the autocomplete field
		other_organizers = event.organizers.exclude(id=current_user.id)
		other_organizer_usernames = [u.username for u in other_organizers]
		other_organizer_usernames_string = ",".join(other_organizer_usernames)
		print event.organizers.all()
		form = EventForm(instance=event, initial={'co_organizers': other_organizer_usernames_string})
	return render(request, 'gather_event_edit.html', {'form': form, 'current_user': current_user, 'event_id': event_id, 'event_slug': event_slug, 'user_list': json.dumps(user_list), 'location': location})
示例#3
0
def create_event(request, location_slug=None):
	location = get_location(location_slug)
	current_user = request.user
	# if the user doesn't have a proper profile, then make sure they extend it first
	# TODO FIXME This is a direct dependency on an external app (the core app where the UserProfile model lives) 
	print current_user.id
	if current_user.id == None :
		messages.add_message(request, messages.INFO, 'We want to know who you are! Please create a profile before submitting an event.')
		return HttpResponseRedirect('/people/register/?next=/events/create/')
	elif current_user.is_authenticated and ((not current_user.profile.bio) or (not current_user.profile.image)):
		messages.add_message(request, messages.INFO, 'We want to know a bit more about you! Please complete your profile before submitting an event.')
		return HttpResponseRedirect('/people/%s/edit/' % current_user.username)

	other_users = User.objects.exclude(id=current_user.id)
	# get a list of users so that those creating an event can select from
	# existing users as event co-organizers
	user_list = [u.username for u in other_users]
	location_admin_group = EventAdminGroup.objects.get(location=location)
	if current_user in location_admin_group.users.all():
		is_event_admin = True
	else:
		is_event_admin = False

	if request.method == 'POST':
		print request.POST
		form = EventForm(request.POST, request.FILES)
		if form.is_valid():
			event = form.save(commit=False)
			event.creator = current_user
			# associate this event with a specific location and admin group
			event.location = location
			event.admin = location_admin_group
			event.save()
			co_organizers = form.cleaned_data.get('co_organizers')
			# always make sure current user is an organizer
			event.organizers.add(current_user)
			event.organizers.add(*co_organizers)
			# organizers should be attendees by default, too. 
			event.attendees.add(current_user)
			event.save()

			new_event_notification(event)

			messages.add_message(request, messages.INFO, 'The event has been created.')
			try:
				resp = HttpResponseRedirect(reverse('gather_view_event', args=(location_slug, event.id, event.slug)))
			except:
				resp = HttpResponseRedirect(reverse('gather_view_event', args=(event.id, event.slug)))
			return resp
		else:
			print "form error"
			print form.errors

	else:
		form = EventForm()
	return render(request, 'gather_event_create.html', {'form': form, 'current_user': current_user, 'user_list': json.dumps(user_list), 'is_event_admin': is_event_admin, 'location': location})
示例#4
0
def create_event(request, location_slug=None):
    location = get_object_or_404(Location, slug=location_slug)
    current_user = request.user
    logger.debug("create_event: location:%s, user:%s" % (location, current_user))

    # if the user doesn't have a proper profile, then make sure they extend it first
    print current_user.id
    if current_user.id == None :
        messages.add_message(request, messages.INFO, 'We want to know who you are! Please create a profile before submitting an event.')
        next_url = '/locations/%s/events/create/' % location.slug
        return HttpResponseRedirect('/people/register/?next=%s' % next_url)
    elif current_user.is_authenticated and ((not current_user.profile.bio) or (not current_user.profile.image)):
        messages.add_message(request, messages.INFO, 'We want to know a bit more about you! Please complete your profile before submitting an event.')
        return HttpResponseRedirect('/people/%s/edit/' % current_user.username)

    other_users = User.objects.exclude(id=current_user.id)
    # get a list of users so that those creating an event can select from
    # existing users as event co-organizers
    user_list = [u.username for u in other_users]
    location_admin_group = EventAdminGroup.objects.get(location=location)
    if current_user in location_admin_group.users.all():
        is_event_admin = True
    else:
        is_event_admin = False

    if request.method == 'POST':
        logger.debug("create_event: POST=%s" % request.POST)
        form = EventForm(request.POST, request.FILES)
        if form.is_valid():
            event = form.save(commit=False)
            event.creator = current_user
            # associate this event with a specific location and admin group
            event.location = location
            event.admin = location_admin_group
            event.save()
            co_organizers = form.cleaned_data.get('co_organizers')
            # always make sure current user is an organizer
            event.organizers.add(current_user)
            event.organizers.add(*co_organizers)
            # organizers should be attendees by default, too.
            event.attendees.add(current_user)
            event.save()

            new_event_notification(event, location)

            messages.add_message(request, messages.INFO, 'The event has been created.')
            return HttpResponseRedirect(reverse('gather_view_event', args=(event.location.slug, event.id, event.slug)))
        else:
            print "form error"
            print form
            print form.errors

    else:
        form = EventForm()
    return render(request, 'gather_event_create.html', {'form': form, 'current_user': current_user, 'user_list': json.dumps(user_list), 'is_event_admin': is_event_admin, 'location': location})