Beispiel #1
0
def show(request):
    if is_admin(request):
        template = 'dashboard.html'
        context = {}
        set_user(request, context)

        accepted_buildings = get_percentage_buildings('ACCEPTED')
        context['accepted_buildings'] = accepted_buildings
        rejected_buildings = get_percentage_buildings('REJECTED')
        context['rejected_buildings'] = rejected_buildings
        pending_buildings = get_percentage_buildings('PENDING')
        context['pending_buildings'] = pending_buildings

        accepted_parties = get_percentage_party_requests('ACCEPTED')
        context['accepted_parties'] = accepted_parties
        rejected_parties = get_percentage_party_requests('REJECTED')
        context['rejected_parties'] = rejected_parties
        pending_parties = get_percentage_party_requests('PENDING')
        context['pending_parties'] = pending_parties

        accepted_attend_requests = get_percentage_attend_requests('ACCEPTED')
        context['accepted_attend_requests'] = accepted_attend_requests
        rejected_attend_requests = get_percentage_attend_requests('REJECTED')
        context['rejected_attend_requests'] = rejected_attend_requests
        pending_attend_requests = get_percentage_attend_requests('PENDING')
        context['pending_attend_requests'] = pending_attend_requests

        return render(request, template, context)
    else:
        return redirect('index')
Beispiel #2
0
def index(request):
    template = 'index.html'
    buildings = get_accepted_buildings()
    parties = get_accepted_parties()
    context = {'buildings': buildings, 'parties': parties, 'nav': 'index'}
    set_user(request, context)
    return render(request, template, context)
Beispiel #3
0
def party_requests(request, id):
    if is_owner(request):
        template = 'party_requests.html'
        requests = get_pending_requests_by_owner_id(id)
        context = {'requests': requests}
        set_user(request, context)
        return render(request, template, context)
    else:
        return redirect('index')
Beispiel #4
0
def customer_parties(request, id):
    if is_customer(request):
        template = 'customer_parties.html'
        parties = get_parties_by_customer_id(id)
        context = {'parties': parties}
        set_user(request, context)
        return render(request, template, context)
    else:
        return redirect('index')
Beispiel #5
0
def attend_requests(request, id):
    if is_customer(request):
        template = 'attend_requests.html'
        attend_requests = get_pending_attend_requests_by_customer_id(id)
        context = {'attend_requests': attend_requests}
        set_user(request, context)
        return render(request, template, context)
    else:
        return redirect('index')
Beispiel #6
0
def admin_buildings(request):
    if is_admin(request):
        template = 'admin_buildings.html'
        buildings = get_pending_buildings()
        context = {'buildings': buildings}
        set_user(request, context)
        return render(request, template, context)
    else:
        return redirect('index')
Beispiel #7
0
def owner_buildings(request, userId):
    if is_owner(request):
        template = 'owner_buildings.html'
        buildings = get_buildings_by_owner_id(userId)
        context = {'buildings': buildings}
        set_user(request, context)
        return render(request, template, context)
    else:
        return redirect('index')
Beispiel #8
0
def search_parties(request):
    template = 'search_parties.html'
    context = {}
    set_user(request, context)

    if request.method == 'GET':
        return render(request, template, context)

    search = request.POST.get('search')
    parties = get_accepted_parties_by_name(search)
    context['parties'] = parties
    return render(request, template, context)
Beispiel #9
0
def search_buildings(request):
    template = 'search_buildings.html'
    context = {}
    set_user(request, context)

    if request.method == 'GET':
        return render(request, template, context)

    search = request.POST.get('search')
    buildings = get_accepted_buildings_by_address(search)
    context['buildings'] = buildings
    return render(request, template, context)
Beispiel #10
0
def show_building(request, id):
    building = get_building_by_id(id)
    user = get_user(request)
    if building.decision == 'ACCEPTED' or building.owner == user or is_admin(
            request):
        template = 'show_building.html'
        context = {'building': building}
        set_user(request, context)
        if is_admin(request) and building.decision == 'PENDING':
            context['choose'] = True
        return render(request, template, context)
    else:
        return redirect('index')
Beispiel #11
0
def show_party(request, id):
    template = 'show_party.html'
    party = get_party_by_id(id)
    attendees = get_accepted_attendees_by_party_id(id)
    context = {'party': party, 'attendees': attendees}
    set_user(request, context)
    can_join = False
    if is_customer(request):
        customer = get_user(request)
        so_far = number_of_attendees_so_far(party)
        available = len(so_far) < party.numberOfAttendees
        if customer not in attendees and not has_made_an_attend_request(
                customer, party) and available:
            can_join = True
    context['canJoin'] = can_join
    return render(request, template, context)
Beispiel #12
0
def show_request(request, id):
    req = get_request_by_id(id)
    user = get_user(request)
    is_mine = False
    if is_owner(request):
        buildings = get_buildings_by_owner_id(user.id)
        is_mine = req.building in buildings
    if is_admin(request) or req.customer == user or is_mine:
        template = 'show_request.html'
        party = get_party_by_request_id(id)
        context = {'party': party, 'request': req}
        set_user(request, context)
        if is_mine and req.decision == 'PENDING':
            context['choose'] = True
        return render(request, template, context)
    else:
        return redirect('index')
Beispiel #13
0
def new_party(request, id):
    if is_customer(request):
        template = 'new_party.html'
        building = get_building_by_id(id)
        context = {'building': building}
        set_user(request, context)
        if request.method == 'GET':
            return render(request, template, context)

        message = request.POST.get('message')
        name = request.POST.get('name')
        description = request.POST.get('description')
        attendees = request.POST.get('attendees')
        startdate = request.POST.get('startdate')
        enddate = request.POST.get('enddate')
        picture = request.POST.get('picture')
        price = request.POST.get('price')
        customer = get_user(request)

        request = Request(message=message,
                          building=building,
                          customer=customer)
        request.save()

        party = Party(name=name,
                      price=price,
                      description=description,
                      numberOfAttendees=attendees,
                      startDate=startdate,
                      endDate=enddate,
                      picture=picture,
                      request=request)
        party.save()

        return redirect(f'/party/customer/{customer.id}/parties')

    else:
        return redirect('index')
Beispiel #14
0
def new_building(request):
    if is_owner(request):
        template = 'new_building.html'
        context = {}
        set_user(request, context)
        if request.method == 'GET':
            return render(request, template, context)

        address = request.POST.get('address')
        capacity = request.POST.get('capacity')
        conditions = request.POST.get('conditions')
        picture = request.POST.get('picture')
        owner = get_user(request)

        building = Building(address=address,
                            capacity=capacity,
                            conditions=conditions,
                            picture=picture,
                            owner=owner)
        building.save()
        return redirect(f'/building/owner/{owner.id}/buildings')

    else:
        return redirect('index')