Пример #1
0
def populate_random_desk_items():
    residents = Resident.on_site.all()[0:random.randint(5, 15)]
    s = Site.objects.get_current()
    items = []
    num_added = 0
    for i in range(30):
        item = DeskItem(
            at_dorm = s,
            name = rand_word(random.randint(4,10)),
        )
        if random.randint(0, 1) == 0:
            item.max_loan_duration = "%d days" % random.randint(1,5)
        item.save()
        num_added += 1
        items.append(item)
    print "Added %d desk items" % num_added
    num_added = 0
    for i in range(30):
        loan = DeskItemLoan(
            desk_item = random.choice(items),
            resident = random.choice(residents),
        )
        loan.save()
        num_added += 1
        if random.randint(0, 3) == 0:
            loan.end_loan()
    print "Added %d desk item loans" % num_added
Пример #2
0
def dashboard(request):
    try:
        resident = request.user.resident
    except Resident.DoesNotExist:
        return render_to_response("personal/non_resident.html", context_instance=RequestContext(request))

    num_packages = packages = Package.objects.filter(recipient=resident, retrieved_at=None).count()
    size_guestlist = GuestlistEntry.get_active_entries_for_resident(resident).count()
    num_active_loans = DeskItemLoan.get_active_loans_for_resident(resident).count()
    payload = {
        "resident": request.user.resident,
        "num_packages": num_packages,
        "size_guestlist": size_guestlist,
        "num_active_loans": num_active_loans,
    }
    return render_to_response("personal/dashboard.html", payload, context_instance=RequestContext(request))
Пример #3
0
 def get_context_data(self, **kwargs):
     context = super(DeskItemDatatableView, self).get_context_data(**kwargs)
     resident = self.request.user.resident
     active_loans = DeskItemLoan.get_active_loans_for_resident(resident).order_by("loaned_at")
     context["active_loans"] = active_loans
     return context