Esempio n. 1
0
class CreationStatisticsFilter(django_filters.FilterSet):

    publish_at = django_filters.DateRangeCompareFilter()

    class Meta:
        model = TutorialResource
        fields = [
            'tutorial_detail__foss', 'language', 'tutorial_detail__level',
            'publish_at'
        ]
Esempio n. 2
0
class TrainingFilter(django_filters.FilterSet):
  academic__state = django_filters.ChoiceFilter(choices=State.objects.none())
  foss = django_filters.ChoiceFilter(choices= [('', '---------')] + list(FossAvailableForWorkshop.objects.filter(status=1).order_by('foss__foss').values_list('foss__id', 'foss__foss').distinct()))
  language = django_filters.ChoiceFilter(choices= [('', '---------')] + list(FossAvailableForWorkshop.objects.values_list('language__id', 'language__name').distinct().order_by('language__name')))
  training_type = django_filters.ChoiceFilter(choices= [('', '---------'), (0, 'Training'), (1, 'Workshop'), (2, 'Live Workshop'), (3, 'Pilot Workshop')])
  academic__institution_type = django_filters.ChoiceFilter(choices= [('', '---------')] + list(InstituteType.objects.values_list('id', 'name').distinct()))
  academic__city = django_filters.ChoiceFilter(choices=State.objects.none())
  tdate = django_filters.DateRangeCompareFilter()
  academic__institution_name = django_filters.CharSearchFilter()
  def __init__(self, *args, **kwargs):
    user=None
    if 'user' in kwargs:
      user = kwargs['user']
      kwargs.pop('user')

    state = None
    if 'state' in kwargs:
      state = kwargs['state']
      kwargs.pop('state')
    super(TrainingFilter, self).__init__(*args, **kwargs)
    if args and args[0] and 'academic__state' in args[0] and args[0]['academic__state']:
      try:
        state = State.objects.get(pk = args[0]['academic__state'])
      except ObjectDoesNotExist:
        pass
    choices = None
    if user:
      choices = list(State.objects.filter(resourceperson__user_id=user, resourceperson__status=1).values_list('id', 'name'))
    else:
      choices = list(State.objects.exclude(name='Uncategorised').order_by('name').values_list('id', 'name'))
    choices.insert(0, ('', '---------'),)
    self.filters['academic__state'].extra.update({'choices' : choices})

    choices = None
    if state:
      choices = list(City.objects.filter(state=state).order_by('name').values_list('id', 'name')) + [('189', 'Uncategorised')]
    else:
      choices = list(City.objects.none())
    choices.insert(0, ('', '---------'),)
    self.filters['academic__city'].extra.update({'choices' : choices})

  class Meta:
    model = Training
    fields = ['academic__state', 'foss']
Esempio n. 3
0
class TrainingRequestFilter(django_filters.FilterSet):

    training_planner__academic__state = django_filters.ChoiceFilter(
        choices=State.objects.none())

    course__foss = django_filters.ChoiceFilter(
        choices=[('', '---------')] + list(
            TrainingRequest.objects.filter(
                status=1).order_by('course__foss__foss').values_list(
                    'course__foss__id', 'course__foss__foss').distinct()))

    course__category = django_filters.ChoiceFilter(
        choices=[('', '---------'), (
            0, 'Course outside lab hours'), (1, 'Course mapped in lab hours'),
                 (2, 'Course unmapped in lab hours'), (3, 'EduEasy Software')])

    training_planner__academic__institution_type = django_filters.ChoiceFilter(
        choices=[('', '---------')] +
        list(InstituteType.objects.all().values_list('id', 'name').distinct()))

    training_planner__academic__city = django_filters.ChoiceFilter(
        choices=State.objects.none())

    sem_start_date = django_filters.DateRangeCompareFilter()

    training_planner__academic__institution_name = \
      django_filters.CharSearchFilter()

    def __init__(self, *args, **kwargs):
        user = None
        if 'user' in kwargs:
            user = kwargs['user']
            kwargs.pop('user')
        rp_completed = None
        if 'rp_completed' in kwargs:
            rp_completed = kwargs['rp_completed']
            kwargs.pop('rp_completed')
        rp_ongoing = None
        if 'rp_ongoing' in kwargs:
            rp_ongoing = kwargs['rp_ongoing']
            kwargs.pop('rp_ongoing')
        rp_markcomplete = None
        if 'rp_markcomplete' in kwargs:
            rp_markcomplete = kwargs['rp_markcomplete']
            kwargs.pop('rp_markcomplete')
        state = None
        if 'state' in kwargs:
            state = kwargs['state']
            kwargs.pop('state')
        super(TrainingRequestFilter, self).__init__(*args, **kwargs)
        if args and args[0] and 'training_planner__academic__state' in args[0] \
          and args[0]['training_planner__academic__state']:
            try:
                state = State.objects.get(
                    pk=args[0]['training_planner__academic__state'])
            except ObjectDoesNotExist:
                pass
        choices = None
        if user:
            if rp_completed:
                foss_list = TrainingRequest.objects.filter(
                    status=1,
                    training_planner__academic__state_id__in=user.
                    resourceperson_set.all().values_list('state_id').distinct(
                    )).order_by('course__foss__foss').values_list(
                        'course__foss__id', 'course__foss__foss').distinct()
            elif rp_ongoing:
                foss_list = TrainingRequest.objects.filter(
                    status=0,
                    training_planner__academic__state_id__in=user.
                    resourceperson_set.all().values_list('state_id').distinct(
                    )).order_by('course__foss__foss').values_list(
                        'course__foss__id', 'course__foss__foss').distinct()
            elif rp_markcomplete:
                foss_list = TrainingRequest.objects.filter(
                    status=2,
                    training_planner__academic__state_id__in=user.
                    resourceperson_set.all().values_list('state_id').distinct(
                    )).order_by('course__foss__foss').values_list(
                        'course__foss__id', 'course__foss__foss').distinct()
            else:
                foss_list = TrainingRequest.objects.filter(
                    training_planner__academic__state_id__in=user.
                    resourceperson_set.all().values_list('state_id').distinct(
                    )).order_by('course__foss__foss').values_list(
                        'course__foss__id', 'course__foss__foss').distinct()
            choices = [('', '---------')] + list(foss_list)
            self.filters['course__foss'].extra.update({'choices': choices})
            choices = list(
                State.objects.filter(resourceperson__user_id=user,
                                     resourceperson__status=1).values_list(
                                         'id', 'name'))
        else:
            choices = list(
                State.objects.exclude(
                    name='Uncategorised').order_by('name').values_list(
                        'id', 'name'))
        choices.insert(
            0,
            ('', '---------'),
        )
        self.filters['training_planner__academic__state'].extra.update(
            {'choices': choices})

        choices = None
        if state:
            choices = list(
                City.objects.filter(state=state).order_by('name').values_list(
                    'id', 'name')) + [('189', 'Uncategorised')]
        else:
            choices = list(
                City.objects.order_by('name').values_list('id', 'name'))
        choices.insert(
            0,
            ('', '---------'),
        )
        self.filters['training_planner__academic__city'].extra.update(
            {'choices': choices})

    class Meta:
        model = TrainingRequest
        fields = ['training_planner__academic__state', 'course__foss']