Example #1
0
File: views.py Project: MaxHXie/Q1
def confirm(request, id):
    if functions.is_artist(request):
        user = request.user
        try:
            event = Event.objects.get(pk=id)
        except Event.DoesNotExist:
            message = "We could not find that event, please try again."
            return create(request)

        if event.artist.user == user:
            if not event.is_confirmed:
                if request.method == "POST":
                    event.is_confirmed = True
                    event.save()
                    request.method = "GET"

                    message = "Your event has now been created!"
                    return single(request, id)

                else:
                    return render(request, 'event_terminal_page.html', context={'event': event})
            else:
                message = "You have already published this event."
                return single_event(request, id)
        else:
            message = "You do not have access this event."
            return create_event(request)
    else:
        message = "You are not logged in as an artist"
        return all_events(request)
Example #2
0
File: views.py Project: MaxHXie/Q1
def hide_show(request, id):
    if functions.is_artist(request):
        try:
            event = Event.objects.get(pk=id)
        except Event.DoesNotExist:
            message = "That event does not exist anymore"
            return all_events(request)

        artists_events = Event.objects.filter(artist=request.user.artist)

        if event in artists_events:
            if request.method == "POST":
                action = request.POST.get("action_type")
                if action == "show":
                    event.is_hidden = False
                    message = 'Your event "%s" is now recovered and visible' % (event.name)
                elif action == "hide":
                    event.is_hidden = True
                    message = 'Your event "%s" is now hidden' % (event.name)

                event.save()
                request.method = "GET"
                return single(request, id)

            else:
                message = 'We were unable to hide the event, please try again.'
                return single(request, id)
        else:
            message = 'You do not have access to this event.'
    else:
        message = 'You are not logged in as an artist.'
        return all_events(request)
Example #3
0
File: views.py Project: 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)
Example #4
0
File: views.py Project: MaxHXie/Q1
def participants(request, id):
    if functions.is_artist(request):
        try:
            event = Event.objects.get(pk=id)
        except:
            message = "This event no longer exists"
            return all_events(request)

        if event.artist == request.user.artist:
            return render(request, 'participants_page.html', context={'event': event})

        else:
            message = "You do not have access to this event."
            return all_events(request)

    else:
        message = "You are not logged in as an artist"
        return all_events(request)
Example #5
0
def edit_profile(request):
    '''
    Present edit profile form for both fans and artists
    '''

    user = functions.get_authenticated_user(request)

    if user != None:
        if functions.is_artist(request):
            form_type = ArtistForm
            form_obj = user.artist
        elif functions.is_fan(request):
            form_type = FanForm
            form_obj = user.fan
        else:
            return index(request)

        #If request method is POST, try to save the form data into the database
        if request.method == "POST":
            form = form_type(request.POST, request.FILES, instance=form_obj)
            if form.is_valid():
                form.save()
                form_obj.valid_profile = True
                form_obj.save()
                messages.success(request, 'Your profile has been saved')
                request.method = "GET"
                return my_profile(request)
            else:
                messages.error(request, 'Your profile was not changed')
                return render(request,
                              'edit_profile_page.html',
                              context={'form': form})
        #If it is not POST, generate a new form with all the infromation already in the form
        else:
            form = form_type(None, instance=form_obj)
            return render(request,
                          'edit_profile_page.html',
                          context={'form': form})

    else:
        messages.error(request, 'You are not logged in')
        return redirect('account_login')
Example #6
0
File: views.py Project: 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)
Example #7
0
File: views.py Project: 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)
Example #8
0
def data(request):
    # Get followers
    # Get number of events
    if functions.is_artist(request):
        user = request.user
        artist = user.artist
        number_of_followers = len(Follow.objects.filter(artist=artist))
        number_of_events = len(Event.objects.filter(artist=artist))
        # number_of_boosts = len(Boost.objects.filter(artist=artist))
        # number_of_visitors = len(Visit.objects.filter(artist=artist))
        # number_of_donations = len(Donate.objects.filter(artist=artist))

        # Remember to include future context
        return render(
            request, 'data_page.html', {
                'number_of_followers': number_of_followers,
                'number_of_events': number_of_events
            })

    else:
        message = "You are not logged in as an artist"
        # Return somewhere
        return index(request)
Example #9
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')
Example #10
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
                  })