Пример #1
0
 def dataExist(self, action='insert', **kwargs):
     data = super(NA_BR_Supplier, self).get_queryset()
     supplier_code = kwargs.get('suppliercode')
     hp = kwargs.get('hp')
     telp = kwargs.get('telp')
     if supplier_code and hp and telp is not None:
         exists = data.filter(suppliercode=supplier_code, hp=hp,
                              telp=telp).exists()
         if exists:
             return (True, Message.Exists.value)
     if supplier_code is not None:
         exist_supCode = data.filter(suppliercode=supplier_code).exists()
         if exist_supCode:
             return (True,
                     Message.get_specific_exists('Supplier',
                                                 'supplier code',
                                                 supplier_code))
     if hp and telp is not None:
         sup_code = supplier_code
         if action == 'update':
             sup_code = kwargs.get('_exclude_supplierCode')
         exist_hp = data.exclude(suppliercode=sup_code).filter(
             hp=hp).exists()
         if exist_hp:
             return (True,
                     Message.get_specific_exists('Supplier', 'HP', hp))
         exist_telp = data.exclude(suppliercode=sup_code).filter(
             telp=telp).exists()
         if exist_telp:
             return (True,
                     Message.get_specific_exists('Supplier', 'Telp', telp))
     return (False, )
 def dataExist(self, **kwargs):
     idapp = kwargs.get('idapp')
     if idapp is not None:
         return super(NA_BR_Employee,
                      self).get_queryset().filter(idapp=idapp).exists()
     nik = kwargs.get('nik')
     if nik is not None:
         is_nik = super(NA_BR_Employee,
                        self).get_queryset().filter(nik=get_nik).exists()
         if is_nik:
             return (True,
                     Message.get_specific_exists('Employee', 'Nik', nik))
     telphp = kwargs.get('telphp')
     if telphp is not None:
         is_telp = super(
             NA_BR_Employee,
             self).get_queryset().filter(telphp=telphp).exists()
         if is_telp:
             return (True,
                     Message.get_specific_exists('Employee', 'Telp/HP',
                                                 telphp))
     return (False, )
Пример #3
0
    def handle_data_exists(cls, err):
        """
        only for Django ORM
        :param err:     -- instance of NAError
        :return:        -- tuple of Data and Message error for user
        """

        instance = err.kwargs.get('instance')
        error_column = cls.retrieve_integrity_column(err=err.message)
        error_field = cls.retrieve_integrity_field(
            column=error_column,
            model=instance._meta.model
        )
        field_display = instance.HUMAN_DISPLAY.get(error_field)
        data = (Data.Exists, Message.get_specific_exists(
            table=instance._meta.model.FORM_NAME,
            column=field_display,
            data=getattr(instance, error_field)
        ))
        return data