Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 1 | #views.py |
| 2 | from django.views.generic import TemplateView |
| 3 | |
Siobhan Tully | 90040c2 | 2014-01-13 23:47:24 -0500 | [diff] [blame] | 4 | from core.models import Slice,SliceRole,SlicePrivilege,Site,Reservation |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 5 | |
| 6 | class DashboardWelcomeView(TemplateView): |
| 7 | template_name = 'admin/dashboard/welcome.html' |
| 8 | |
| 9 | def get(self, request, *args, **kwargs): |
| 10 | context = self.get_context_data(**kwargs) |
Siobhan Tully | 90040c2 | 2014-01-13 23:47:24 -0500 | [diff] [blame] | 11 | sliceList = Slice.objects.all() |
| 12 | try: |
| 13 | site = Site.objects.filter(id=request.user.site.id) |
| 14 | except: |
| 15 | site = Site.objects.filter(name="Princeton") |
| 16 | context['site'] = site[0] |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 17 | |
Siobhan Tully | 90040c2 | 2014-01-13 23:47:24 -0500 | [diff] [blame] | 18 | slicePrivs = SlicePrivilege.objects.filter(user=request.user) |
| 19 | userSliceInfo = [] |
| 20 | for entry in slicePrivs: |
| 21 | |
| 22 | try: |
| 23 | reservationList = Reservation.objects.filter(slice=entry.slice) |
| 24 | reservations = (True,reservationList) |
| 25 | |
| 26 | except: |
| 27 | reservations = None |
| 28 | |
| 29 | userSliceInfo.append({'slice': Slice.objects.get(id=entry.slice.id), |
| 30 | 'role': SliceRole.objects.get(id=entry.role.id).role, |
| 31 | 'reservations': reservations}) |
| 32 | |
| 33 | context['userSliceInfo'] = userSliceInfo |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 34 | return self.render_to_response(context=context) |