예제 #1
0
def my_events(request):
    if request.user.is_authenticated:
        status = functions.check_user_valid_profile(request)
        if status == 'not_valid':
            request.method = "GET"
            messages.info(
                request,
                'Det saknas fortfarande nödvändig information om dig. Fyll i dem för att komma igång.'
            )
            return edit_profile(request)
        elif status == 'not_active':
            messages.error(
                request,
                'Ditt konto är inte aktivt, kontakta [email protected] så hjälper vi dig.'
            )
            return logout(request)

    if functions.is_instructor(request):
        this_instructors_events = HobbyEvent.objects.filter(
            event_host=request.user.instructor).order_by('-datetime')
        return render(request,
                      'my_events_page.html',
                      context={'event_list': this_instructors_events})
    else:
        messages.error(request, 'Du är inte inloggad som instruktör.')
        return all_events(request)
예제 #2
0
def single_event(request, event_id):
    if request.user.is_authenticated:
        status = functions.check_user_valid_profile(request)
        if status == 'not_valid':
            request.method = "GET"
            messages.info(
                request,
                'Det saknas fortfarande nödvändig information om dig. Fyll i dem för att komma igång.'
            )
            return edit_profile(request)
        elif status == 'not_active':
            messages.error(
                request,
                'Ditt konto är inte aktivt, kontakta [email protected] så hjälper vi dig.'
            )
            return logout(request)

    this_user = functions.get_this_user(request)

    try:
        this_event = HobbyEvent.objects.get(pk=event_id)
    except HobbyEvent.DoesNotExist:
        messages.error(request, 'Det där evenemanget existerar inte längre.')
        return all_events(request)

    VisitHobbyEvent.objects.create(user=this_user, hobby_event=this_event)

    if this_event.event_host.user == this_user or (
            this_event.is_hidden == False and this_event.is_active == True
            and this_event.is_accepted == True
            and this_event.has_happened == False):
        if this_event.is_accepted == False:
            return create_event_terminal(request, this_event.id)
    else:
        if this_event.has_happened:
            messages.error(request, 'Det här evenemanget har passerat')
        else:
            messages.error(request,
                           'Det här evenemanget går inte längre att ses.')
        return all_events(request)

    try:
        HobbyEventSignup.objects.get(hobby_event=this_event,
                                     user=this_user,
                                     is_success=True)
        signed_up = True
    except HobbyEventSignup.DoesNotExist:
        signed_up = False

    return render(request,
                  'single_event_page.html',
                  context={
                      'this_event': this_event,
                      'this_user': this_user,
                      'signed_up': signed_up,
                      'spam_uri':
                      'https://www.spelapaintball.com/#wpcf7-f2197-o1'
                  })
예제 #3
0
파일: views.py 프로젝트: MaxHXie/hobbyin
def signup_for_event(request, event_id):
    if request.user.is_authenticated:
        try:
            this_event = HobbyEvent.objects.get(pk=event_id)
        except HobbyEvent.DoesNotExist:
            messages.error(request,
                           'Det där evenemanget existerar inte längre.')
            return all_events(request)

        try:
            HobbyEventSignup.objects.get(hobby_event=this_event,
                                         user=request.user)
            messages.error(
                request, 'Du har redan anmält dig till det här evenemanget.')
            return single_event(request, event_id)
        except HobbyEventSignup.DoesNotExist:
            profile_model = functions.get_profile_model(request.user)
            if profile_model != None:
                profile = profile_model.objects.get(user=request.user)
                if profile.user != this_event.event_host.user:
                    HobbyEventSignup.objects.create(
                        hobby_event=this_event,
                        user=request.user,
                        first_name=profile.first_name,
                        last_name=profile.last_name,
                        email=profile.email,
                        telephone=profile.telephone,
                        is_success=True)
                    messages.success(request,
                                     'Du är nu anmäld till evenemanget.')
                    return single_event(request, event_id)
                else:
                    messages.error(
                        request,
                        'Du kan inte anmäla dig till ditt egna evenemang.')
                    return single_event(request, event_id)
            else:
                messages.error(
                    request,
                    'Något gick fel. Kontakta oss på [email protected] så hjälper vi dig.'
                )
                return logout(request)
    else:
        messages.error(
            request, 'Du måste vara inloggad för att komma åt den här sidan.')
        return all_events(request)
예제 #4
0
def signup_for_event(request, event_id):
    if request.user.is_authenticated:
        try:
            this_event = HobbyEvent.objects.get(pk=event_id)
        except HobbyEvent.DoesNotExist:
            messages.error(request, 'This event no longer exists.')
            return all_events(request)

        try:
            HobbyEventSignup.objects.get(hobby_event=this_event,
                                         user=request.user)
            messages.error(request,
                           'You have already signed up for this event.')
            return single_event(request, event_id)
        except HobbyEventSignup.DoesNotExist:
            profile_model = functions.get_profile_model(request.user)
            if profile_model != None:
                profile = profile_model.objects.get(user=request.user)
                if profile.user != this_event.event_host.user:
                    HobbyEventSignup.objects.create(
                        hobby_event=this_event,
                        user=request.user,
                        first_name=profile.first_name,
                        last_name=profile.last_name,
                        email=profile.email,
                        telephone=profile.telephone,
                        is_success=True)
                    messages.success(request,
                                     'You have signed up to the event.')
                    return single_event(request, event_id)
                else:
                    messages.error(request,
                                   'You cannot signup to your own event.')
                    return single_event(request, event_id)
            else:
                messages.error(
                    request,
                    'Något gick fel. Kontakta oss på [email protected] så hjälper vi dig.'
                )
                return logout(request)
    else:
        messages.error(
            request, 'Du måste vara inloggad för att komma åt den här sidan.')
        return all_events(request)
예제 #5
0
def edit_event(request, event_id):
    if request.user.is_authenticated:
        status = functions.check_user_valid_profile(request)
        if status == 'not_valid':
            request.method = "GET"
            messages.info(
                request,
                'Det saknas fortfarande nödvändig information om dig. Fyll i dem för att komma igång.'
            )
            return edit_profile(request)
        elif status == 'not_active':
            messages.error(
                request,
                'Ditt konto är inte aktivt, kontakta [email protected] så hjälper vi dig.'
            )
            return logout(request)

    if functions.is_instructor(request):
        try:
            this_event = HobbyEvent.objects.get(pk=event_id)
        except HobbyEvent.DoesNotExist:
            messages.error(request, 'Där gick något snett, försök igen.')
            return create_events(request)

        this_instructors_events = HobbyEvent.objects.filter(
            event_host=request.user.instructor)
        if this_event in this_instructors_events:
            if request.method == "POST":
                form = CreateEventForm(request.POST, instance=this_event)
                if form.is_valid():
                    form.save()
                    messages.success(
                        request, 'Ditt evenemang: "' + this_event.event_name +
                        '" är nu ändrat.')
                    request.method = "GET"
                    return single_event(request, this_event.id)

                else:
                    messages.error(
                        request,
                        'Ditt evenemang kunde inte ändras. Dubbelkolla gärna så att allting är rätt.'
                    )
                    return render(
                        request,
                        'create_event_page.html',
                        context={
                            'form':
                            form,
                            'type':
                            'edit',
                            'spam_uri':
                            'https://www.spelapaintball.com/#wpcf7-f2197-o1'
                        })
            else:
                form = CreateEventForm(instance=this_event)
                return render(
                    request,
                    'create_event_page.html',
                    context={
                        'form':
                        form,
                        'type':
                        'edit',
                        'spam_uri':
                        'https://www.spelapaintball.com/#wpcf7-f2197-o1'
                    })
        else:
            messages.error(
                request,
                'Du har inte tillgång till det där evenmanget. Dubbelkolla så att du är inloggad på rätt konto.'
            )
            return single_event(request, event_id)
    else:
        messages.error(request, 'Du är inte inloggad som instruktör.')
        return all_events(request)
예제 #6
0
def all_events(request):
    """
    Filter and sort all events on five factors:
        1. is_active, is_accepted, is_hidden: Do not include events that does not meet these criteria.
        2. search_hobby_event: Filter away events that does not match the search string.
        3. event_id: Sort by having the most recent events first. (Secondary priority sort)
        4. event.has_happened: Do not include all events that already has happened.
        5. input_zip_code: Sort by having the closest events first. (Primary priority sort)
    """

    if request.user.is_authenticated:
        status = functions.check_user_valid_profile(request)
        if status == 'not_valid':
            request.method = "GET"
            messages.info(
                request,
                'Det saknas fortfarande nödvändig information om dig. Fyll i dem för att komma igång.'
            )
            return edit_profile(request)
        elif status == 'not_active':
            messages.error(
                request,
                'Ditt konto är inte aktivt, kontakta [email protected] så hjälper vi dig.'
            )
            return logout(request)

    this_user = functions.get_this_user(request)

    search_hobby_event = request.GET.get('search_hobby_event')
    input_zip_code = request.GET.get('input_zip_code')

    #Filter away events that does not match the search string.
    if search_hobby_event != None or input_zip_code != None:
        EventSearch.objects.create(user=this_user,
                                   search_string=search_hobby_event,
                                   zip_code_search=input_zip_code)

    if search_hobby_event != None and search_hobby_event != "":
        event_list1 = HobbyEvent.objects.filter(
            event_name__icontains=search_hobby_event,
            is_active=True,
            is_accepted=True,
            is_hidden=False)
        event_list3 = HobbyEvent.objects.filter(
            city__icontains=search_hobby_event,
            is_active=True,
            is_accepted=True,
            is_hidden=False)
        event_list4 = HobbyEvent.objects.filter(
            city_district__icontains=search_hobby_event,
            is_active=True,
            is_accepted=True,
            is_hidden=False)
        try:
            hobby = Hobby.objects.get(hobby_name__iexact=search_hobby_event)
            event_list2 = HobbyEvent.objects.filter(hobby=hobby,
                                                    is_active=True,
                                                    is_accepted=True,
                                                    is_hidden=False)
            temp_list = event_list1 | event_list2 | event_list3 | event_list4

        except Hobby.DoesNotExist:
            hobby = None
            event_list2 = None
            temp_list = event_list1 | event_list3 | event_list4

        event_list = temp_list.distinct()

        if len(event_list) == 0:
            messages.error(
                request,
                'Vi kunde inte hitta några evenemang för den här hobbyn.')
            request.method = "GET"

    else:
        hobby = None
        event_list = HobbyEvent.objects.filter(is_active=True,
                                               is_accepted=True,
                                               is_hidden=False)

    #Sort by having the most recent events first. (Secondary priority sort)
    event_list = event_list.order_by('-id')

    #Do not include events that already has happened
    event_list = [event for event in event_list if event.has_happened == False]

    worked, event_list, error = functions.sort_by_proximity(
        event_list, input_zip_code, request)
    if worked == False and error != None:
        messages.error(request, error)

    return render(request,
                  'all_events_page.html',
                  context={
                      'event_list': event_list,
                      'hobby': hobby,
                      'search_hobby_event': search_hobby_event,
                      'input_zip_code': input_zip_code
                  })
예제 #7
0
def create_event(request):
    if functions.is_instructor(request):
        status = functions.check_user_valid_profile(request)
        if status == 'not_valid':
            request.method = "GET"
            messages.info(
                request,
                'Necessary information is still missing, fill them in before getting started.'
            )
            return edit_profile(request)
        elif status == 'not_active':
            messages.error(
                request,
                'Your account is inactive, contact [email protected] and we will help you.'
            )
            return logout(request)

        current_user = request.user
        if request.method == "POST":
            event_object = HobbyEvent.objects.create(event_host=instructor,
                                                     hobby=instructor.hobbies,
                                                     is_active=True)
            color = random.choice(colors)
            event_object.event_color_red = color[0]
            event_object.event_color_green = color[1]
            event_object.event_color_blue = color[2]
            event_object.save()
            form = CreateEventForm(request.POST, instance=event_object)
            if form.is_valid():
                form.save()
                messages.info(
                    request,
                    'Last step, double check so that all information is correct.'
                )
                request.method = "GET"
                return create_event_terminal(request, event_object.id)

            else:
                messages.error(
                    request,
                    'Your event could not be created, double check so that everything is correct.'
                )
                return render(
                    request,
                    'create_event_page.html',
                    context={
                        'form':
                        form,
                        'type':
                        'create',
                        'spam_uri':
                        'https://www.spelapaintball.com/#wpcf7-f2197-o1'
                    })
        else:
            form = CreateEventForm()
            return render(request,
                          'create_event_page.html',
                          context={
                              'form':
                              form,
                              'type':
                              'create',
                              'spam_uri':
                              'https://www.spelapaintball.com/#wpcf7-f2197-o1'
                          })

    else:
        messages.error(request, 'You are not logged in.')
        return all_events(request)
예제 #8
0
파일: views.py 프로젝트: MaxHXie/hobbyin
def create_event(request):
    if functions.is_instructor(request):
        status = functions.check_user_valid_profile(request)
        if status == 'not_valid':
            request.method = "GET"
            messages.info(
                request,
                'Det saknas fortfarande nödvändig information om dig. Fyll i dem för att komma igång.'
            )
            return edit_profile(request)
        elif status == 'not_active':
            messages.error(
                request,
                'Ditt konto är inte aktivt, kontakta [email protected] så hjälper vi dig.'
            )
            return logout(request)

        current_user = request.user
        if request.method == "POST":
            event_object = HobbyEvent.objects.create(event_host=instructor,
                                                     hobby=instructor.hobbies,
                                                     is_active=True)
            color = random.choice(colors)
            event_object.event_color_red = color[0]
            event_object.event_color_green = color[1]
            event_object.event_color_blue = color[2]
            event_object.save()
            form = CreateEventForm(request.POST, instance=event_object)
            if form.is_valid():
                form.save()
                messages.info(
                    request,
                    'Sista steget, dubbelkolla så att all info är rätt.')
                request.method = "GET"
                return create_event_terminal(request, event_object.id)

            else:
                messages.error(
                    request,
                    'Ditt evenemang kunde inte skapas. Dubbelkolla gärna så att allting är rätt.'
                )
                return render(
                    request,
                    'create_event_page.html',
                    context={
                        'form':
                        form,
                        'type':
                        'create',
                        'spam_uri':
                        'https://www.spelapaintball.com/#wpcf7-f2197-o1'
                    })
        else:
            form = CreateEventForm()
            return render(request,
                          'create_event_page.html',
                          context={
                              'form':
                              form,
                              'type':
                              'create',
                              'spam_uri':
                              'https://www.spelapaintball.com/#wpcf7-f2197-o1'
                          })

    else:
        messages.error(request, 'Du är inte inloggad som instruktör.')
        return all_events(request)