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)
def my_profile(request): ## User is redirected here upon LOGIN this_user = functions.get_this_user(request) if this_user != None: status = functions.check_user_valid_profile(request) if status == 'not_valid': request.method = "GET" messages.info( request, 'There is still missing necessary information before you to get started.' ) return edit_profile(request) elif status == 'not_active': messages.error( request, 'Your account is inactive, contact [email protected] for help or more information.' ) return logout(request) else: if functions.is_instructor(request) or functions.is_customer( request): return profile_with_user(request, this_user.id) else: messages.error( request, 'Something went really wrong, contact [email protected] and we will help you.' ) return logout(request) else: messages.error(request, 'You are not logged in.') return redirect('account_login')
def my_profile(request): ## User is redirected here upon LOGIN this_user = functions.get_this_user(request) if this_user != None: 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) else: if functions.is_instructor(request) or functions.is_customer( request): return profile_with_user(request, this_user.id) else: messages.error( request, 'Något gick väldigt fel kontakta [email protected] så hjälper vi dig' ) return logout(request) else: messages.error(request, 'Du är inte inloggad') return redirect('account_login')
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' })
def profile_with_user(request, user_id): if request.user.is_authenticated: status = functions.check_user_valid_profile(request) if status == 'not_valid': request.method = "GET" messages.info( request, 'There is still missing necessary information before you to get started..' ) return edit_profile(request) elif status == 'not_active': messages.error( request, 'Your account is inactive, contact [email protected] for help or more information.' ) return logout(request) this_user = functions.get_this_user(request) try: user = User.objects.get(pk=user_id) except User.DoesNotExist: messages.error(request, 'This profile no longer exists.') return render(request, 'profile_page.html', context={ 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' }) profile_model = functions.get_profile_model(user) try: profile = profile_model.objects.get(user=user) except profile_model.DoesNotExist: messages.error(request, 'This profile no longer exists.') return render(request, 'profile_page.html', context={ 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' }) if profile.is_active == False: messages.error(request, 'This profile is inactive.') return render(request, 'profile_page.html', context={ 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' }) return render(request, 'profile_page.html', context={ 'profile': profile, 'this_user': this_user, 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' })
def index(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) hobbies = Hobby.objects.all() if len(hobbies) == 0: hobbies = None else: hobby_event_dictionary = {} hobby_instructor_dictionary = {} for hobby in hobbies: hobby_events = HobbyEvent.objects.filter(hobby=hobby, is_active=True, is_accepted=True, is_hidden=False) hobby_events = [ event for event in hobby_events if event.has_happened == False ] instructors = Instructor.objects.filter(hobbies=hobby, valid_profile=True, is_private_instructor=True, is_active=True) hobby_event_dictionary[hobby.hobby_name] = hobby_events hobby_instructor_dictionary[hobby.hobby_name] = instructors return render(request, 'landing_page.html', context={ 'hobbies': hobbies, 'hobby_event_dictionary': hobby_event_dictionary, 'hobby_instructor_dictionary': hobby_instructor_dictionary })
def index(request): if request.user.is_authenticated: status = functions.check_user_valid_profile(request) if status == 'not_valid': request.method = "GET" messages.info( request, 'There is still missing necessary information before you to get started.' ) return edit_profile(request) elif status == 'not_active': messages.error( request, 'Your account is inactive, contact [email protected] for help or more information.' ) return logout(request) hobbies = Hobby.objects.all() hobby_event_dictionary = {} if len(hobbies) == 0: hobbies = None else: hobby_event_dictionary = {} for hobby in hobbies: hobby_events = HobbyEvent.objects.filter(hobby=hobby, is_active=True, is_accepted=True, is_hidden=False) hobby_events = [ event for event in hobby_events if event.has_happened == False ] hobby_event_dictionary[hobby.hobby_name] = hobby_events return render(request, 'landing_page.html', context={ 'hobbies': hobbies, 'hobby_event_dictionary': hobby_event_dictionary })
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)
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 })
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)
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)
def profile_with_user_hobby(request, user_id, hobby): 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) try: profile_user = User.objects.get(pk=user_id) except User.DoesNotExist: messages.error(request, 'Den här profilen existerar inte längre') return render(request, 'profile_page.html', context={ 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' }) try: instructor = Instructor.objects.get(user=profile_user) except Instructor.DoesNotExist: messages.error(request, 'Den här profilen existerar inte längre') return render(request, 'profile_page.html', context={ 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' }) try: hobby = Hobby.objects.get(hobby_name=hobby) except Hobby.DoesNotExist: return profile_with_user(request, user_id) this_user = functions.get_this_user(request) VisitInstructor.objects.create(user=this_user, instructor=instructor, hobby=hobby) hobby_list = Hobby.objects.filter(instructor=instructor) if hobby not in hobby_list: return profile_with_user(request, user_id) if len( Follower.objects.filter(instructor=profile_user.instructor, follower=this_user)) > 0: following = True else: following = False followers = len( Follower.objects.filter(instructor=profile_user.instructor)) return render(request, 'profile_page.html', context={ 'hobby': hobby, 'profile': instructor, 'this_user': this_user, 'profile_user': profile_user, 'following': following, 'followers': followers, 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' })
def profile_with_user(request, user_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: user = User.objects.get(pk=user_id) except User.DoesNotExist: messages.error(request, 'Den här profilen existerar inte längre.') return render(request, 'profile_page.html', context={ 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' }) profile_model = functions.get_profile_model(user) try: profile = profile_model.objects.get(user=user) except profile_model.DoesNotExist: messages.error(request, 'Den här profilen existerar inte längre.') return render(request, 'profile_page.html', context={ 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' }) if profile.is_active == False: messages.error(request, 'Den här profilen är avaktiverad.') return render(request, 'profile_page.html', context={ 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' }) if profile_model == Instructor: hobby_list = Hobby.objects.filter(instructor=profile) if len(hobby_list) == 1: return profile_with_user_hobby(request, user_id, hobby_list[0]) else: hobby_list = [] return render(request, 'profile_page.html', context={ 'hobby_list': hobby_list, 'profile': profile, 'this_user': this_user, 'spam_uri': 'https://www.spelapaintball.com/#wpcf7-f2197-o1' })