Beispiel #1
0
 def test_CommaSeparatedIntegerField(self):
     lazy_func = lazy(lambda: '1,2', six.text_type)
     self.assertIsInstance(
         CommaSeparatedIntegerField().get_prep_value(lazy_func()),
         six.text_type)
     lazy_func = lazy(lambda: 0, int)
     self.assertIsInstance(
         CommaSeparatedIntegerField().get_prep_value(lazy_func()),
         six.text_type)
Beispiel #2
0
class Diem(models.Model):
    sinh_vien=ForeignKey(SinhVien,
                         blank=False, null=False, 
                         verbose_name="Sinh viên")
    mon_thi = ForeignKey(MonThi,
                         blank=False, null=False,
                         verbose_name="Môn thi")
    
    trang_thai_thi = CharField(max_length=20,
                               choices=TRANG_THAI_THI,
                               default='DA_THI',
                               verbose_name='Trạng thái thi')
    
    diem=CommaSeparatedIntegerField(max_length=5, blank=True, null=True,
                              verbose_name="Điểm")
    class Meta:
        unique_together = (('sinh_vien', 'mon_thi'),)
        verbose_name = "Điểm"
        verbose_name_plural = "Bảng điểm"
Beispiel #3
0
class Binding(models.Model):
    data_form = models.ForeignKey('DataForm')
    field = models.ForeignKey('Field')
    field_choice = models.ForeignKey(
        'FieldChoice',
        blank=True,
        null=True,
        help_text=
        'Optionally narrow down to a choice on this field if available.')
    operator = models.CharField(max_length=255,
                                choices=BINDING_OPERATOR_CHOICES)
    value = models.CharField(
        max_length=255,
        blank=True,
        help_text="Required if a Operator is equal to 'checked'.")

    true_field = SeparatedValuesField(blank=True)
    true_choice = SeparatedValuesField(blank=True)

    false_field = SeparatedValuesField(blank=True)
    false_choice = SeparatedValuesField(blank=True)

    action = models.CharField(max_length=255,
                              choices=BINDING_ACTION_CHOICES,
                              default='show-hide')
    function = models.CharField(
        max_length=255,
        blank=True,
        help_text="Required if Action is equal to 'Function'.")

    additional_rules = CommaSeparatedIntegerField(max_length=200, blank=True)

    def clean(self):
        # Field requires a Operator and Value
        if self.operator != 'checked' and not self.value:
            raise ValidationError(
                "A Value is required if the Operator is not equal to 'checked'."
            )

        if self.field_choice and self.operator != 'checked':
            raise ValidationError(
                "Operator must be equal to 'checked of Field Choice is selected."
            )

        # A field or choice is required
        if (not self.true_field and not self.true_choice
                and not self.false_field and not self.field_choice):
            raise ValidationError('A Field or Choice is required.')

        # If action is function, then a function is needed
        if self.action == 'function' and not self.function:
            raise ValidationError(
                'A function is required if action is function.')

        # If additional rules are applied, then the rules cannot be the same as current record
        if self.additional_rules and unicode(self.id) in self.additional_rules:
            raise ValidationError(
                'You cannot apply the current rule to additional rules.')

    def __unicode__(self):
        return '%s' % self.pk

    class Meta:
        verbose_name = 'Field Binding'
        verbose_name_plural = 'Field Bindings'
Beispiel #4
0
class CaThi(models.Model):
    '''
    Thiet lap mot ca thi, trong do co danh sach cau hoi de tu do lam
    cac de thi cho tung sinh vien
    '''
    title = CharField(verbose_name="Ca thi", max_length=200, blank=False)
    
    description=TextField(verbose_name="Ghi chú", blank=True, null=True)
    mon_thi = ForeignKey(MonThi, blank=False, null=False,
                         verbose_name="Môn thi")
#     lop_thi = ForeignKey(Lop, blank=False, null=False,
#                          verbose_name="Lớp thi")
#     ds_thisinh = ForeignKey(Lop_CaThi, blank=False, null=False, 
#                          verbose_name="Danh sách thí sinh")
    ds_giamthi = ManyToManyField(GiaoVien, verbose_name=u'Danh sách giám thị coi thi')
    
    ds_thisinh = ManyToManyField(SinhVien, blank=False, 
                                verbose_name=u"Danh sách thí sinh")
    ds_thisinh.help_text = 'Tìm kiếm theo họ tên sinh viên hoặc mã lớp.'
    
    ngay_thi = DateField(verbose_name="Ngày thi")
    tg_bat_dau=TimeField(verbose_name="Thời gian bắt đầu")
    tg_ket_thuc=TimeField(verbose_name="Thời gian kết thúc")
    
    ds_cau_hoi = CommaSeparatedIntegerField(max_length=1024, 
                                            verbose_name="Danh sach cau hoi (ids)")
#     setting = ManyToManyField(QuestionGroup_Setting, 
#                             verbose_name="Thiết lập cấu hình ca thi")
    tao_moi_de_thi = BooleanField(blank=False, null=False,
                                  verbose_name="Tạo mới đề thi cho các sinh viên",
                                  default=True)
    
    random_order = BooleanField(blank=False, null=False,
                                verbose_name="Hiển thị câu hỏi ngẫu nhiên",
                                default=True)
    answers_at_end = BooleanField(blank=False, null=False,
                                  verbose_name="Hiển thị câu trả lời khi kết thúc",
                                  default=False)
    result_at_end = BooleanField(blank=False, null=False,
                               verbose_name="Hiển thị kết quả khi kết thúc",
                               default=True)
    exam_paper = BooleanField(blank=False, null=False,
                              verbose_name="Lưu bài thi",
                              default=True)
    single_attempt = BooleanField(blank=False, null=False,
                                  verbose_name="Mỗi người một đề thi",
                                  default=True)
    pass_mark = PositiveIntegerField(verbose_name="Điểm đạt yêu cầu")
    success_text = TextField(blank=True,
                             verbose_name="Thông báo được hiển thị nếu thí sinh vượt qua")
    fail_text = TextField(blank=True,
                          verbose_name="Thông báo được hiển thị nếu thí sinh không vượt qua")
    draft=BooleanField(verbose_name="Bản nháp", 
                       default=False)
    
    class Meta:
        verbose_name = "Ca thi"
        verbose_name_plural = "Danh sách ca thi"

    def __unicode__(self):
        return u'%s' %(self.title)
    
    def save(self, *args, **kwargs):
        # luu CaThi va Cathi_Setting
#         super(CaThi, self).save(*args, **kwargs)
#         # lay danh sach cau hoi cho ca thi
#         # lay cathi_setting
        questionGroup_settings = QuestionGroup_Setting.objects.filter(ca_thi__exact=self)
#         # cac cau hoi cua de thi
        questions = []
        for cathi_setting in questionGroup_settings:
            # lay cau hoi theo nhom va loai (type)
            qs = Question.objects.filter(mon_thi=self.mon_thi,
                                    question_type = cathi_setting.question_type,
                                    question_group = cathi_setting.question_group)
            # lay id
            q_ids = qs.values_list('id', flat=True)
            # lay ngau nhien so cau hoi
             
            questions += sample(q_ids, cathi_setting.num_of_questions)
         
        self.ds_cau_hoi = ','.join(map(str, questions)) + ","
         
        # luu CaThi-ds_cauhoi
        super(CaThi, self).save(*args, **kwargs)
        # tao de thi cho tung sinh vien
 
        # lay danh sach sinh vien cua lop
#         dsSV = SinhVien.objects.filter(lop=self.lop_thi)
        dsSV = self.ds_thisinh.all()
         
        if(self.tao_moi_de_thi == False):
            return
         
        # voi moi sinh vien, tao mot de thi
        for sv in dsSV:
            # tao de thi
            dethi = DeThi.objects.update_or_create(sinh_vien=sv,
                                                   ca_thi=self,
                                                   )[0]
            # lay ngau nhien cau hoi trong ngan hang de
            ds_cauhoi = sample(questions, len(questions))
            ds_cauhoi_answer = []
            for cauhoi_id in ds_cauhoi:
                # lay cau hoi voi id tuong ung
                q = Question.objects.get(id=cauhoi_id)
                # neu cau hoi la multichoice question thi hoan doi thu tu
                # cau tra loi
                if q.question_type == MCQUESTION:
                    # lay cac cau tra loi cua cau hoi nay
#                     q = (MCQuestion)q
                     
#                     answers = Answer.objects.filter(question=q.id)
                    q.__class__ = MCQuestion
                    answers = q.getAnswers()
                     
                    # lay id cua cac cau hoi
                    answer_ids = answers.values_list('id', flat=True)
                     
                    # dao thu tu cau tra loi
                    answer_ids = sample(answer_ids, len(answer_ids))
                     
                    # add vao mot dictionary
                    ds_cauhoi_answer.append((cauhoi_id, answer_ids))
                 
                elif q.question_type == TFQUESTION:
                    ds_cauhoi_answer.append((cauhoi_id, [1, 0]))
                 
                else:
                    ds_cauhoi_answer.append((cauhoi_id, []))
                     
            dethi.ds_cau_hoi =  json.dumps(ds_cauhoi_answer)
            dethi.save()                             
Beispiel #5
0
 def test_CommaSeparatedIntegerField(self):
     self.assertIsInstance(
         CommaSeparatedIntegerField().get_prep_value('1,2'), six.text_type)
     self.assertIsInstance(CommaSeparatedIntegerField().get_prep_value(0),
                           six.text_type)
Beispiel #6
0
 def test_CommaSeparatedIntegerField(self):
     self.assertIsInstance(CommaSeparatedIntegerField().get_prep_value('1,2'), str)
     self.assertIsInstance(CommaSeparatedIntegerField().get_prep_value(0), unicode)