Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        if 'request' in kwargs.keys():
            request = kwargs['request']
            del kwargs['request']
        else:
            return
        super(OrderForm, self).__init__(*args, **kwargs)
        _, data = list_request(request, 'get_service_types')
        self.fields['service_type_id'].choices = [
            (int(element[0]), ' '.join(map(str, element[1:])))
            for element in data
        ]

        _, data = list_request(request, 'get_bonuses')
        self.fields['service_bonus_id'].choices = [(int(element[0]),
                                                    ' '.join(map(str, element[1:]))) for element in data]\
                                                  + [(None, "None")]

        _, data = list_request(request, 'get_clients')
        self.fields['client_id'].choices = [(int(element[0]),
                                             ' '.join(map(str, element[1:])))
                                            for element in data]

        _, data = list_request(request, 'get_discount_types')
        self.fields['discount_type_id'].choices = [(int(element[0]),
                                                    ' '.join(map(str, element[1:]))) for element in data]\
                                                + [(None, "None")]

        _, data = list_request(request, 'get_offices')
        self.fields['office_id'].choices = [(int(element[0]),
                                             ' '.join(map(str, element[1:])))
                                            for element in data]
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        if 'request' in kwargs.keys():
            request = kwargs['request']
            del kwargs['request']
        else:
            return
        super(OrderForm, self).__init__(*args, **kwargs)
        _, data = list_request(request, 'get_service_types')
        self.fields['service_type_id'].choices = [(int(element[0]),
                                                   ' '.join(map(str, element[1:]))) for element in data]

        _, data = list_request(request, 'get_bonuses')
        self.fields['service_bonus_id'].choices = [(int(element[0]),
                                                    ' '.join(map(str, element[1:]))) for element in data]\
                                                  + [(None, "None")]

        _, data = list_request(request, 'get_clients')
        self.fields['client_id'].choices = [(int(element[0]),
                                             ' '.join(map(str, element[1:]))) for element in data]

        _, data = list_request(request, 'get_discount_types')
        self.fields['discount_type_id'].choices = [(int(element[0]),
                                                    ' '.join(map(str, element[1:]))) for element in data]\
                                                + [(None, "None")]

        _, data = list_request(request, 'get_offices')
        self.fields['office_id'].choices = [(int(element[0]), ' '.join(map(str, element[1:]))) for element in data]
Exemplo n.º 3
0
def services(request):
    row_names, data = list_request(request, 'get_service_types')
    extra_thing = None
    if 'connection' in request.COOKIES and request.COOKIES['connection'] == 'admin':
        extra_thing = {'url': 'django_app:update_service', 'text': 'Edit service'}
    return render(request, 'django_app/service_types_list.html',
                  {"headers": row_names, "data": data, "extra_thing": extra_thing})
Exemplo n.º 4
0
def client_orders(request, client_id):
    row_names, data = list_request(request, 'client_orders', [int(client_id)])
    is_ready_index = row_names.index('Is ready')
    data = convert_to_type(data, bool, is_ready_index)

    return render(request, 'django_app/client_orders_list.html',
                  {"headers": row_names, "data": data})
Exemplo n.º 5
0
def get_order_info(request, order_id):
    row_names, data = list_request(request, 'get_order_info', [int(order_id)])
    is_ready_index = row_names.index('Is ready')

    data = convert_to_type(data, bool, is_ready_index)
    return render(request, 'django_app/order_status.html',
                  {"headers": row_names, "data": data})
Exemplo n.º 6
0
def get_offices(request):
    row_names, data = list_request(request, 'get_offices')
    extra_thing = None
    if 'connection' in request.COOKIES and request.COOKIES['connection'] == 'admin':
        extra_thing = {'url': 'django_app:update_office', 'text': 'Update office'}
    return render(request, 'django_app/list_template.html',
                  {"headers": row_names, "data": data, 'extra_thing': extra_thing})
Exemplo n.º 7
0
def get_discounts(request):
    row_names, data = list_request(request, 'get_discount_types')
    extra_thing = None
    if 'connection' in request.COOKIES and request.COOKIES['connection'] == 'admin':
        extra_thing = {'url': 'django_app:update_discount', 'text': 'Update discount'}
    return render(request, 'django_app/list_template.html', {'data': data, 'headers': row_names,
                                                             'extra_thing': extra_thing})
Exemplo n.º 8
0
def client_info(request, client_id):
    row_names, data = list_request(request, 'client_info', [int(client_id)])
    is_ready_index = row_names.index('Best client')
    data = convert_to_type(data, bool, is_ready_index)

    return render(request, 'django_app/client_info.html',
                  {"headers": row_names, "data": data,
                   'extra_thing': {'url': 'django_app:update_client', 'text': 'Update client'}
                   })
Exemplo n.º 9
0
def client_orders_ready_not_returned(request, client_id):
    row_names, data = list_request(request, 'ready_not_returned', [int(client_id)])
    is_ready_index = row_names.index('Is ready')
    data = convert_to_type(data, bool, is_ready_index)

    extra_thing = None
    if 'connection' in request.COOKIES and request.COOKIES['connection'] == 'worker':
        extra_thing = {'url': 'django_app:return_order', 'text': 'Return'}
    return render(request, 'django_app/orders_ready_not_returned_list.html',
                  {"headers": row_names, "data": data, 'extra_thing': extra_thing})
Exemplo n.º 10
0
 def __init__(self, *args, **kwargs):
     if 'request' in kwargs.keys():
         request = kwargs['request']
         del kwargs['request']
     else:
         return
     super(CreateUserForm, self).__init__(*args, **kwargs)
     _, roles = list_request(request, 'get_roles')
     roles_as_list = map(lambda x: x[0], roles)
     self.fields['role'].choices = zip(roles_as_list, roles_as_list)
Exemplo n.º 11
0
 def __init__(self, *args, **kwargs):
     if 'request' in kwargs.keys():
         request = kwargs['request']
         del kwargs['request']
     else:
         return
     super(CreateUserForm, self).__init__(*args, **kwargs)
     _, roles = list_request(request, 'get_roles')
     roles_as_list = map(lambda x: x[0], roles)
     self.fields['role'].choices = zip(roles_as_list, roles_as_list)
Exemplo n.º 12
0
def update_client(request, client_id):
    if request.method == 'POST':
        form = ClientForm(request.POST)
        if form.is_valid():
            if update_client_in_db(request,
                                   form.cleaned_data['first_name'],
                                   form.cleaned_data['last_name'],
                                   client_id):
                messages.info(request, 'Client updated successfully')
            else:
                messages.error(request, 'Error while updating')
            return to_index_page()
    else:
        row_names, record = list_request(request, 'client_info', [int(client_id)])
        client_id, first_name, last_name, best_client = record[0]
        form = ClientForm(data={'first_name': first_name, 'last_name': last_name, 'best_client': best_client})
    return render(request, 'django_app/client_form.html', {'form': form, 'id': client_id})
Exemplo n.º 13
0
def update_office(request, office_id):
    if request.method == 'POST':
        form = OfficeForm(request.POST)
        if form.is_valid():
            if call_procedure_in_db(request, 'update_office_by_id',
                                    [int(office_id),
                                     form.cleaned_data['location'],
                                     form.cleaned_data['description']]):
                messages.info(request, 'Office updated!')
            else:
                messages.error(request, 'Error while updating')
            return to_index_page()
    else:
        row_names, record = list_request(request, 'get_office_by_id', [int(office_id)])
        _, loc, description = record[0]
        form = OfficeForm(data={'location': loc, 'description': description})
    return render(request, 'django_app/edit_form_template.html', {'form': form, 'id': office_id,
                                                                  'url_': 'django_app:update_office'})
Exemplo n.º 14
0
def update_service(request, service_id):
    if request.method == 'POST':
        form = ServiceForm(request.POST)
        if form.is_valid():
            if call_procedure_in_db(request, 'update_service_by_id',
                                    [int(service_id),
                                     form.cleaned_data['name'],
                                     form.cleaned_data['price']]):
                messages.info(request, 'Service updated')
            else:
                messages.error(request, 'Service update error')
            return to_index_page()
    else:
        row_names, record = list_request(request, 'get_service_by_id', [int(service_id)])
        _, name, price = record[0]
        form = ServiceForm(data={'name': name, 'price': price})
    return render(request, 'django_app/edit_form_template.html', {'form': form, 'id': service_id,
                                                                  'url_': 'django_app:update_service'})
Exemplo n.º 15
0
def update_discount(request, discount_id):
    if request.method == 'POST':
        form = DiscountForm(request.POST)
        if form.is_valid():
            if call_procedure_in_db(request, 'update_discount_by_id',
                                    [int(discount_id),
                                     form.cleaned_data['description'],
                                     form.cleaned_data['value']]):
                messages.info(request, 'Discount updated')
            else:
                messages.error(request, 'Error while updating a discount')
            return to_index_page()
    else:
        row_names, record = list_request(request, 'get_discount_by_id', [int(discount_id)])
        _, desr, val = record[0]
        form = DiscountForm(data={'description': desr, 'value': val})
    return render(request, 'django_app/edit_form_template.html', {'form': form, 'id': discount_id,
                                                                  'url_': 'django_app:update_discount'})
Exemplo n.º 16
0
def update_bonus(request, bonus_id):
    if request.method == 'POST':
        form = BonusForm(request.POST)
        if form.is_valid():
            if call_procedure_in_db(request, 'update_bonus_by_id',
                                    [int(bonus_id),
                                     form.cleaned_data['type'],
                                     form.cleaned_data['value']]
                                    ):
                messages.info(request, 'Bonus updated')
            else:
                messages.error(request, 'Error while updating')
            return to_index_page()
    else:
        row_names, record = list_request(request, 'get_bonus_by_id', [int(bonus_id)])
        _, type_, value = record[0]
        form = BonusForm(data={'type': type_, 'value': value})
    return render(request, 'django_app/edit_form_template.html', {'form': form, 'id': bonus_id,
                                                                      'url_': 'django_app:update_bonus'})
Exemplo n.º 17
0
def all_orders(request):
    row_names, data = list_request(request, 'get_orders')
    return render(request, 'django_app/orders_list.html', {'data': data, 'headers': row_names})
Exemplo n.º 18
0
def get_clients(request):
    row_names, data = list_request(request, 'get_clients')
    return render(request, 'django_app/client_list.html',
                  {"headers": row_names, "data": data,
                   'extra_thing': {'url': 'django_app:update_client',
                                   'text': 'Update client'}})