Ejemplo n.º 1
0
def follow_instructor(request):
    if request.user.is_authenticated:
        this_user = functions.get_this_user(request)
        profile_model = functions.get_profile_model(this_user)
        if request.method == "POST":
            user_id = request.POST.get('user_id')
        else:
            return my_profile(request)

        try:
            instructor_user = User.objects.get(pk=user_id)
            temp_model = functions.get_profile_model(instructor_user)
            if temp_model != Instructor:
                messages.error(request, 'Du kan bara följa instruktörer.')
                return profile_with_user(request, user_id)
        except User.DoesNotExist:
            messages.error(request, 'Den här profilen existerar inte längre.')
            return profile_with_user(request, user_id)

        try:
            Follower.objects.get(instructor=instructor_user.instructor,
                                 follower=this_user)
            messages.error(
                request,
                'Du följer redan ' + instructor_user.instructor.first_name +
                ' ' + instructor_user.instructor.last_name + '.')
            return profile_with_user(request, user_id)
        except Follower.DoesNotExist:
            pass

        if profile_model == None:
            messages.error(request,
                           'Du är inte behörig att följa instruktörer.')
            return profile_with_user(request, user_id)
        else:
            profile_model.objects.get(user=this_user)
            if this_user == instructor_user:
                messages.error(request, 'Du kan inte följa dig själv.')
                return profile_with_user(request, user_id)
            else:
                Follower.objects.create(instructor=instructor_user.instructor,
                                        follower=this_user)
                messages.success(
                    request,
                    'Du följer nu ' + instructor_user.instructor.first_name +
                    ' ' + instructor_user.instructor.last_name)
                return profile_with_user(request, user_id)

    else:
        messages.error(request, 'Du måste vara inloggad')
        return profile_with_user(request, user_id)
Ejemplo n.º 2
0
def follow_instructor(request):
    if request.user.is_authenticated:
        this_user = functions.get_this_user(request)
        profile_model = functions.get_profile_model(this_user)
        if request.method == "POST":
            user_id = request.POST.get('user_id')
        else:
            return my_profile(request)

        try:
            instructor_user = User.objects.get(pk=user_id)
            temp_model = functions.get_profile_model(instructor_user)
            if temp_model != Instructor:
                messages.error(request, 'You can only follow instructors.')
                return profile_with_user(request, user_id)
        except User.DoesNotExist:
            messages.error(request, 'This profile no longer exists.')
            return profile_with_user(request, user_id)

        try:
            Follower.objects.get(instructor=instructor_user.instructor,
                                 follower=this_user)
            messages.error(
                request, 'You are already following ' +
                instructor_user.instructor.first_name + ' ' +
                instructor_user.instructor.last_name + '.')
            return profile_with_user(request, user_id)
        except Follower.DoesNotExist:
            pass

        if profile_model == None:
            messages.error(request,
                           'You are not authorized to follow this profile')
            return profile_with_user(request, user_id)
        else:
            profile_model.objects.get(user=this_user)
            if this_user == instructor_user:
                messages.error(request, 'You cannot follow yourself')
                return profile_with_user(request, user_id)
            else:
                Follower.objects.create(instructor=instructor_user.instructor,
                                        follower=this_user)
                messages.success(
                    request, 'You are now following ' +
                    instructor_user.instructor.first_name + ' ' +
                    instructor_user.instructor.last_name)
                return profile_with_user(request, user_id)

    else:
        messages.error(request, 'You have to be logged in')
        return profile_with_user(request, user_id)
Ejemplo n.º 3
0
def unfollow_instructor(request):
    if request.user.is_authenticated:
        this_user = functions.get_this_user(request)
        profile_model = functions.get_profile_model(this_user)
        if request.method == "POST":
            user_id = request.POST.get('user_id')
        else:
            return my_profile(request)

        try:
            instructor_user = User.objects.get(pk=user_id)
            temp_model = functions.get_profile_model(instructor_user)
            if temp_model != Instructor:
                messages.error(request, 'You can only unfollow users.')
                return profile_with_user(request, user_id)
        except User.DoesNotExist:
            messages.error(request, 'This profile no longer exists.')
            return profile_with_user(request, user_id)

        if profile_model == None:
            messages.error(request,
                           'You are not authorized to unfollow instructors.')
            return profile_with_user(request, user_id)
        else:
            profile_model.objects.get(user=this_user)
            if this_user == instructor_user:
                messages.error(request, 'You cannot unfollow yourself.')
                return profile_with_user(request, user_id)
            else:
                follow_objects = Follower.objects.filter(
                    instructor=instructor_user.instructor, follower=this_user)
                if len(follow_objects) == 0:
                    messages.error(request,
                                   'You are already not following this user.')
                    return profile_with_user(request, user_id)
                else:
                    for object in follow_objects:
                        object.delete()
                messages.info(
                    request, 'You have unfollowed ' +
                    instructor_user.instructor.first_name + ' ' +
                    instructor_user.instructor.last_name)
                return profile_with_user(request, user_id)

    else:
        messages.error(request, 'You have to be logged in.')
        return profile_with_user(request, user_id)
Ejemplo n.º 4
0
def unfollow_instructor(request):
    if request.user.is_authenticated:
        this_user = functions.get_this_user(request)
        profile_model = functions.get_profile_model(this_user)
        if request.method == "POST":
            user_id = request.POST.get('user_id')
        else:
            return my_profile(request)

        try:
            instructor_user = User.objects.get(pk=user_id)
            temp_model = functions.get_profile_model(instructor_user)
            if temp_model != Instructor:
                messages.error(request, 'Du kan bara avfölja instruktörer.')
                return profile_with_user(request, user_id)
        except User.DoesNotExist:
            messages.error(request, 'Den här profilen existerar inte längre.')
            return profile_with_user(request, user_id)

        if profile_model == None:
            messages.error(request,
                           'Du är inte behörig att avfölja instruktörer.')
            return profile_with_user(request, user_id)
        else:
            profile_model.objects.get(user=this_user)
            if this_user == instructor_user:
                messages.error(request, 'Du kan inte avfölja dig själv.')
                return profile_with_user(request, user_id)
            else:
                follow_objects = Follower.objects.filter(
                    instructor=instructor_user.instructor, follower=this_user)
                if len(follow_objects) == 0:
                    messages.error(
                        request, 'Du följer redan inte den här instruktören.')
                    return profile_with_user(request, user_id)
                else:
                    for object in follow_objects:
                        object.delete()
                messages.info(
                    request, 'Du har nu avföljt ' +
                    instructor_user.instructor.first_name + ' ' +
                    instructor_user.instructor.last_name)
                return profile_with_user(request, user_id)

    else:
        messages.error(request, 'Du måste vara inloggad')
        return profile_with_user(request, user_id)
Ejemplo n.º 5
0
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'
                  })
Ejemplo n.º 6
0
def send_instructor_message(request, user_id, hobby):
    try:
        instructor_user = User.objects.get(pk=user_id)
    except User.DoesNotExist:
        messages.error(request, 'Den här profilen existerar inte längre')
        return profile_with_user_hobby(request, user_id, hobby)

    if request.user.is_authenticated:
        if request.method == "POST":
            message_text = request.POST.get('message_text')
            if len(message_text) > 2500:
                messages.error(
                    request,
                    'Ditt medddelande får inte vara längre än 2500 tecken')
                return profile_with_user_hobby(request, user_id, hobby)
            profile_model = functions.get_profile_model(request.user)
            if profile_model != None:
                profile = profile_model.objects.get(user=request.user)
                if instructor_user == profile.user:
                    messages.error(
                        request,
                        'Du kan inte skicka meddelanden till dig själv.')
                    return profile_with_user_hobby(request, user_id, hobby)
                message_object = InstructorMessage.objects.create(
                    to_user=instructor_user,
                    first_name=profile.first_name,
                    last_name=profile.last_name,
                    email=profile.email,
                    telephone=profile.telephone,
                    message=message_text)
                mail_subject, mail_message = compose_message(
                    profile, message_text)
                try:
                    send_mail(mail_subject, mail_message,
                              '*****@*****.**', [instructor_user.email])
                    message_objects.message_sent = True
                    message_objects.save()
                except SMTPException:
                    messages.error(request,
                                   'Ditt meddelande kunde inte skickas iväg.')
                    return profile_with_user_hobby(request, user_id, hobby)
                messages.success(request,
                                 'Ditt meddelande har blivit skickat.')
                return profile_with_user_hobby(request, user_id, hobby)
            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, "Ditt meddelande skickades inte.")
            return profile_with_user_hobby(request, user_id, hobby)
    else:
        messages.error(request,
                       "Du måste vara inloggad för att skicka meddelanden.")
        return profile_with_user_hobby(request, user_id_hobby)
Ejemplo n.º 7
0
def send_instructor_message(request, user_id, hobby):
    try:
        instructor_user = User.objects.get(pk=user_id)
    except User.DoesNotExist:
        messages.error(request, 'This profile is inactive.')
        return profile_with_user_hobby(request, user_id, hobby)

    if request.user.is_authenticated:
        if request.method == "POST":
            message_text = request.POST.get('message_text')
            if len(message_text) > 2500:
                messages.error(request,
                               'Your message cannot exceed 2500 symbols.')
                return profile_with_user_hobby(request, user_id, hobby)
            profile_model = functions.get_profile_model(request.user)
            if profile_model != None:
                profile = profile_model.objects.get(user=request.user)
                if instructor_user == profile.user:
                    messages.error(request,
                                   'You cannot send messages to yourself.')
                    return profile_with_user_hobby(request, user_id, hobby)
                message_object = InstructorMessage.objects.create(
                    to_user=instructor_user,
                    first_name=profile.first_name,
                    last_name=profile.last_name,
                    email=profile.email,
                    telephone=profile.telephone,
                    message=message_text)
                mail_subject, mail_message = compose_message(
                    profile, message_text)
                try:
                    send_mail(mail_subject, mail_message,
                              '*****@*****.**', [instructor_user.email])
                    message_objects.message_sent = True
                    message_objects.save()
                except SMTPException:
                    messages.error(request, 'Your message could not be sent.')
                    return profile_with_user_hobby(request, user_id, hobby)
                messages.success(request,
                                 'Ditt meddelande har blivit skickat.')
                return profile_with_user_hobby(request, user_id, hobby)
            else:
                messages.error(
                    request,
                    'Something went wrong, contact us and we will help you.')
                return logout(request)
        else:
            messages.error(request, "Your message could not be sent.")
            return profile_with_user_hobby(request, user_id, hobby)
    else:
        messages.error(request, "You have to be logged in to send messages.")
        return profile_with_user_hobby(request, user_id_hobby)
Ejemplo n.º 8
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,
                           '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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
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'
                  })