Beispiel #1
0
def sales(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        form = SalesForm(request.POST or None)
        drawer = Drawer.objects.all()[0]
        item_scanned = ''
        if form.is_valid():
            try:
                item_scanned = Item.objects.get(id_number=form.cleaned_data.get('item_id'))
                t = Transaction(item=item_scanned)
                item_scanned.quantity -= 1
                item_scanned.save()
                drawer.amount += item_scanned.price
                drawer.save()
                t.save()
            except Item.DoesNotExist:
                context['error'] = True

            form = SalesForm(None)

        transactions = Transaction.objects.order_by('-timestamp')[:10]
        context['form'] = form
        context['item_scanned'] = item_scanned
        context['transactions'] = transactions
    return render(request, "dbcafe/sales.html", context)
Beispiel #2
0
def convert(request, uniqname):
    if request.user.is_superuser or is_officer(request.user.username):
        if request.POST:
            member = Member.objects.get(uniqname=uniqname)
            if member.status == 'E':
                member.status = 'A'
                member.save()
                electee = Electee.objects.get(member=member)
                electee.delete()
    return redirect(request.META.get('HTTP_REFERER'), None, None)
Beispiel #3
0
def convert(request, uniqname):
    if request.user.is_superuser or is_officer(request.user.username):
        if request.POST:
            member = Member.objects.get(uniqname=uniqname)
            if member.status == 'E':
                member.status = 'A'
                member.save()
                electee = Electee.objects.get(member=member)
                electee.delete()
    return redirect(request.META.get('HTTP_REFERER'), None, None)
Beispiel #4
0
def undo(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        transaction = Transaction.objects.all().order_by('-timestamp')[0]
        transaction.delete()
    return redirect('sales')
Beispiel #5
0
def reset(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        drawer = Drawer.objects.all()[0]
        drawer.amount = 300
        drawer.save()
    return redirect('stats')
Beispiel #6
0
def stats(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        drawer = Drawer.objects.all()[0]
        context = {
            'drawer': drawer
        }
    return render(request, "dbcafe/stats.html", context)
Beispiel #7
0
def items_list(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        items = Item.objects.all()
        context = {
            'items': items
        }
    return render(request, "dbcafe/items_list.html", context)
Beispiel #8
0
def all_electees(request):
    context = {}
    m = Member.objects.get(uniqname=request.user.username)
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        # get all of the electee objects to display
        electee_list = Electee.objects.filter(member__status='E')
        requirements = dict((requirements.requirement, requirements)
                            for requirements in Requirements.objects.all())

        # process the electee progress, so that wo don't have to run those if-else in template html
        electee_list_plain = []
        for electee in electee_list:
            progress = {
                'uniqname': electee.member.uniqname,
                'first_name': electee.member.first_name,
                'last_name': electee.member.last_name,
                'num_socials_approved': electee.num_socials_approved,
                'num_service_hours_approved':
                electee.num_service_hours_approved,
                'electee_interview': electee.electee_interview,
                'electee_exam': electee.electee_exam,
                'dues': electee.dues,
            }

            # check for if requirement meets
            req_social, req_service = ('A_UG_SOCIAL', 'C_UG_TOTAL_HOURS') if \
                electee.member.is_undergraduate() else ('B_G_SOCIAL', 'D_G_TOTAL_HOURS')

            progress['social_req'] = requirements[req_social].num_required
            progress['service_req'] = requirements[req_service].num_required

            progress['social_done'] = (progress['num_socials_approved'] >=
                                       progress['social_req'])
            progress['service_done'] = (progress['num_service_hours_approved']
                                        >= progress['service_req'])

            # decide if the electee are able to convert to active
            progress['convert'] = progress['social_done'] and progress[
                'service_done'] and progress['electee_interview'] and progress[
                    'electee_exam'] and progress['dues']

            electee_list_plain.append(progress)

        context['electee_list'] = electee_list_plain

    return render(request, "electeeManagement/all_electees.html", context)
Beispiel #9
0
def all_electees(request):
    context = {}
    m =  Member.objects.get(uniqname=request.user.username)
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        # get all of the electee objects to display
        electee_list = Electee.objects.filter(member__status='E')
        requirements = dict(
            (requirements.requirement, requirements) for requirements in Requirements.objects.all())

        # process the electee progress, so that wo don't have to run those if-else in template html
        electee_list_plain = []
        for electee in electee_list:
            progress = {
                'uniqname': electee.member.uniqname,
                'first_name': electee.member.first_name,
                'last_name': electee.member.last_name,

                'num_socials_approved': electee.num_socials_approved,
                'num_service_hours_approved': electee.num_service_hours_approved,
                'electee_interview': electee.electee_interview,
                'electee_exam': electee.electee_exam,
                'dues': electee.dues,
            }

            # check for if requirement meets
            req_social, req_service = ('A_UG_SOCIAL', 'C_UG_TOTAL_HOURS') if \
                electee.member.is_undergraduate() else ('B_G_SOCIAL', 'D_G_TOTAL_HOURS')

            progress['social_req'] = requirements[req_social].num_required
            progress['service_req'] = requirements[req_service].num_required

            progress['social_done'] = (
                progress['num_socials_approved'] >= progress['social_req'])
            progress['service_done'] = (
                progress['num_service_hours_approved'] >= progress['service_req'])

            # decide if the electee are able to convert to active
            progress['convert'] = progress['social_done'] and progress['service_done'] and progress[
                'electee_interview'] and progress['electee_exam'] and progress['dues']

            electee_list_plain.append(progress)

        context['electee_list'] = electee_list_plain

    return render(request, "electeeManagement/all_electees.html", context)
Beispiel #10
0
def electee_submission_approval(request, approved=0):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        # get all unapproved socials and service hours
        social_list = Social.objects.filter(approved='0')
        service_hour_list = Service_Hours.objects.filter(approved='0')

        SocialFormSet = modelformset_factory(Social,
                                             fields=('approved', ),
                                             extra=0)
        social_formset = SocialFormSet(queryset=Social.objects.filter(
            approved='0').order_by('timestamp'))

        ServiceFormSet = modelformset_factory(Service_Hours,
                                              fields=('approved', ),
                                              extra=0)
        service_formset = ServiceFormSet(queryset=Service_Hours.objects.filter(
            approved='0').order_by('timestamp'))

        context = {
            'social_list': social_list,
            'service_hour_list': service_hour_list,
            'social_formset': social_formset,
            'service_formset': service_formset,
            'approved': approved
        }

        if request.POST:
            formset = SocialFormSet(request.POST)
            if formset.is_valid():
                formset.save()
                update_approved_hours()
            formset = ServiceFormSet(request.POST)
            if formset.is_valid():
                formset.save()
                update_approved_hours()
            return redirect('electee_submission_approval', approved=1)

    return render(request,
                  "electeeManagement/electee_submission_approval.html",
                  context)
Beispiel #11
0
def items_add(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        form = ItemForm(request.POST or None)
        context = {
            'form': form
        }

        if request.POST:
            form.save()
            return redirect('items_list')

    return render(request, "dbcafe/items_add.html", context)
Beispiel #12
0
def items_edit(request, item):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        i = Item.objects.get(name=item)
        form = ItemForm(instance=i)
        context = {
            'form': form
        }
        if request.POST:
            form = ItemForm(request.POST, instance=i)
            if form.is_valid():
                form.save()
                return redirect('items_list')

    return render(request, "dbcafe/items_edit.html", context)
Beispiel #13
0
def electee_turn_ins(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        TurnInsFormset = modelformset_factory(Electee,
                                              fields=('electee_interview',
                                                      'dues', 'electee_exam'),
                                              extra=0)
        turnins_formset = TurnInsFormset(queryset=Electee.objects.all())
        context = {'turnins_formset': turnins_formset}

        if request.POST:
            formset = TurnInsFormset(request.POST)
            formset.save()
            context['turnins_saved'] = True

    return render(request, "electeeManagement/electee_turn_ins.html", context)
Beispiel #14
0
def electee_submission_approval(request, approved=0):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        # get all unapproved socials and service hours
        social_list = Social.objects.filter(approved='0')
        service_hour_list = Service_Hours.objects.filter(approved='0')

        SocialFormSet = modelformset_factory(Social, fields=('approved',), extra=0)
        social_formset = SocialFormSet(
            queryset=Social.objects.filter(approved='0').order_by('timestamp'))

        ServiceFormSet = modelformset_factory(Service_Hours, fields=('approved',), extra=0)
        service_formset = ServiceFormSet(
            queryset=Service_Hours.objects.filter(approved='0').order_by('timestamp'))

        context = {
            'social_list': social_list,
            'service_hour_list': service_hour_list,
            'social_formset': social_formset,
            'service_formset': service_formset,
            'approved': approved
        }

        if request.POST:
            formset = SocialFormSet(request.POST)
            if formset.is_valid():
                formset.save()
                update_approved_hours()
            formset = ServiceFormSet(request.POST)
            if formset.is_valid():
                formset.save()
                update_approved_hours()
            return redirect('electee_submission_approval', approved=1)

    return render(request, "electeeManagement/electee_submission_approval.html", context)
Beispiel #15
0
def electee_turn_ins(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        TurnInsFormset = modelformset_factory(Electee,
                                              fields=('electee_interview', 'dues', 'electee_exam'),
                                              extra=0)
        turnins_formset = TurnInsFormset(queryset=Electee.objects.all())
        context = {
            'turnins_formset': turnins_formset
        }

        if request.POST:
            formset = TurnInsFormset(request.POST)
            formset.save()
            context['turnins_saved'] = True

    return render(request, "electeeManagement/electee_turn_ins.html", context)
Beispiel #16
0
def edit_electee_requirements(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        RequirementsFormset = modelformset_factory(Requirements, fields=('num_required',), extra=0)
        req_formset = RequirementsFormset(queryset=Requirements.objects.all())

        context = {
            'req_formset': req_formset,
            'requirement_changed': False
        }

        if request.POST:
            formset = RequirementsFormset(request.POST)
            formset.save()
            context['requirement_changed'] = True

    return render(request, "electeeManagement/edit_electee_requirements.html", context)
Beispiel #17
0
def edit_electee_requirements(request):
    context = {}
    if not (request.user.is_superuser or is_officer(request.user.username)):
        context = {
            'error': True,
            'error_msg': 'You do not have permission to access this page'
        }
    else:
        RequirementsFormset = modelformset_factory(Requirements,
                                                   fields=('num_required', ),
                                                   extra=0)
        req_formset = RequirementsFormset(queryset=Requirements.objects.all())

        context = {'req_formset': req_formset, 'requirement_changed': False}

        if request.POST:
            formset = RequirementsFormset(request.POST)
            formset.save()
            context['requirement_changed'] = True

    return render(request, "electeeManagement/edit_electee_requirements.html",
                  context)
Beispiel #18
0
def remove_electee(request, uniqname):
    if request.user.is_superuser or is_officer(request.user.username):
        if request.POST:
            member = Member.objects.get(uniqname=uniqname)
            member.delete()
    return redirect(request.META.get('HTTP_REFERER'), None, None)
Beispiel #19
0
def remove_electee(request, uniqname):
    if request.user.is_superuser or is_officer(request.user.username):
        if request.POST:
            member = Member.objects.get(uniqname=uniqname)
            member.delete()
    return redirect(request.META.get('HTTP_REFERER'), None, None)