Exemple #1
0
    def get_context_data(self, **kwargs):
        """
        Set context for managers Dashboard.
        """
        context = super(Dashboard, self).get_context_data(**kwargs)

        ctx = {
            'rereview_count': None,
            'pending_count': None,
            # Needed to determine whether to show the cancel/un-cancel button
            'posted_state': State.posted,
            'state': 'posted',
            'start_date': self.get_start_date(),
            'show_rereview': get_main_calendar() in self.request.user.editable_calendars.all() or self.request.user.is_superuser
        }

        # merge context data
        ctx.update(context)

        calendar = self.get_calendar()
        if calendar:
            ctx['rereview_count'] = calendar.future_event_instances().filter(event__state=State.rereview).count()
            ctx['pending_count'] = calendar.future_event_instances().filter(event__state=State.pending).count()
        else:
            ctx['rereview_count'] = get_all_users_future_events(self.request.user).filter(event__state=State.rereview).count()
            ctx['pending_count'] = get_all_users_future_events(self.request.user).filter(event__state=State.pending).count()

        # get the state filter
        state_id = State.get_id(self.kwargs.get('state'))
        if state_id is None and self.kwargs.get('state') == 'subscribed':
            ctx['state'] = 'subscribed'
        elif state_id is not None:
            ctx['state'] = self.kwargs.get('state')

        return ctx
Exemple #2
0
    def get_queryset(self):
        """
        Get queryset based on date and state.
        """
        events = None
        calendar = self.get_calendar()
        if calendar:
            if not self.request.user.is_superuser and calendar not in self.request.user.calendars:
                return HttpResponseNotFound('You do not have permission to access this calendar.')

            if self.is_date_selected():
                events = calendar.range_event_instances(self.get_start_date(), self.get_end_date())
            else:
                events = calendar.future_event_instances()
        else:
            if self.is_date_selected():
                events = get_events_by_range(self.get_start_date(),
                                             self.get_end_date(),
                                             user=self.request.user)
            else:
                events = get_all_users_future_events(self.request.user)

        # get the state filter
        if self.kwargs.get('state') == 'subscribed' and events:
            events = events.filter(event__state=State.get_id('posted'), event__created_from__isnull=False)
        else:
            state_id = State.get_id(self.kwargs.get('state'))
            if state_id is None:
                state_id = State.get_id('posted')

            if events:
                events = events.filter(event__state=state_id)

        self.queryset = events
        return events