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))
Beispiel #2
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),
    )
Beispiel #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)

    if event_form.is_valid():
        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)
            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))
Beispiel #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))
Beispiel #5
0
def report_event(request, event_id):
    event = get_event_by_id(event_id)
    user = request.user
    initial = get_initial_data(event)
    initial['name_for_certificate'] = event.organizer
    event_report_fields = OrderedDict()

    if request.method == 'POST':
        report_event_form = ReportEventForm(data=request.POST)
    else:
        report_event_form = ReportEventForm(initial=initial)

    if event.is_reporting_allowed():
        if report_event_form.is_valid():
            event_data = report_event_form.cleaned_data

            event.__dict__.update(event_data)
            event.reported_at = datetime.now()
            event.save()

            if generate_certificate_for(event.pk,
                                        event.certificate_file_name(),
                                        event.name_for_certificate):
                event.certificate_generated_at = datetime.now()
                event.save()

            return HttpResponseRedirect(
                reverse('web.view_event',
                        kwargs={
                            'event_id': event.id,
                            'slug': event.slug
                        }))
    else:
        for field_name, field in report_event_form.fields.items():
            event_report_fields[field.label] = initial[field_name]

    return render_to_response('pages/report_event.html', {
        'form': report_event_form,
        'event': event,
        'event_report_fields': event_report_fields,
    },
                              context_instance=RequestContext(request))
def report_event(request, event_id):
    event = get_event_by_id(event_id)
    user = request.user
    initial = get_initial_data(event)
    initial['name_for_certificate'] = event.organizer
    event_report_fields = OrderedDict()

    if request.method == 'POST':
        report_event_form = ReportEventForm(data=request.POST)
    else:
        report_event_form = ReportEventForm(initial=initial)

    if event.is_reporting_allowed():
        if report_event_form.is_valid():
            event_data = report_event_form.cleaned_data

            event.__dict__.update(event_data)
            event.reported_at = datetime.now()
            event.save()

            if generate_certificate_for(event.pk, event.certificate_file_name(), event.name_for_certificate):
                event.certificate_generated_at = datetime.now()
                event.save()

            return HttpResponseRedirect(
                reverse(
                    'web.view_event',
                    kwargs={
                        'event_id': event.id,
                        'slug': event.slug}))
    else:
        for field_name, field in report_event_form.fields.items():
            event_report_fields[field.label] = initial[field_name]

    return render_to_response(
        'pages/report_event.html', {
            'form': report_event_form,
            'event': event,
            'event_report_fields': event_report_fields,
        }, context_instance=RequestContext(request))