Exemplo n.º 1
0
class ScheduleForm(forms.ModelForm):
    events = forms.ModelMultipleChoiceField(label='Events',
                                            queryset=Event.objects.all(),
                                            required=False,
                                            widget=FilteredSelectMultiple(
                                                "events", is_stacked=False))

    weeks = CSIMultipleChoiceField(
        initial='0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19',
        choices=Term.all_weeks_choices(),
        required=False,
        label='Weeks')

    trainees = forms.ModelMultipleChoiceField(
        queryset=Trainee.objects.all(),
        label='Participating Trainees',
        required=False,
        widget=TraineeSelect2MultipleInput,
    )

    def save(self, commit=True):
        instance = super(ScheduleForm, self).save(commit=False)
        weeks = self.cleaned_data['weeks'].split(',')  # etc
        if len(weeks) > 1:
            weeks.sort(key=int)
        instance.weeks = ','.join(weeks)
        if commit:
            instance.save()
        return instance

    def __init__(self, *args, **kwargs):
        super(ScheduleForm, self).__init__(*args, **kwargs)
        self.fields['trainees'].widget.attrs['class'] = 'select-fk'
        self.fields['parent_schedule'].widget.attrs['class'] = 'select-fk'
        self.fields['term'].widget.attrs['class'] = 'select-fk'
        self.fields['query_filter'].widget.attrs['class'] = 'select-fk'

    class Meta:
        model = Schedule
        exclude = []
Exemplo n.º 2
0
class BaseScheduleForm(forms.ModelForm):
  events = forms.ModelMultipleChoiceField(
    label='Events',
    queryset=Event.objects.all(),
    required=False,
    widget=FilteredSelectMultiple(
      "events", is_stacked=False)
  )

  weeks = CSIMultipleChoiceField(
    initial='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18',
    choices=Term.all_weeks_choices(),
    required=False,
    label='Weeks'
  )

  trainees = forms.ModelMultipleChoiceField(
    queryset=Trainee.objects.all(),
    label='Participating Trainees',
    required=False,
    widget=TraineeSelect2MultipleInput,
  )


  def __init__(self, *args, **kwargs):
    super(BaseScheduleForm, self).__init__(*args, **kwargs)
    self.fields['trainees'].widget.attrs['class'] = 'select-fk'
    self.fields['parent_schedule'].widget.attrs['class'] = 'select-fk'
    self.fields['term'].widget.attrs['class'] = 'select-fk'
    self.fields['term'].initial = Term.current_term()
    self.fields['season'].initial = 'All'
    self.fields['trainee_select'].initial = 'MA'
    self.fields['query_filter'].widget.attrs['class'] = 'select-fk'

  class Meta:
    model = Schedule
    exclude = []
Exemplo n.º 3
0
def home(request):
    user = request.user

    # Default for Daily Bible Reading
    current_term = Term.current_term()
    term_id = current_term.id

    try:
        # Do not set as user input.
        current_week = Term.current_term().term_week_of_date(date.today())
    except ValueError:
        current_week = 19
    term_week_code = str(term_id) + "_" + str(current_week)

    try:
        trainee_bible_reading = BibleReading.objects.get(trainee=user)
    except ObjectDoesNotExist:
        trainee_bible_reading = BibleReading(
            trainee=trainee_from_user(user),
            weekly_reading_status={term_week_code: EMPTY_WEEK_CODE_QUERY},
            books_read={})
        trainee_bible_reading.save()
    except MultipleObjectsReturned:
        return HttpResponse(
            'Multiple bible reading records found for trainee!')

    weekly_status = EMPTY_WEEKLY_STATUS
    finalized_str = UNFINALIZED_STR
    if term_week_code in trainee_bible_reading.weekly_reading_status:
        weekly_reading = trainee_bible_reading.weekly_reading_status[
            term_week_code]
        json_weekly_reading = json.loads(weekly_reading)
        weekly_status = str(json_weekly_reading['status'])
        finalized_str = str(json_weekly_reading['finalized'])

    data = {
        'daily_nourishment': Portion.today(),
        'user': user,
        'isTrainee': is_trainee(user),
        'trainee_info': BibleReading.weekly_statistics,
        'current_week': current_week,
        'weekly_status': weekly_status,
        'weeks': Term.all_weeks_choices(),
        'finalized': finalized_str,
        'weekday_codes': json.dumps(WEEKDAY_CODES)
    }
    notifications = get_announcements(request)
    for notification in notifications:
        tag, content = notification
        messages.add_message(request, tag, content)
    data['popups'] = get_popups(request)

    if is_trainee(user):
        trainee = trainee_from_user(user)
        # Bible Reading progress bar
        trainee_bible_reading = BibleReading.objects.filter(
            trainee=trainee).first()
        if trainee_bible_reading is None:
            data['bible_reading_progress'] = 0
        else:
            _, year_progress = BibleReading.calcBibleReadingProgress(
                trainee_bible_reading, user)
            data['bible_reading_progress'] = year_progress

    # condition for maintenance brothers
    elif is_TA(user) and user.has_group(['facility_maintenance'
                                         ]) and user.groups.all().count() == 1:
        data['house_requests'] = MaintenanceRequest.objects.all()
        data['request_status'] = MaintenanceRequest.STATUS

    return render(request, 'index.html', context=data)
Exemplo n.º 4
0
def home(request):
  user = request.user
  trainee = trainee_from_user(user)
  worker = None

  # Set default values
  current_week = 19
  weekly_status = EMPTY_WEEKLY_STATUS
  finalized_str = UNFINALIZED_STR
  designated_list = []
  assigned_list = []
  service_day = []

  # Default for Daily Bible Reading
  current_term = Term.current_term()
  term_id = current_term.id

  if is_trainee(user):
    worker = Worker.objects.get(trainee=user)

    if request.GET.get('week_schedule'):
      current_week = request.GET.get('week_schedule')
      current_week = int(current_week)
      current_week = current_week if current_week < LAST_WEEK else LAST_WEEK
      current_week = current_week if current_week > FIRST_WEEK else FIRST_WEEK
      cws = WeekSchedule.get_or_create_week_schedule(trainee, current_week)
    else:
      # Do not set as user input.
      current_week = Term.current_term().term_week_of_date(date.today())
      cws = WeekSchedule.get_or_create_week_schedule(trainee, current_week)

    # try:
    #   # Do not set as user input.
    #   current_week = Term.current_term().term_week_of_date(date.today())
    #   cws = WeekSchedule.get_or_create_week_schedule(trainee, current_week)

    # except ValueError:
    #   cws = WeekSchedule.get_or_create_current_week_schedule(trainee)

    term_week_code = str(term_id) + "_" + str(current_week)

    try:
      trainee_bible_reading = BibleReading.objects.get(trainee=user)
    except ObjectDoesNotExist:
      trainee_bible_reading = BibleReading(
        trainee=trainee_from_user(user),
        weekly_reading_status={term_week_code: EMPTY_WEEK_CODE_QUERY},
        books_read={})
      trainee_bible_reading.save()
    except MultipleObjectsReturned:
      return HttpResponse('Multiple bible reading records found for trainee!')

    if term_week_code in trainee_bible_reading.weekly_reading_status:
      weekly_reading = trainee_bible_reading.weekly_reading_status[term_week_code]
      json_weekly_reading = json.loads(weekly_reading)
      weekly_status = str(json_weekly_reading['status'])
      finalized_str = str(json_weekly_reading['finalized'])

    worker_assignments = worker.assignments.filter(week_schedule=cws)
    designated_list = list(service.encode("utf-8") for service in worker_assignments.filter(service__category__name="Designated Services").values_list('service__name', flat=True))
    assigned_list = list(service.encode("utf-8") for service in worker_assignments.exclude(service__category__name="Designated Services").values_list('service__name', flat=True))
    service_day = list(worker_assignments.exclude(service__category__name="Designated Services").values_list('service__weekday', flat=True))

  data = {
      'daily_nourishment': Portion.today(),
      'user': user,
      'worker': worker,
      'isTrainee': is_trainee(user),
      'trainee_info': BibleReading.weekly_statistics,
      'current_week': current_week,
      'weekly_status': weekly_status,
      'weeks': Term.all_weeks_choices(),
      'finalized': finalized_str,
      'weekday_codes': json.dumps(WEEKDAY_CODES),
      'service_day': json.dumps(service_day),
      'assigned_list': json.dumps(assigned_list),
      'designated_list': json.dumps(designated_list),
  }

  notifications = get_announcements(request)
  for notification in notifications:
    tag, content = notification
    messages.add_message(request, tag, content)
  data['popups'] = get_popups(request)

  if is_trainee(user):
    trainee = trainee_from_user(user)
    # Bible Reading progress bar
    trainee_bible_reading = BibleReading.objects.filter(trainee=trainee).first()
    if trainee_bible_reading is None:
      data['bible_reading_progress'] = 0
    else:
      _, year_progress = BibleReading.calcBibleReadingProgress(trainee_bible_reading, user)
      data['bible_reading_progress'] = year_progress

  # condition for maintenance brothers
  elif is_TA(user) and user.has_group(['facility_maintenance']) and user.groups.all().count() == 1:
    data['house_requests'] = MaintenanceRequest.objects.all()
    data['request_status'] = MaintenanceRequest.STATUS

  return render(request, 'index.html', context=data)