コード例 #1
0
    def test_later_access_nowait(self):

        get_next_value()

        def one(output):
            output.append(("one", "begin"))
            with transaction.atomic():
                value = get_next_value()
                output.append(("one", value))
                time.sleep(0.5)
                output.append(("one", "commit"))
            connection.close()

        def two(output):
            time.sleep(0.1)
            output.append(("two", "begin"))
            with self.assertRaises(DatabaseError):
                with transaction.atomic():
                    value = get_next_value(nowait=True)
                    output.append(("two", value))  # shouldn't be reached
            connection.close()

        expected = [
            ("one", "begin"),
            ("one", 2),
            ("two", "begin"),
            ("one", "commit"),
        ]

        self.assertSequence(one, two, expected)
コード例 #2
0
def outbound(request, id=0):
    if 'is_login' not in request.session or request.session['limit'] <= datetime.datetime.today().strftime('%Y-%m-%d'):
        return redirect('login')
    else:
        if request.session['role'] == "OPR":
            raise PermissionDenied
        else:
            if request.method == "GET":
                if id == 0:
                    context = {
                        'form': OutboundForm(),
                        'title': 'Add Outbound | Outbound',
                        'customer': Customer.objects.filter(deleted=0, userGroup=request.session['usergroup']),
                        'date': datetime.datetime.now().strftime("%Y-%m-%d"),
                        'id_outbound_date': datetime.datetime.now().strftime("%d%m%Y"),
                        'id_outbound': get_last_value('outbound_seq'),
                        'role': request.session['role'],
                        'username': request.session['username'],
                        'group_id': request.session['usergroup'],
                        'con_cre': request.session['id'],
                    }
                    return render(request, 'inside/wmsOutbound/outbound.html', context)
                return render(request, 'inside/wmsOutbound/update_outbound.html', context)
            else:
                if id == 0:
                    form = OutboundForm(request.POST)
                if form.is_valid():
                    form.save()
                    if id == 0:
                        get_next_value('outbound_seq')
                    return redirect('outbound')
            return render(request, 'inside/wmsOutbound/outbound.html')
コード例 #3
0
    def test_later_access_to_different_sequences(self):

        get_next_value('one')
        get_next_value('two')

        def one(output):
            output.append(('one', 'begin'))
            with transaction.atomic():
                value = get_next_value('one')
                output.append(('one', value))
                time.sleep(0.2)
                output.append(('one', 'commit'))
            connection.close()

        def two(output):
            time.sleep(0.1)
            output.append(('two', 'begin'))
            with transaction.atomic():
                value = get_next_value('two')
                output.append(('two', value))
                output.append(('two', 'commit'))
            connection.close()

        expected = [
            ('one', 'begin'),
            ('one', 2),
            ('two', 'begin'),
            ('two', 2),
            ('two', 'commit'),
            ('one', 'commit'),
        ]

        self.assertSequence(one, two, expected)
コード例 #4
0
    def test_later_access_with_rollback(self):

        get_next_value()

        def one(output):
            output.append(("one", "begin"))
            with transaction.atomic():
                value = get_next_value()
                output.append(("one", value))
                time.sleep(0.2)
                transaction.set_rollback(True)
                output.append(("one", "rollback"))
            connection.close()

        def two(output):
            time.sleep(0.1)
            output.append(("two", "begin"))
            with transaction.atomic():
                value = get_next_value()
                output.append(("two", value))
                output.append(("two", "commit"))
            connection.close()

        expected = [
            ("one", "begin"),
            ("one", 2),
            ("two", "begin"),
            ("one", "rollback"),
            ("two", 2),
            ("two", "commit"),
        ]

        self.assertSequence(one, two, expected)
コード例 #5
0
 def test_probar_el_generador_de_secuencias(self):
     siguiente = get_next_value('nodosMenu')
     self.assertEqual(siguiente, 1)
     siguiente = get_next_value('nodosMenu')
     self.assertEqual(siguiente, 2)
     siguiente = get_next_value()
     self.assertEqual(siguiente, 1)
コード例 #6
0
    def test_later_access_with_rollback(self):

        get_next_value()

        def one(output):
            output.append(('one', 'begin'))
            with transaction.atomic():
                value = get_next_value()
                output.append(('one', value))
                time.sleep(0.2)
                transaction.set_rollback(True)
                output.append(('one', 'rollback'))
            connection.close()

        def two(output):
            time.sleep(0.1)
            output.append(('two', 'begin'))
            with transaction.atomic():
                value = get_next_value()
                output.append(('two', value))
                output.append(('two', 'commit'))
            connection.close()

        expected = [
            ('one', 'begin'),
            ('one', 2),
            ('two', 'begin'),
            ('one', 'rollback'),
            ('two', 2),
            ('two', 'commit'),
        ]

        self.assertSequence(one, two, expected)
コード例 #7
0
    def test_later_access_to_different_sequences(self):

        get_next_value("one")
        get_next_value("two")

        def one(output):
            output.append(("one", "begin"))
            with transaction.atomic():
                value = get_next_value("one")
                output.append(("one", value))
                time.sleep(0.2)
                output.append(("one", "commit"))
            connection.close()

        def two(output):
            time.sleep(0.1)
            output.append(("two", "begin"))
            with transaction.atomic():
                value = get_next_value("two")
                output.append(("two", value))
                output.append(("two", "commit"))
            connection.close()

        expected = [
            ("one", "begin"),
            ("one", 2),
            ("two", "begin"),
            ("two", 2),
            ("two", "commit"),
            ("one", "commit"),
        ]

        self.assertSequence(one, two, expected)
コード例 #8
0
def add(request):
    if request.method == "POST":
        add_form = ProjectForm(request.POST)
        if add_form.is_valid():
            start_date = add_form.cleaned_data['start_date']
            project_no = add_form.cleaned_data['project_no']
            project_name = add_form.cleaned_data['project_name']
            protype_code = add_form.cleaned_data['protype_code'].PROTYPE_CODE
            language_code = add_form.cleaned_data['language_code'].LANGUAGE_CODE
            summary = add_form.cleaned_data['summary']
            status_code = add_form.cleaned_data['status_code'].STATUS_CODE
            customer = add_form.cleaned_data['customer']
            charge = add_form.cleaned_data['charge']
            reviewer = add_form.cleaned_data['reviewer']
            release_date = add_form.cleaned_data['release_date']
            remarks = add_form.cleaned_data['remarks']
            message_add = ""
            if not isdateformat(start_date):
                message_add = "発生日は yyyy/MM/dd の形式で入力してください。\n"
            elif not isdate(start_date):
                message_add = "発生日は カレンダーに存在しない日付です。\n"
            if protype_code == "":
                message_add = message_add + "工程区分が選択されていません。\n"
            if language_code == "":
                message_add = message_add + "開発言語が選択されていません。\n"
            if status_code == "":
                message_add = message_add + "状態が選択されていません。\n"
            if release_date != "":
                if not isdateformat(release_date):
                        message_add = message_add + "リリース日は yyyy/MM/dd の形式で入力してください。\n"
                elif not isdate(release_date):
                        message_add = message_add + "リリース日はカレンダーに存在しない日付です。\n"
            #try:
                #incident = models.Project.objects.get(PROJECT_ID=9999)
            if Sequence.objects.get(name="festival_classification_seq").last >= 9999:
                message_add = "登録可能な一連番号が無いため、登録を行えません。"
            #except Exception:
                #pass
            if not message_add:
                start_date = datetime.datetime.strptime(start_date, '%Y/%m/%d').strftime('%Y-%m-%d')
                if release_date != "":
                    release_date = datetime.datetime.strptime(release_date, '%Y/%m/%d').strftime('%Y-%m-%d')
                    models.Project.objects.create(PROJECT_ID=get_next_value('festival_classification_seq'),
                                                  START_DATE=start_date, PROJECT_NO=project_no,
                                                  PROJECT_NAME=project_name, PROTYPE_CODE_id=protype_code,
                                                  LANGUAGE_CODE_id=language_code, SUMMARY=summary,
                                                  STATUS_CODE_id=status_code, CUSTOMER=customer, CHARGE=charge,
                                                  REVIEWER=reviewer, RELEASE_DATE=release_date, REMARKS=remarks)
                    return redirect('/add/')
                else:
                    models.Project.objects.create(PROJECT_ID=get_next_value('festival_classification_seq'),
                                                  START_DATE=start_date, PROJECT_NO=project_no,
                                                  PROJECT_NAME=project_name, PROTYPE_CODE_id=protype_code,
                                                  LANGUAGE_CODE_id=language_code, SUMMARY=summary,
                                                  STATUS_CODE_id=status_code, CUSTOMER=customer, CHARGE=charge,
                                                  REVIEWER=reviewer, REMARKS=remarks)
                    return redirect('/add/')
        return render(request, 'add.html', locals())
    add_form = ProjectForm()
    return render(request, 'add.html', locals())
コード例 #9
0
 def test_functions_defaults(self):
     self.assertEqual(get_last_value(), None)
     self.assertEqual(get_next_value(), 1)
     self.assertEqual(get_last_value(), 1)
     self.assertEqual(get_next_value(), 2)
     self.assertEqual(get_last_value(), 2)
     self.assertEqual(get_next_value(), 3)
コード例 #10
0
 def test_functions_sequence_name(self):
     self.assertEqual(get_last_value("cases"), None)
     self.assertEqual(get_next_value("cases"), 1)
     self.assertEqual(get_last_value("cases"), 1)
     self.assertEqual(get_next_value("cases"), 2)
     self.assertEqual(get_last_value("invoices"), None)
     self.assertEqual(get_next_value("invoices"), 1)
     self.assertEqual(get_last_value("invoices"), 1)
     self.assertEqual(get_next_value("invoices"), 2)
コード例 #11
0
def subcategory(request, id=0):
    if 'is_login' not in request.session or request.session[
            'limit'] <= datetime.datetime.today().strftime('%Y-%m-%d'):
        return redirect('login')
    else:
        if request.session['role'] == "OPR":
            raise PermissionDenied
        else:
            if request.method == "GET":
                if id == 0:
                    context = {
                        'form':
                        SubcategoryForm(),
                        'category':
                        Category.objects.get(pk=request.session['category']),
                        'subcategory_id':
                        get_last_value('subcategory_seq'),
                        'group_id':
                        request.session['usergroup'],
                        'role':
                        request.session['role'],
                        'username':
                        request.session['username'],
                        'title':
                        'Add Subcategory | Inbound'
                    }
                    return render(request,
                                  'inside/wmsInbound/subcategoryCreate.html',
                                  context)
                else:
                    subcategory = Subcategory.objects.get(pk=id)
                    context = {
                        'form': SubcategoryForm(instance=subcategory),
                        'subcategory': subcategory,
                        'role': request.session['role'],
                        'group_id': request.session['usergroup'],
                        'username': request.session['username'],
                        'title': 'Update Subcategory | Inbound'
                    }
                    return render(request,
                                  'inside/wmsInbound/subcategoryUpdate.html',
                                  context)
            else:
                if id == 0:
                    form = SubcategoryForm(request.POST)
                else:
                    subcategory = Subcategory.objects.get(pk=id)
                    form = SubcategoryForm(request.POST, instance=subcategory)
                if form.is_valid():
                    form.save()
                    if id == 0:
                        get_next_value('subcategory_seq')
                    return redirect('subcategoryIndex',
                                    id=request.session['category'])
コード例 #12
0
def register(request):
    if request.method == "GET":
        context = {
            'title': 'Register Akun',
            'id': get_last_value('usergroup_seq'),
            'provinsi': Province.objects.all(),
        }
        return render(request, "inside/wmsGroup/register.html", context)
    elif request.method == "POST":
        if UserGroup.objects.filter(email=request.POST['email']).exists():
            messages.error(request, 'Email already exists')
            return redirect('groupRegister')
        else:
            form = UserGroupForm(request.POST, request.FILES)
            if form.is_valid():
                form.save()
                man_user = User.objects.create(
                    name='MAN_'+request.POST['name'],
                    username=request.POST['email'],
                    password=request.POST['password'],
                    userGroup=UserGroup.objects.get(pk=request.POST['id']),
                    role=Role.objects.get(pk='MAN')
                )
                man_user.save()
                get_next_value('usergroup_seq')
                email = urlsafe_base64_encode(force_bytes(request.POST['email']))
                domain = get_current_site(request).domain
                token = token_generator.make_token(request.POST['phoneNumber'])
                link = reverse('activate', kwargs={'email': email, 'token': token})
                usergroup = UserGroup.objects.filter(email=request.POST['email'])
                usergroup.update(token=token)
                activate_url = 'http://'+domain+link

                email_subject = 'Activate WMS Polpos account'
                email_body = 'Hello '+request.POST['name']+' link activate is '+activate_url
                email = EmailMessage(
                    email_subject,
                    email_body,
                    settings.EMAIL_HOST_USER,
                    [request.POST['email']],
                )
                email.send(fail_silently=False)
                return redirect('login')
            else:
                messages.error(request, 'Terjadi Error')
                return redirect('groupRegister')
    else:
        context = {
            'title': 'Register Akun',
            'ug': UserGroup.objects.get(pk=request.session['usergroup'])
        }
        return render(request, "inside/wmsGroup/register.html", context)
コード例 #13
0
ファイル: test_api.py プロジェクト: raultr/CarmesiAnt
    def setUp(self):
       #import ipdb;ipdb.set_trace()
       if self.setup_done:
            return
       self.utilt = UtileriasParametroTest()
       #self.client = APIClient()
       self.menu = MenuFactory() #Menu.objects.create(nombre="Menu1")
       get_next_value('nodosMenu', initial_value=0)

       #self.staging_server = os.environ.get('STAGING_SERVER')
       #if not self.staging_server:
       #     self.staging_server = self.LOCAL_HOST

       self.base_url = f'{self.staging_server}{self.base_url}'
コード例 #14
0
    def create(self, validated_data):
        user = self.context['request'].user
        extended_user = self.get_person_manager_extended_user(user=user)

        validated_data['customer'] = extended_user.customer

        generator = IBANGenerator()

        with transaction.atomic():
            iban_sequence = get_next_value('iban_sequence')
            iban = generator.generate(
                country_code='BG',
                bank=Account.DJANGO_BANK_BIC,
                account=
                f"{validated_data['product'].code[:2]}{validated_data['currency'].code}{iban_sequence:05d}"
            )

        validated_data['iban'] = iban['generated_iban']

        validated_data['balance'] = randint(1, 77) * 1000

        instance = Account.objects.create(**validated_data)

        instance.users.add(user)

        return instance
コード例 #15
0
    def test_crear_nodomenu_con_etiqueta_mayor_a_su_longitud_permitida(self):
        siguiente = get_next_value('nodosMenu')
        self.assertEquals(siguiente, 1)

        etiqueta = 'a' * 100

        with self.assertRaises(ValidationError) as cm:
            nodo_padre1 = NodoMenuFactoryUtils.crear_nodo_menu(
                id=None, nodo_padre=None, menu=self.menu, etiqueta=etiqueta)

        error = cm.exception
        self.assertEquals(
            error.messages[0], 'La longitud maxima es de '
            '60 caracteres (tiene 100)')
        siguiente = get_next_value('nodosMenu')
        self.assertEquals(siguiente, 2)
コード例 #16
0
 def test_functions_reset_value(self):
     self.assertEqual(get_next_value("reference", reset_value=3), 1)
     self.assertEqual(get_next_value("reference", reset_value=3), 2)
     self.assertEqual(get_next_value("reference", reset_value=3), 1)
     self.assertEqual(get_next_value("reference", reset_value=3), 2)
     self.assertEqual(get_next_value("reference", 1, 3), 1)
     self.assertEqual(get_next_value("reference", 1, 3), 2)
     self.assertEqual(get_next_value("reference", 1, 3), 1)
     self.assertEqual(get_next_value("reference", 1, 3), 2)
コード例 #17
0
def rack(request):
    if 'is_login' not in request.session or request.session[
            'limit'] <= datetime.datetime.today().strftime('%Y-%m-%d'):
        return redirect('login')
    else:
        if request.session['role'] == 'OPR':
            raise PermissionDenied
        else:
            if request.method == "GET":
                context = {
                    'form': RackForm(),
                    'role': request.session['role'],
                    'group_id': request.session['usergroup'],
                    'username': request.session['username'],
                    'id': get_last_value('rack_seq'),
                    'title': 'Add Rack',
                }
                return render(request, 'inside/wmsStorage/rackCreate.html',
                              context)
            else:
                if Rack.objects.filter(rack=request.POST['rack'],
                                       userGroup=request.session['usergroup'],
                                       deleted=0).exists():
                    messages.error(request, 'Rack ID has been used')
                    return redirect('rackCreate')
                else:
                    form = RackForm(request.POST)
                    if form.is_valid():
                        form.save()
                        numberbin = int(request.POST['row']) * int(
                            request.POST['col'])
                        data_bin = []
                        for i in range(int(numberbin)):
                            binlocation = request.POST['rack'] + (str(i + 1))
                            data_bin.append(
                                Binlocation(
                                    binlocation=binlocation,
                                    rack=Rack.objects.get(
                                        pk=request.POST['id']),
                                    capacity=request.POST['capacity'],
                                    userGroup=UserGroup.objects.get(
                                        pk=request.session['usergroup'])))
                        Binlocation.objects.bulk_create(data_bin)
                        get_next_value('rack_seq')
                        return redirect('rackIndex')

            return render(request, 'inside/wmsStorage/rackIndex.html')
コード例 #18
0
 def two(output):
     time.sleep(0.1)
     output.append(("two", "begin"))
     with transaction.atomic():
         value = get_next_value("two")
         output.append(("two", value))
         output.append(("two", "commit"))
     connection.close()
コード例 #19
0
 def one(output):
     output.append(("one", "begin"))
     with transaction.atomic():
         value = get_next_value("one")
         output.append(("one", value))
         time.sleep(0.2)
         output.append(("one", "commit"))
     connection.close()
コード例 #20
0
 def one(output):
     output.append(('one', 'begin'))
     with transaction.atomic():
         value = get_next_value('one')
         output.append(('one', value))
         time.sleep(0.2)
         output.append(('one', 'commit'))
     connection.close()
コード例 #21
0
 def two(output):
     time.sleep(0.1)
     output.append(('two', 'begin'))
     with transaction.atomic():
         value = get_next_value('two')
         output.append(('two', value))
         output.append(('two', 'commit'))
     connection.close()
コード例 #22
0
ファイル: models.py プロジェクト: kapiak/ware_prod
    def save(self, **kwargs):
        self.clean()
        if not self.order:
            order = Order.objects.create(
                number=get_next_value("order_number", initial_value=10000))
            self.order = order

        return super().save(**kwargs)
コード例 #23
0
 def two(output):
     time.sleep(0.1)
     output.append(("two", "begin"))
     with self.assertRaises(DatabaseError):
         with transaction.atomic():
             value = get_next_value(nowait=True)
             output.append(("two", value))  # shouldn't be reached
     connection.close()
コード例 #24
0
ファイル: models.py プロジェクト: cuhong/medexpense
 def set_serial(self):
     if self.serial:
         return None
     claim_serial = self.claim.serial
     sequence = get_next_value(claim_serial)
     serial = f"{claim_serial}-{str(sequence).zfill(3)}"
     self.serial = serial
     self.save()
コード例 #25
0
ファイル: models.py プロジェクト: cuhong/medexpense
 def set_serial(self):
     if self.serial:
         return None
     dt = self.registered_at.strftime('%Y%m%d')
     sequence = get_next_value(dt)
     serial = f"{dt}-{str(sequence).zfill(5)}"
     self.serial = serial
     self.save()
コード例 #26
0
def supplier(request, id=0):
    if 'is_login' not in request.session or request.session[
            'limit'] <= datetime.datetime.today().strftime('%Y-%m-%d'):
        return redirect('login')
    else:
        if request.session['role'] == "OPR":
            raise PermissionDenied
        else:
            if request.method == "GET":
                if id == 0:
                    context = {
                        'form': SupplierForm(),
                        'id_supplier': get_last_value('supplier_seq'),
                        'group_id': request.session['usergroup'],
                        'username': request.session['username'],
                        'role': request.session['role'],
                        'title': 'Add Supplier | Inbound'
                    }
                    return render(request, 'inside/wmsInbound/supplier.html',
                                  context)
                else:
                    supplier = Supplier.objects.get(pk=id)
                    context = {
                        'form': SupplierForm(instance=supplier),
                        'supplier': supplier,
                        'group_id': request.session['usergroup'],
                        'username': request.session['username'],
                        'role': request.session['role'],
                        'title': 'Update Supplier | Inbound'
                    }
                return render(request,
                              'inside/wmsInbound/update_supplier.html',
                              context)
            else:
                if id == 0:
                    form = SupplierForm(request.POST)
                else:
                    supplier = Supplier.objects.get(pk=id)
                    form = SupplierForm(request.POST, instance=supplier)
                if form.is_valid():
                    form.save()
                    if id == 0:
                        get_next_value('supplier_seq')
                    return redirect('list_supplier')
            return render(request, 'inside/wmsInbound/supplier.html')
コード例 #27
0
 def gera_protocolo_analise_sensorial(self):
     id_sequecial = str(get_next_value('protocolo_analise_sensorial'))
     serial = ''
     for _ in range(MAX_NUMERO_PROTOCOLO - len(id_sequecial)):
         serial = serial + '0'
     serial = serial + str(id_sequecial)
     self.protocolo_analise_sensorial = f'AS{serial}'
     self.necessita_analise_sensorial = True
     self.save()
コード例 #28
0
 def one(output):
     output.append(('one', 'begin'))
     with transaction.atomic():
         value = get_next_value()
         output.append(('one', value))
         time.sleep(0.2)
         transaction.set_rollback(True)
         output.append(('one', 'rollback'))
     connection.close()
コード例 #29
0
 def one(output):
     output.append(("one", "begin"))
     with transaction.atomic():
         value = get_next_value()
         output.append(("one", value))
         time.sleep(0.2)
         transaction.set_rollback(True)
         output.append(("one", "rollback"))
     connection.close()
コード例 #30
0
    def generate_number(self):
        if self.number:
            return self.number

        with transaction.atomic():
            self.number = get_next_value("invoice_numbers", initial_value=1000000)
            self.save()

        return self.number
コード例 #31
0
ファイル: views.py プロジェクト: raultr/carrera
	def perform_create(self, serializer):
		with transaction.atomic():
			num_sig = Consecutivo.objects.get(llave=self.request.data['genero'])
			serializer.save(numero=get_next_value(num_sig.nombre_secuencia, initial_value=num_sig.valor_inicial))
コード例 #32
0
ファイル: models.py プロジェクト: emory-libraries/pidman
 def next_sequence_value(cls):
     return get_next_value(cls.SEQUENCE_NAME)