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
def submit_event_to_main(request, pk=None): """ Submit the event to the main calendar. """ event = get_object_or_404(Event, pk=pk) if not request.user.is_superuser and event.calendar not in request.user.calendars: messages.error(request, 'You cannot submit Event %s to the Main Calendar.' % event.title) else: if event.state == State.posted: if not event.is_submit_to_main: try: get_main_calendar().import_event(event) except Exception, e: log.error(str(e)) messages.error(request, 'Unable to submit Event %s to the Main Calendar.' % event.title) else: messages.success(request, 'Event %s was successfully submitted to the Main Calendar. Please allow 2-3 days for your event to be reviewed before it is posted to UCF\'s Main Calendar.' % event.title) else: messages.warning(request, 'Event %s has already been submitted to the Main Calendar. Please allow 2-3 days for your event to be reviewed before it is posted to UCF\'s Main Calendar.' % event.title) else:
except Exception, e: """ Try to catch errors gracefully here, but make sure they're logged """ log.error(str(e)) messages.error(self.request, 'Something went wrong while trying to create this \ event. Please try again.') return self.render_to_response( self.get_context_data(form=form, event_instance_formset=event_instance_formset)) else: # Import to main calendar if requested and state is posted if form.cleaned_data['submit_to_main']: if self.object.state == State.posted: get_main_calendar().import_event(self.object) messages.success(self.request, 'Event successfully submitted to the Main Calendar. Please allow 2-3 days for your event to be reviewed before it is posted to UCF\'s Main Calendar.') else: messages.error(self.request, 'Event can not be submitted to the Main Calendar unless it is posted on your calendar.') update_subscriptions(self.object) messages.success(self.request, 'Event successfully saved') return HttpResponseRedirect(self.get_success_url()) def form_invalid(self, form, event_instance_formset): """ Called if a form is invalid. Re-renders the context data with the data-filled forms and errors. """ messages.error(self.request, 'Something wasn\'t entered correctly. Please review the errors below and try again.')