def clean(self):
        super(ResearchForm, self).clean()
        if 'start' in self.cleaned_data and 'end' in self.cleaned_data:
            if self.cleaned_data['start'] >= self.cleaned_data['end']:
                raise forms.ValidationError(_(u'The research start time should be less than end time.'))
            elif datetime.datetime.now() >= datetime.datetime.combine(self.cleaned_data['end'], datetime.time()):
                raise forms.ValidationError(_(u'The research end time should be more than current time.'))

        remind_scientist_info = json.loads(self.cleaned_data['remind_scientist_info'])
        remind_participant_info = json.loads(self.cleaned_data['remind_participant_info'])

        if remind_scientist_info and len(remind_scientist_info) > 0:
            for remind_scientist in remind_scientist_info:
                if is_integer(remind_scientist.get('time', 0)) <= 0:
                    raise forms.ValidationError(_(u'The scientist remind time can not be empty.'))

        if remind_participant_info and len(remind_participant_info) > 0:
            for remind_participant in remind_participant_info:
                if is_integer(remind_participant.get('time', 0)) <= 0:
                    raise forms.ValidationError(_(u'The participant remind time can not be empty.'))

        if 'is_feedback_promise' in self.cleaned_data and 'feedback_promise_time' in self.cleaned_data:
            if self.cleaned_data['is_feedback_promise'] and not self.cleaned_data['feedback_promise_time']:
                raise forms.ValidationError(_(u'Feedback promise time can not be empty.'))

        return self.cleaned_data
def scheme_assign_credit(request):
    try:
        scheme_id = request.POST.get('scheme_id', None)
        participant_id = request.POST.get('participant_id', None)
        assigned_credit = is_integer(request.POST.get('assigned_credit', 0))

        scheme = get_object_or_404(CreditScheme, id=scheme_id)
        scientist = get_object_or_404(ScientistCreditScheme, credit_scheme=scheme, scientist=request.user)
        participant = get_object_or_404(ParticipantCreditScheme, id=participant_id, credit_scheme=scheme)

        if assigned_credit < 0:
            result = {'status': 'fail', 'reason': 'remain credit can not assign to negative number'}
        elif assigned_credit > scientist.remain_credit:
            result = {'status': 'fail', 'reason': 'not enough remain credit'}
        else:
            scientist.remain_credit -= assigned_credit
            scientist.save()
            participant.incomplete_credit -= assigned_credit
            participant.save()
            SchemeCreditRecord(credit_scheme=scheme, scientist=scientist.scientist,
                               participant=participant.participant).save()
            result = {'status': 'success', 'scientist_remain_credit': scientist.remain_credit,
                      'participant_incomplete_credit': participant.incomplete_credit}
    except Exception as e:
        result = {'status': 'fail', 'reason': e.message}
    return json_result(request, result)
def resize_research_event(request):
    research_id = request.POST.get('research_id', None)
    event_id = request.POST.get('event_id', None)
    start_delta = request.POST.get('start_delta', None)
    end_delta = request.POST.get('end_delta', None)

    try:
        research = get_object_or_404(Research, id=research_id)
        event = get_object_or_404(ResearchEvent, id=event_id)
        if start_delta:
            event.start += datetime.timedelta(minutes=is_integer(start_delta))
        if end_delta:
            event.end += datetime.timedelta(minutes=is_integer(end_delta))
        if research.start > event.start:
            result = {'status': 'fail', 'reason': 'event start time can not before the start time of research'}
        elif research.end < event.end:
            result = {'status': 'fail', 'reason': 'event end time can not after the end time of research'}
        else:
            event.save()
            result = {'status': 'success'}
    except Exception as e:
        result = {'status': 'fail', 'reason': e.message}

    return json_result(request, result)
Exemple #4
0
    def __call__(index=None, *args):
        if not CLUB.playlist:
            raise IncorrectCommand('Плейлист пуст.')

        if index is None:
            CLUB.playing = 0

        else:
            playlist_length = 0 if CLUB.playlist_length == 1 else CLUB.playlist_length - 1
            if not is_integer(
                    index, only_positive=True) or int(index) > playlist_length:
                raise IncorrectCommand(
                    'В плейлисте нет трека под номером {}'.format(index))
            CLUB.playing = int(index)

        CLUB.update_persons_activities()
        print(CLUB)