def get_queryset(self): ''' Change the queryset depending on the user's rights. The rules are the following: * A BV user sees all submissions * A regular user sees it's own submissions ''' queryset = SubmissionInternational.objects.filter(creation_date__month=self.get_month()) \ .filter(creation_date__year=self.get_year()) \ .order_by('gym__state', 'creation_date') if user_type(self.request.user) == USER_TYPE_BUNDESVERBAND: return queryset elif user_type(self.request.user) == USER_TYPE_USER: return queryset.filter(user=self.request.user)
def get_context_data(self, **kwargs): ''' Pass a list of all available dates ''' context = super(SubmissionListView, self).get_context_data(**kwargs) queryset = SubmissionInternational.objects.all().order_by('gym__state', 'creation_date') if user_type(self.request.user) == USER_TYPE_USER: queryset = queryset.filter(user=self.request.user) context.update(get_overview_context(self.model, queryset, self.request.user)) return context
def processor(request): return { # User type 'user_type': user_type(request.user), # User types 'USER_TYPE_BUNDESVERBAND': USER_TYPE_BUNDESVERBAND, 'USER_TYPE_USER': USER_TYPE_USER, # Submission stati 'SUBMISSION_STATUS_EINGEGANGEN': SubmissionStarter.SUBMISSION_STATUS_EINGEGANGEN, 'SUBMISSION_STATUS_BEWILLIGT': SubmissionStarter.SUBMISSION_STATUS_BEWILLIGT, 'SUBMISSION_STATUS_ABGELEHNT': SubmissionStarter.SUBMISSION_STATUS_ABGELEHNT, }
def render_submission_list(submissions, user, filter_mode, submission_type='starter'): ''' Render a table with submissions :param submissions: list with submissions :param user: current user :param filter_mode what submissions to list (open, closed, etc.) :param submission_type The type of the submission. Allowed values: starter, gym, judge ''' if submission_type == 'starter': url_fragment = '' elif submission_type == 'gym': url_fragment = '-studio' elif submission_type == 'judge': url_fragment = '-judge' elif submission_type == 'international': url_fragment = '-international' context = dict() context['SUBMISSION_STATUS_EINGEGANGEN'] = SubmissionStarter.SUBMISSION_STATUS_EINGEGANGEN context['SUBMISSION_STATUS_BEWILLIGT'] = SubmissionStarter.SUBMISSION_STATUS_BEWILLIGT context['SUBMISSION_STATUS_ABGELEHNT'] = SubmissionStarter.SUBMISSION_STATUS_ABGELEHNT submission_list = [] if submissions: if filter_mode == 'open': submission_list = [i for i in submissions if i.submission_status == SubmissionStarter.SUBMISSION_STATUS_EINGEGANGEN] elif filter_mode == 'closed': submission_list = [i for i in submissions if i.submission_status != SubmissionStarter.SUBMISSION_STATUS_EINGEGANGEN] else: submission_list = [i for i in submissions] context['submission_list'] = submission_list context['submission_type'] = submission_type context['user_type'] = user_type(user) context['USER_TYPE_BUNDESVERBAND'] = USER_TYPE_BUNDESVERBAND context['USER_TYPE_USER'] = USER_TYPE_USER context['url_submission_view'] = 'submission{0}-view'.format(url_fragment) context['url_submission_edit'] = 'submission{0}-edit-status'.format(url_fragment) context['url_submission_delete'] = 'submission{0}-delete'.format(url_fragment) return render_to_string("tags/render_submission_list.html", context)
def get_overview_context(model_class, queryset, user, **kwargs): ''' Pass a list of all available dates ''' context = {} # Count how many submissions were exported for each month month_list = [] for date_obj in queryset.dates('creation_date', 'month'): tmp_count = model_class.objects.filter(mail_merge=True)\ .filter(creation_date__month=date_obj.month)\ .filter(creation_date__year=date_obj.year) month_list.append({'date': date_obj, 'export_count': tmp_count.count()}) context['submission_list'] = queryset context['month_list'] = month_list context['current_year'] = datetime.date.today().year context['current_month'] = datetime.date.today().month context['show_closed'] = False if user_type(user) == USER_TYPE_BUNDESVERBAND else True context['mailmerge_count'] = model_class.objects.filter(mail_merge=False) \ .filter(submission_status=model_class.SUBMISSION_STATUS_BEWILLIGT) \ .count() return context