def edit_event(request, event_id):
    event = get_event_by_id(event_id)
    user = request.user
    initial = get_initial_data(event)
    initial['user_email'] = request.user.email

    event_data = {}

    if request.method == 'POST':
        event_form = AddEventForm(data=request.POST, files=request.FILES)
    else:
        event_form = AddEventForm(initial=initial)

    existing_picture = event.picture

    if event_form.is_valid():
        # picture_check works with jasny bootstrap magix
        picture_check = request.POST.get('picture')
        picture = request.FILES.get('picture', None)
        event_data = event_form.cleaned_data
        event_data['creator'] = request.user

        # checking if user entered a different email than in her profile
        if user.email != event_data['user_email']:
            update_user_email(user.id, event_data['user_email'])
        event_data.pop('user_email')

        try:
            if picture:
                if picture.size > (256 * 1024):
                    raise ImageSizeTooLargeException('Image size too large.')
                event_data['picture'] = process_image(picture)
            elif picture_check == "nochange":
                event_data['picture'] = existing_picture
            else:
                del event_data['picture']

            create_or_update_event(event_id, **event_data)

            return HttpResponseRedirect(
                reverse(
                    'web.view_event',
                    kwargs={
                        'event_id': event.id,
                        'slug': event.slug}))

        except ImageSizeTooLargeException:
            messages.error(
                request, 'The image is just a bit too big for us (must be up to 256 kb). '
                'Please reduce your image size and try agin.')
        except UploadImageError as e:
            messages.error(request, e.message)

    return render_to_response(
        'pages/add_event.html', {
            'form': event_form,
            'address': event_data.get('location', None),
            'editing': True,
            'picture_url': event.picture,
        }, context_instance=RequestContext(request))
Exemple #2
0
def add_event(request):
	event_form = AddEventForm()

	if request.method == 'POST':
		event_form = AddEventForm(data=request.POST, files=request.FILES)

	if event_form.is_valid():
		picture = request.FILES.get('picture', None)
		event_data = {}
		try:
			if picture:
				if picture.size > (256 * 1024):
					raise ImageSizeTooLargeException('Image size too large.')

				event_data['picture'] = process_image(picture)

			event_data.update(event_form.cleaned_data)
			event_data['creator'] = request.user
			event = create_or_update_event(**event_data)

			t = loader.get_template('alerts/thank_you.html')
			c = Context({'event': event, })
			messages.info(request, t.render(c))

			return HttpResponseRedirect(reverse('web.view_event', args=[event.pk, event.slug]))

		except ImageSizeTooLargeException:
			messages.error(request, 'The image is just a bit too big for us. '
			                        'Please reduce your image size and try agin.')
		except UploadImageError as e:
			messages.error(request, e.message)

	return render_to_response("pages/add_event.html", {
		'form': event_form,
	}, context_instance=RequestContext(request))
Exemple #3
0
def edit_event(request, event_id):
    event = get_event_by_id(event_id)
    user = request.user
    initial = get_initial_data(event)
    initial["user_email"] = request.user.email

    event_data = {}

    if request.method == "POST":
        event_form = AddEventForm(data=request.POST, files=request.FILES)
    else:
        event_form = AddEventForm(initial=initial)

    existing_picture = event.picture

    if event_form.is_valid():
        # picture_check works with jasny bootstrap magix
        picture_check = request.POST.get("picture")
        picture = request.FILES.get("picture", None)
        event_data = event_form.cleaned_data
        event_data["creator"] = request.user

        # checking if user entered a different email than in her profile
        if user.email != event_data["user_email"]:
            update_user_email(user.id, event_data["user_email"])
        event_data.pop("user_email")

        try:
            if picture:
                if picture.size > (256 * 1024):
                    raise ImageSizeTooLargeException("Image size too large.")
                event_data["picture"] = process_image(picture)
            elif picture_check == "nochange":
                event_data["picture"] = existing_picture
            else:
                del event_data["picture"]

            create_or_update_event(event_id, **event_data)

            return HttpResponseRedirect(reverse("web.view_event", kwargs={"event_id": event.id, "slug": event.slug}))

        except ImageSizeTooLargeException:
            messages.error(
                request,
                "The image is just a bit too big for us (must be up to 256 kb). "
                "Please reduce your image size and try agin.",
            )
        except UploadImageError as e:
            messages.error(request, e.message)

    return render_to_response(
        "pages/add_event.html",
        {
            "form": event_form,
            "address": event_data.get("location", None),
            "editing": True,
            "picture_url": event.picture,
        },
        context_instance=RequestContext(request),
    )
Exemple #4
0
def edit_event(request, event_id):
	event = get_event_by_id(event_id)
	initial = get_initial_data(event)

	event_data = {}

	if request.method == 'POST':
		event_form = AddEventForm(data=request.POST, files=request.FILES)
	else:
		event_form = AddEventForm(initial=initial)

	if event_form.is_valid():
		picture = request.FILES.get('picture', None)
		event_data = event_form.cleaned_data

		event_data['creator'] = request.user

		try:
			if picture:
				if picture.size > (256 * 1024):
					raise ImageSizeTooLargeException('Image size too large.')

				event_data['picture'] = process_image(picture)
			else:
				del event_data['picture']

			create_or_update_event(event_id, **event_data)

			return HttpResponseRedirect(reverse('web.view_event',
			                                    kwargs={'event_id': event.id, 'slug': event.slug}))

		except ImageSizeTooLargeException:
			messages.error(request, 'The image is just a bit too big for us (must be up to 256 kb). '
			                        'Please reduce your image size and try agin.')
		except UploadImageError as e:
			messages.error(request, e.message)
		
	return render_to_response(
		'pages/add_event.html', {
			'form': event_form,
			'address': event_data.get('location', None),
			'editing': True,
			'picture_url': event.picture,
		}, context_instance=RequestContext(request))
Exemple #5
0
def add_event(request):
    if request.method == "POST":
        event_form = AddEventForm(data=request.POST, files=request.FILES)

        if event_form.is_valid():
            picture = request.FILES.get("picture", None)
            event_data = {}
            try:
                if picture:
                    if picture.size > (256 * 1024):
                        raise ImageSizeTooLargeException("Image size too large.")

                    event_data["picture"] = process_image(picture)

                event_data.update(event_form.cleaned_data)
                event_data["creator"] = request.user

                # checking if user entered a different email than in her profile
                if request.user.email != event_data["user_email"]:
                    update_user_email(request.user.id, event_data["user_email"])
                event_data.pop("user_email")

                event = create_or_update_event(**event_data)

                t = loader.get_template("alerts/thank_you.html")
                c = Context({"event": event})
                messages.info(request, t.render(c))

                return HttpResponseRedirect(reverse("web.view_event", args=[event.pk, event.slug]))

            except ImageSizeTooLargeException:
                messages.error(
                    request, "The image is just a bit too big for us. " "Please reduce your image size and try agin."
                )
            except UploadImageError as e:
                messages.error(request, e.message)
    else:
        event_form = AddEventForm(initial={"user_email": request.user.email})

    return render_to_response("pages/add_event.html", {"form": event_form}, context_instance=RequestContext(request))