def populate_random_guests(): s = Site.objects.get_current() f = open('residents/test_names.txt') names = [n.strip().split() for n in f.readlines()] residents = Resident.on_site.all()[0:random.randint(5, 15)] today = timezone.now().date() num_added = 0 for r in residents: for i in range(5): first, last = random.choice(names) name = "%s %s" % (first, last) MIT = (random.randint(0,3) == 0) username = last[0:8].lower() if MIT else "" g = GuestlistEntry( guest_of = r, for_dorm = s, name = name, is_mit_student = MIT, username = username, ) if random.randint(0, 4) == 0: g.starts_on = today + timedelta(random.randint(1,10)) if random.randint(0, 4) == 0: g.expires_on = today + timedelta(random.randint(-10,10)) num_added += 1 g.save() print "Added %d guest list entries" % num_added
def guestlist_add(request): if request.method == "POST": form = GuestlistEntryForm(request.POST) if form.is_valid(): g = GuestlistEntry() g.guest_of = request.user.resident g.for_dorm = Site.objects.get_current() g.name = form.cleaned_data["name"] g.is_mit_student = form.cleaned_data["is_mit_student"] g.username = form.cleaned_data["username"] g.starts_on = form.cleaned_data["starts_on"] g.expires_on = form.cleaned_data["expires_on"] g.save() # TODO email the user about their package return HttpResponseRedirect(reverse(guestlist)) else: form = GuestlistEntryForm(initial={"is_mit_student": True}) payload = {"form": form, "prev_url": reverse(guestlist)} return render_to_response("guestlist/guestlistentry_form.html", payload, context_instance=RequestContext(request))
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))
def get_queryset(self): return GuestlistEntry.get_active_entries_for_dorm().order_by('name')
def guestlist(request): resident = request.user.resident guestlist_entries = GuestlistEntry.get_active_entries_for_resident(resident).order_by("-expires_on", "name") payload = {"guests": guestlist_entries, "today": timezone.now().date()} return render_to_response("personal/guestlist.html", payload, context_instance=RequestContext(request))