示例#1
0
def has_permission(feedback_relation, user):
    content_object = feedback_relation.content_object

    if isinstance(content_object, Event):
        return content_object in get_group_restricted_events(user)

    # If the object is not an event return false by default
    return False
示例#2
0
def past(request):
    if not has_access(request):
        raise PermissionDenied

    allowed_events = get_group_restricted_events(request.user, True)
    events = allowed_events.filter(
        event_start__lt=timezone.now().date()).order_by('-event_start')

    context = get_base_context(request)
    context['events'] = events

    return render(request, 'events/dashboard/index.html', context)
示例#3
0
def generate_json(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    # If this is not an attendance event, redirect to event with error
    if not event.attendance_event:
        messages.error(request, _("Dette er ikke et påmeldingsarrangement."))
        return redirect(event)

    # Check access
    if event not in get_group_restricted_events(request.user):
        messages.error(
            request,
            _('Du har ikke tilgang til listen for dette arrangementet. hei'))
        return redirect(event)

    attendee_unsorted = event.attendance_event.attending_attendees_qs
    attendee_sorted = sorted(attendee_unsorted,
                             key=lambda attendee: attendee.user.last_name)
    waiters = event.attendance_event.waitlist_qs
    reserve = event.attendance_event.reservees_qs
    # Goes though attendance, the waitlist and reservations, and adds them to a json file.
    attendees = []
    for a in attendee_sorted:
        attendees.append({
            "first_name": a.user.first_name,
            "last_name": a.user.last_name,
            "year": a.user.year,
            "phone_number": a.user.phone_number,
            "allergies": a.user.allergies
        })
    waitlist = []
    for w in waiters:
        waitlist.append({
            "first_name": w.user.first_name,
            "last_name": w.user.last_name,
            "year": w.user.year,
            "phone_number": w.user.phone_number
        })

    reservees = []
    for r in reserve:
        reservees.append({"name": r.name, "note": r.note})

    response = HttpResponse(content_type='application/json')
    response['Content-Disposition'] = 'attachment; filename="' + str(
        event.id) + '.json"'
    response.write(
        json.dumps({
            'Attendees': attendees,
            'Waitlist': waitlist,
            'Reservations': reservees
        }))

    return response
示例#4
0
def generate_pdf(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    # If this is not an attendance event, redirect to event with error
    if not event.attendance_event:
        messages.error(request, _("Dette er ikke et påmeldingsarrangement."))
        return redirect(event)

    if event.organizer and request.user.has_perm('events.change_event', obj=event) \
            or event in get_group_restricted_events(request.user):
        return EventPDF(event).render_pdf()

    messages.error(
        request, _('Du har ikke tilgang til listen for dette arrangementet.'))
    return redirect(event)
示例#5
0
def generate_pdf(request, event_id):
    event = get_object_or_404(Event, pk=event_id)

    # If this is not an attendance event, redirect to event with error
    if not event.attendance_event:
        messages.error(request, _("Dette er ikke et påmeldingsarrangement."))
        return redirect(event)

    # Check access
    if event not in get_group_restricted_events(request.user):
        messages.error(
            request,
            _('Du har ikke tilgang til listen for dette arrangementet.'))
        return redirect(event)

    return EventPDF(event).render_pdf()
示例#6
0
def details(request, event_id, event_slug):
    event = get_object_or_404(Event, pk=event_id)

    # Restricts access to the event if it is group restricted
    if not event.can_display(request.user):
        messages.error(request, "Du har ikke tilgang til dette arrangementet.")
        return index(request)

    user_access_to_event = False
    if request.user:
        if event in get_group_restricted_events(request.user):
            user_access_to_event = True

    if request.method == 'POST':
        if request.is_ajax and 'action' in request.POST and 'extras_id' in request.POST:
            return JsonResponse(
                handle_event_ajax(event, request.user, request.POST['action'],
                                  request.POST['extras_id']))

    form = CaptchaForm(user=request.user)
    context = {
        'captcha_form':
        form,
        'event':
        event,
        'ics_path':
        request.build_absolute_uri(reverse('event_ics', args=(event.id, ))),
        'user_access_to_event':
        user_access_to_event,
    }

    if event.is_attendance_event():
        try:
            payment = Payment.objects.get(
                content_type=ContentType.objects.get_for_model(
                    AttendanceEvent),
                object_id=event_id)
        except Payment.DoesNotExist:
            payment = None

        context = handle_attendance_event_detail(event, request.user, context)
        if payment:
            request.session['payment_id'] = payment.id
            context = handle_event_payment(event, request.user, payment,
                                           context)

    return render(request, 'events/details.html', context)
示例#7
0
def mail_participants(request, event_id):
    event = get_object_or_404(Event, pk=event_id)

    # If this is not an attendance event, redirect to event with error
    if not event.attendance_event:
        messages.error(request, _("Dette er ikke et påmeldingsarrangement."))
        return redirect(event)

    # Check access
    if event not in get_group_restricted_events(request.user):
        messages.error(request,
                       _('Du har ikke tilgang til å vise denne siden.'))
        return redirect(event)

    all_attendees = list(event.attendance_event.attendees_qs)
    attendees_on_waitlist = list(event.attendance_event.waitlist_qs)
    attendees_not_paid = list(event.attendance_event.attendees_not_paid)

    if request.method == 'POST':
        subject = request.POST.get('subject')
        message = request.POST.get('message')

        mail_sent = handle_mail_participants(event,
                                             request.POST.get('from_email'),
                                             request.POST.get('to_email'),
                                             subject, message, all_attendees,
                                             attendees_on_waitlist,
                                             attendees_not_paid)

        if mail_sent:
            messages.success(request, _('Mailen ble sendt'))
        else:
            messages.error(
                request, _('Vi klarte ikke å sende mailene dine. Prøv igjen'))

    return render(
        request, 'events/mail_participants.html', {
            'all_attendees': all_attendees,
            'attendees_on_waitlist': attendees_on_waitlist,
            'attendees_not_paid': attendees_not_paid,
            'event': event
        })
示例#8
0
def get_group_restricted_feedback_relations(user):
    events = get_group_restricted_events(user, True)

    return FeedbackRelation.objects.filter(
        object_id__in=events,
        content_type=ContentType.objects.get(model="event"))