예제 #1
0
파일: views.py 프로젝트: MaxHXie/Q1
def index(request):
    if request.user.is_authenticated:
        status = functions.user_status(request)
        if status == 'not valid':
            request.method = "GET"
            message = "There are still missing information about you."
            return edit_profile(request)
        elif status == 'not activated':
            message = "Your account have not been activated."
            return logout(request)

    # Get all genres and events and present them on the landing page with a pre-programmed way of sorting / prioritizing.
    genres = Genre.objects.all()
    event_dict = {}
    artist_dict = {}

    if len(genres) == 0:
        genres = None

    else:
        for genre in genres:
            events = Event.objects.filter(genre=genre, is_active=True, is_confirmed=True, is_hidden=False)
            events = [event for event in events if event.has_happened == False]
            artists = Artist.objects.filter(genres=genre, valid_profile=True, is_active=True)
            event_dict[genre.name] = events
            artist_dict[genre.name] = artists

    return render(request, 'landing_page.html', context={'genres': genres, 'event_dict': event_dict, 'artist_dict': artist_dict})
예제 #2
0
파일: views.py 프로젝트: MaxHXie/Q1
def my_events(request):
    if request.user.is_authenticated:
        status = functions.user_status(request)
        if status == "not valid":
            request.method = "GET"
            message = "There is still information missing about you."
            return edit_profile(request)
        elif status == "not activated":
            message = "Your account is not activated."
            return logout(request)

    if functions.is_artist(request):
        artists_events = Event.objects.filter(artist=request.user.artist).order_by('-datetime')
        return render(request, 'my_events_page.html', context={'event_list': artists_events})
    else:
        message = "You are not logged in as an artist"
        return all_events(request)
예제 #3
0
파일: views.py 프로젝트: MaxHXie/Q1
def single(request, id):
    if request.user.is_authenticated:
        status = functions.user_status(request)
        if status == "not valid":
            request.method = "GET"
            message = "Your profile is not complete, there is still missing information."
            return edit_profile(request)
        elif status == 'not active':
            message = "Your account has not been activated"
            return logout(request)

    user = request.user

    try:
        event = Event.objects.get(pk=id)
    except Event.DoesNotExist:
        message = "The event you are looking for no longer exists"
        return all_events(request)

    try:
        Signup.objects.get(event=event, user=user, is_success=True)
        is_signed_up = True
    except Signup.DoesNotExist:
        is_signed_up = False

    if event.artist.user == user and event.is_confirmed == False:
        return confirm(request, id)

    if event.has_happened:
        message = "This event has already passed"
        return render(request, 'single_event_page.html', context={'event': event, 'user': user, 'is_signed_up': is_signed_up})

    if event.is_hidden:
        if user == event.artist.user:
            return render(request, 'single_event_page.html', context={'event': event, 'user': user, 'is_signed_up': is_signed_up})
        else:
            message = "This event is no longer visible"
            return all_events(request)

    #Check if this user already has signed up for the event or not

    return render(request, 'single_event_page.html', context={'event': event, 'user': user, 'is_signed_up': is_signed_up})
예제 #4
0
파일: views.py 프로젝트: MaxHXie/Q1
def edit(request, id):
    if request.user.is_authenticated:
        status = functions.user_status(request)
        if status == "not valid":
            request.method = "GET"
            message = "There is still information missing about you."
            return edit_profile(request)
        elif status == "not activated":
            message = "Your account is not activated."
            return logout(request)

    if functions.is_artist(request):
        try:
            event = Event.objects.get(pk=id)
        except Event.DoesNotExist:
            message = "Could not retrieve that event"

        artists_events = Event.objects.filter(artist=request.user.artist)
        if event in artists_events:
            if request.method == "POST":
                form = CreateEventForm(request.POST, instance=event)
                if form.is_valid():
                    form.save()
                    message = "Your event %s has now been edited" % (event.name)
                    request.method = "GET"
                    return single(request, event.id)

                else:
                    message = "Your event could not be edited. Double check it."
                    request.method = "GET"
                    form = CreateEventForm(instance=event)
                    return render(request, 'create_event_page.html', context={'form': form, 'type': edit})
            else:
                form = CreateEventForm(instance=event)
                return render(request, 'create_event_page.html', context={'form': form, 'type':'edit'})
        else:
            message = "You do not have access to this event."
            return single(request, id)
    else:
        message = "You are not logged in as an artist"
        return single(request, id)
예제 #5
0
파일: views.py 프로젝트: MaxHXie/Q1
def create(request):
    if functions.is_artist(request):
        status = functions.user_status(request)
        if status == "not valid":
            request.method = "GET"
            message = "Your profile is not complete, you need to fill in more information."
            return edit_profile(request)
        elif status == "not activated":
            message = "You have not activated your profile."
            return logout(request)

        user = request.user
        if request.method == "POST":
            color = random.choice(colors)
            event = Event.objects.create(
                artist = user.artist,
                genre = user.artist.genres,
                is_active = True,
                is_confirmed = False,
                is_hidden = False,
                red = color[0],
                green = color[1],
                blue = color[2]
            )
            form = CreateEventForm(request.POST, instance=event)
            if form.is_valid():
                form.save()
                message = "Last step, double check all your information."
                request.method = "GET"
                return confirm(request, event.id)

            else:
                message = "Your event could not be created for some reason, double check it."
                return render(request, 'create_event.html', context={'form', form})
        else:
            form = CreateEventForm()
            return render(request, 'create_event_page.html', context={'form': form})
    else:
        message = "You are not logged in as an artist"
        return all_events(request)
예제 #6
0
def my_profile(request):
    '''
    Get and present the profile of the current user
    '''
    if request.user.is_authenticated:
        status = functions.user_status(request)
        if status == 'not valid':
            request.method = "GET"
            messages.error(request, 'There is still missing info about you.')
            return edit_profile(request)
        elif status == 'not activated':
            messages.error(request, 'Your account is not activated.')
            return logout(request)

        user = request.user

        if functions.is_artist(request) or functions.is_fan(request):
            return profile_id(request, user.id)
        else:
            messages.error(request, 'Something went wrong, please try again.')
            return logout(request)
    else:
        messages.error(request, 'You are not logged in')
        return redirect('account_login')
예제 #7
0
def profile_id(request, id):
    '''
    Get and present the profile of the user with a specific id

    id: Integer | Primary key used to find the user
    '''
    if request.user.is_authenticated:
        status = functions.user_status(request)
        if status == 'not valid':
            request.method = "GET"
            messages.error(request,
                           'There is still information missing about you.')
            return edit_profile(request)
        elif status == 'not active':
            messages.error(request, 'Your account has not been activated')
            return logout(request)

    this_user = request.user

    try:
        user = User.objects.get(pk=id)
    except User.DoesNotExist:
        messages.error(request, 'This profile no longer exists')
        return render(request, 'profile_page.html')

    if functions.is_artist(request):
        profile = Artist.objects.get(user=user)
        try:
            follow = Follow.objects.get(artist=profile, follower=this_user)
            following = True
        except Follow.DoesNotExist:
            following = False

        try:
            boost = Boost.objects.get(user=this_user, artist=profile)
            if boost.is_active == True:
                boosting = True
            else:
                boosting = False
        except Boost.DoesNotExist:
            boosting = False

    elif functions.is_fan(request):
        profile = Fan.objects.get(user=user)
    else:
        messages.error(request, 'This profile no longer exists.')
        return render(request, 'profile_page.html')

    followers = len(Follow.objects.filter(artist=profile))
    boosters = len(Boost.objects.filter(artist=profile))

    if profile.is_active == False:
        messages.error(request, 'This profile is no longer active')
        return render(request, 'profile_page.html')

    if functions.profile_type(user) == "artist":
        genre = Genre.objects.get(artist=profile)
    else:
        genre = []

    return render(request,
                  'profile_page.html',
                  context={
                      'genre': genre,
                      'profile': profile,
                      'this_user': this_user,
                      'following': following,
                      'followers': followers,
                      'boosting': boosting,
                      'boosters': boosters
                  })
예제 #8
0
파일: views.py 프로젝트: MaxHXie/Q1
def all_events(request):
    if request.user.is_authenticated:
        status = functions.user_status(request)
        if status == "not valid":
            request.method = "GET"
            message = "Your profile is not complete, there is still missing information."
            return edit_profile(request)
        elif status == 'not active':
            message = "Your account has not been activated"
            return logout(request)

    user = request.user

    search_text = request.GET.get('search')

    if search_text != None and search_text != "":
        Search.objects.create(user=user, search_text=search_text)

        '''
        event_list is all events that are valid.
        And if there is an artists that matches the search string, then we are
        displaying all the events by that artist as well.
        And if there are any genres that matches the search string, then we are
        displaying all the events in that genre.
        And matches the search string on either name, city, city_district or location_name.

        Search priority order: Genre, Artist, Other information
        '''
        all_events = Event.objects.filter(is_active=True, is_confirmed=True, is_hidden=False)

        #The code below sorts all events.
        try:
            genre = Genre.objects.get(name__iexact=search_text)
            genre_events = all_events.filter(genre=genre)
        except Genre.DoesNotExist:
            genre_events = Event.objects.none()
            genre = None

        try:
            artist = Artist.objects.get(name__iexact=search_text)
            artist_events = all_events.filter(artist=artist)
        except Artist.DoesNotExist:
            artist_events = Event.objects.none()

        other_info_events = all_events.filter(Q(name__icontains=search_text) | Q(city__icontains=search_text) | Q(city_district__icontains=search_text) | Q(location_name__icontains=search_text))

        '''
        Merge all lists together in the order of priority.
        Remove duplicate events.
        Remove all events that has happened.
        '''
        event_list = genre_events | artist_events | other_info_events
        event_list = event_list.distinct()

        if len(event_list) == 0:
            message = "We could not find any events for this search"
            request.method = "GET"

    else:
        event_list = Event.objects.filter(is_active=True, is_confirmed=True, is_hidden=False)
        genre = None

    return render(request, 'events_page.html', context={'event_list': event_list, 'search_text': search_text, 'genre': genre})