예제 #1
0
def go_cat_home(request, context=None):
    try:
        context = get_context_in_session(request)

        if not context:
            context = {}

        ITEMS_PER_PAGE = 10

        productPage = None
        if request.GET.get('pr_page'):
            productPage = request.GET.get('pr_page')
        else:
            productPage = 1

        client = UnoClient.objects.get(client_id=request.session['id'])
        context['client'] = client
        context['addPrForm'] = AddPrForm()

        # Get all products
        prResult = CtgProduct.objects.filter(client_id=client.client_id,
                                             active=True).order_by(
                                                 '-creation_time', 'itemcode')
        pagedList = Paginator(prResult, ITEMS_PER_PAGE)
        products = pagedList.get_page(productPage)

        for pr in products:
            pr.product_id = str(pr.product_id).replace('-', '')
            pr.itemcode = getDefCatalogCode(pr.itemcode)

        context['products'] = products
        context['prCount'] = len(products)

        return render(request, 'catalog/index.html', context=context)
    except Exception:
        # traceback.print_exc()
        logError(request)
        if request and hasattr(request, 'session'):
            request.session.clear()

        store_context_in_session(
            request, addSnackDataToContext(context, 'Unknown Error'))
        return redirect('go_login')
예제 #2
0
def go_admin(request, context=None):
    try:
        if request is None:
            return redirect('go_login')
        elif request.session['id'] != getCpAdminId():
            request.session.clear()
            return redirect('go_login')
    except KeyError:
        return redirect('go_login')

    context = get_context_in_session(request)

    if context is None:
        context = {}

    ITEMS_PER_PAGE = 3

    requestPage = None
    if request.GET.get('request_page'):
        requestPage = request.GET.get('request_page')
    else:
        requestPage = 1

    # Fetch client data
    clientList = UnoClient.objects.all().order_by('-creation_time',
                                                  'client_id')
    pagedList = Paginator(clientList, ITEMS_PER_PAGE)
    clients = pagedList.get_page(requestPage)

    # Store the current page in temp session variable
    request.session['admin_page'] = requestPage

    # Deprecated but usable
    for client in clients:
        tempBytes = client.signature_letter
        if tempBytes:
            client.signature_letter = tempBytes.decode('U8')

    context['clients'] = clients
    context['approvalForm'] = ApprovalForm()

    return render(request, 'core/admin.html', context=context)
예제 #3
0
def go_client(request, context=None):
    if request and hasattr(
            request,
            'session') and request.session and 'id' in request.session:
        if len(request.session['id']) != 32:
            request.session.clear()
            return redirect('go_login')
        else:
            context = get_context_in_session(request)

            if context is None:
                context = {}

            client = UnoClient.objects.get(client_id=request.session['id'])
            context['client'] = client

            # Customer form
            context['customerForm'] = CustomerForm()

            # Opportunity form
            oppoForm = OpportunityForm(initial={'client_id': client.client_id})

            customerList = UnoCustomer.objects.filter(client=client)
            custChoice = []

            for cust in customerList:
                choice = (cust.customer_id, cust.customer_name)
                custChoice.append(choice)

            if len(custChoice) > 0:
                oppoForm.fields['customer'].choices = custChoice
                context['oppoForm'] = oppoForm
            else:
                context['oppoForm'] = None

            return render(request, 'core/client.html', context=context)
    else:
        return redirect('go_login')
예제 #4
0
def go_records(request):
    try:
        client = UnoClient.objects.get(client_id=request.session['id'])

        context = get_context_in_session(request)
        if not context:
            context = {}

        context['entity_name'] = client.entity_name

        records = []

        oppoList = UnoOpportunity.objects.filter(client=client)
        if len(oppoList) < 1:
            store_context_in_session(
                request, addSnackDataToContext(context,
                                               'No opportunity found'))
            return redirect('go_client')

        for oppo in oppoList:
            customer = UnoCustomer.objects.get(customer_id=oppo.customer_id)
            records.append(
                (str(oppo.opportunity_number).replace('-', ''),
                 oppo.creation_time, customer.customer_name, oppo.active))

        context['records'] = records

        return render(request, 'core/records.html', context=context)
    except Exception:
        # traceback.print_exc()
        logError(request)
        if request and hasattr(request, 'session'):
            request.session.clear()

        store_context_in_session(
            request, addSnackDataToContext(context, 'Unexpected Error'))
        return redirect('go_login')
예제 #5
0
def go_login(request, context=None):
    try:
        if request and request.session:
            pass
            # Test cookie (disabled)
            # if request.session.test_cookie_worked():
            # print('Django session is working')
            # request.session.delete_test_cookie()
    except AttributeError:
        pass

    # Retrieve session context if passed
    context = get_context_in_session(request)

    if context is None:
        context = {}

    if request.method == 'GET':
        loginForm = LoginForm()
        psrForm = PasswordResetForm()
        context['loginForm'] = loginForm
        context['psrForm'] = psrForm

    return render(request, 'core/login.html', context=context)
예제 #6
0
def go_spec_config(request, context=None):
    try:
        context = get_context_in_session(request)

        if not context:
            context = {}

        # Load specification
        client = UnoClient.objects.get(client_id=request.session['id'])
        specification = CtgSpecification.objects.get(
            ctg_doc_id=request.GET.get('doc_id'), active=True)

        context['client'] = client
        context['specification'] = specification

        # Get parent URL
        flag = ''
        pntUrl = ''
        pntText = ''
        product = CtgProduct.objects.filter(
            ctg_doc_id=specification.parent_ctg_id, client=client, active=True)
        if product and len(product) > 0:
            flag = 'PR'
            pntText = getDefCatalogCode(product[0].itemcode)
            pntUrl = reverse('go_pr_config') + '?doc_id=' + \
                str(product[0].ctg_doc_id).replace('-', '')
        else:
            feature = CtgFeature.objects.filter(
                ctg_doc_id=specification.parent_ctg_id,
                client=client,
                active=True)
            if feature and len(feature) > 0:
                flag = 'FET'
                pntText = getDefCatalogCode(feature[0].itemcode)
                pntUrl = reverse('go_fet_config') + '?doc_id=' + \
                    str(feature[0].ctg_doc_id).replace('-', '')

        if not flag:
            raise Exception
        context['reUrl'] = pntUrl
        context['pntText'] = pntText

        # Spec config details
        # Values
        values = CtgValue.objects.filter(specification=specification).order_by(
            '-creation_time', 'code')
        context['values'] = values
        context['valCount'] = len(values)

        # Spec edit form
        editSpecForm = EditSpecForm()
        editSpecForm.fields['specification_id'].widget.attrs['value'] = str(
            specification.specification_id).replace('-', '')
        editSpecForm.fields['leaf_name'].widget.attrs[
            'value'] = specification.leaf_name
        editSpecForm.fields['data_type'].widget.attrs[
            'value'] = getGeneralTranslation(specification.data_type)
        editSpecForm.fields['spec_label'].widget.attrs[
            'value'] = specification.label
        editSpecForm.fields['spec_label'].widget.attrs[
            'data-name'] = specification.label
        editSpecForm.fields['default_value'].widget.attrs[
            'value'] = specification.default_value
        editSpecForm.fields['default_value'].widget.attrs[
            'data-value'] = specification.default_value
        context['editSpecForm'] = editSpecForm

        dt = specification.data_type

        # Other config forms
        # Value form
        if dt == 'ENUM':
            addValueForm = AddValueForm()
            addValueForm.fields['specification_id'].widget.attrs[
                'value'] = str(specification.specification_id).replace(
                    '-', '')
            context['addValueForm'] = addValueForm

        # Restriction form
        if dt == 'STR' or dt == 'QTY':
            resForm = RestrictionForm()
            resForm.fields['specification_id'].widget.attrs['value'] = str(
                specification.specification_id).replace('-', '')
            # Retrieve and populate
            resList = CtgRestriction.objects.filter(
                specification=specification)
            for res in resList:
                if res.rule_type == 'MAX':
                    resForm.fields['max_val'].widget.attrs['value'] = res.value
                    resForm.fields['max_val'].widget.attrs[
                        'data-value'] = res.value
                elif res.rule_type == 'MIN':
                    resForm.fields['min_val'].widget.attrs['value'] = res.value
                    resForm.fields['min_val'].widget.attrs[
                        'data-value'] = res.value
                elif res.rule_type == 'UPLEN':
                    resForm.fields['max_len'].widget.attrs['value'] = res.value
                    resForm.fields['max_len'].widget.attrs[
                        'data-value'] = res.value
                elif res.rule_type == 'LOLEN':
                    resForm.fields['min_len'].widget.attrs['value'] = res.value
                    resForm.fields['min_len'].widget.attrs[
                        'data-value'] = res.value
                elif res.rule_type == 'AO':
                    resForm.fields['alpha_only'].widget.attrs[
                        'value'] = res.value
                    resForm.fields['alpha_only'].widget.attrs[
                        'data-value'] = res.value
                elif res.rule_type == 'NUO':
                    resForm.fields['num_only'].widget.attrs[
                        'value'] = res.value
                    resForm.fields['num_only'].widget.attrs[
                        'data-value'] = res.value
                elif res.rule_type == 'EML':
                    resForm.fields['email_only'].widget.attrs[
                        'value'] = res.value
                    resForm.fields['email_only'].widget.attrs[
                        'data-value'] = res.value
                elif res.rule_type == 'NN':
                    resForm.fields['not_null'].widget.attrs[
                        'value'] = res.value
                    resForm.fields['not_null'].widget.attrs[
                        'data-value'] = res.value
            # Disable not applicable rules
            if dt == 'STR':
                resForm.fields['max_val'].widget.attrs['disabled'] = 'true'
                resForm.fields['max_val'].widget.attrs[
                    'class'] = 'form-inp-dis'
                resForm.fields['min_val'].widget.attrs['disabled'] = 'true'
                resForm.fields['min_val'].widget.attrs[
                    'class'] = 'form-inp-dis'
            elif dt == 'QTY':
                resForm.fields['max_len'].widget.attrs['disabled'] = 'true'
                resForm.fields['max_len'].widget.attrs[
                    'class'] = 'form-inp-dis'
                resForm.fields['min_len'].widget.attrs['disabled'] = 'true'
                resForm.fields['min_len'].widget.attrs[
                    'class'] = 'form-inp-dis'
                resForm.fields['alpha_only'].widget.attrs['disabled'] = 'true'
                resForm.fields['alpha_only'].widget.attrs[
                    'class'] = 'form-inp-dis'
                resForm.fields['num_only'].widget.attrs['disabled'] = 'true'
                resForm.fields['num_only'].widget.attrs[
                    'class'] = 'form-inp-dis'
                resForm.fields['email_only'].widget.attrs['disabled'] = 'true'
                resForm.fields['email_only'].widget.attrs[
                    'class'] = 'form-inp-dis'
            context['resForm'] = resForm

        # Price form
        priceForm = PriceForm()
        priceForm.fields['specification_id'].widget.attrs['value'] = str(
            specification.specification_id).replace('-', '')
        # Retrieve data
        priceList = CtgPrice.objects.filter(
            specification=specification).order_by('creation_time')
        # Populate price point(s)
        priceData = {}
        for price in priceList:
            data = (price.mrc, price.nrc, price.unit_mrc, price.unit_nrc)
            if not price.value:
                priceData['$'] = data
            else:
                priceData[price.value.code] = data
        context['priceData'] = priceData if len(priceData) > 0 else None
        # Disable fields
        priceForm.fields['value'].widget.attrs['disabled'] = 'true'
        priceForm.fields['value'].widget.attrs['class'] = 'form-inp-dis'
        if dt == 'QTY':
            priceForm.fields['mrc'].widget.attrs['disabled'] = 'true'
            priceForm.fields['mrc'].widget.attrs['class'] = 'form-inp-dis'
            priceForm.fields['nrc'].widget.attrs['disabled'] = 'true'
            priceForm.fields['nrc'].widget.attrs['class'] = 'form-inp-dis'
        else:
            priceForm.fields['unit_mrc'].widget.attrs['disabled'] = 'true'
            priceForm.fields['unit_mrc'].widget.attrs['class'] = 'form-inp-dis'
            priceForm.fields['unit_nrc'].widget.attrs['disabled'] = 'true'
            priceForm.fields['unit_nrc'].widget.attrs['class'] = 'form-inp-dis'
        if dt == 'ENUM' and len(values) > 0:
            # Populate values
            valueList = []
            for val in values:
                valueList.append((val.code, val.translation))
            priceForm.fields['value'].choices = valueList
            priceForm.fields['value'].widget.attrs.pop('disabled', None)
            priceForm.fields['value'].widget.attrs.pop('class', None)
        context['priceForm'] = priceForm

        return render(request, 'catalog/specification.html', context=context)
    except Exception:
        # traceback.print_exc()
        logError(request)
        store_context_in_session(
            request, addSnackDataToContext(context, 'Unknown Error'))
        return redirect('go_cat_home')
예제 #7
0
def go_fet_config(request, context=None):
    try:
        context = get_context_in_session(request)

        if not context:
            context = {}

        # Get client and feature
        client = UnoClient.objects.get(client_id=request.session['id'])
        feature = CtgFeature.objects.get(ctg_doc_id=request.GET.get('doc_id'),
                                         client_id=client.client_id,
                                         active=True)

        feature.itemcode = getDefCatalogCode(feature.itemcode)
        context['client'] = client
        context['feature'] = feature

        # Get product URL
        product = CtgProduct.objects.get(product_id=feature.product_id)
        prUrl = reverse('go_pr_config') + '?doc_id=' + \
            str(product.ctg_doc_id).replace('-', '')
        context['reUrl'] = prUrl
        context['pntText'] = getDefCatalogCode(product.itemcode)

        # Load specs
        specs = CtgSpecification.objects.filter(
            parent_ctg_id=feature.ctg_doc_id,
            active=True).order_by('-creation_time', 'leaf_name')
        context['specs'] = specs
        context['spCount'] = len(specs)

        # Initialize forms
        # Edit feature
        editFetForm = EditFetForm()
        editFetForm.fields['feature_id'].widget.attrs['value'] = str(
            feature.feature_id).replace('-', '')
        editFetForm.fields['feature_code'].widget.attrs[
            'value'] = feature.itemcode
        editFetForm.fields['feature_name'].widget.attrs['value'] = feature.name
        editFetForm.fields['feature_name'].widget.attrs[
            'data-name'] = feature.name
        editFetForm.fields['limit'].widget.attrs['value'] = feature.limit
        editFetForm.fields['limit'].widget.attrs['data-value'] = feature.limit
        editFetForm.fields['is_extended'].widget.attrs[
            'value'] = feature.extended
        editFetForm.fields['is_extended'].widget.attrs[
            'data-value'] = feature.extended
        context['editFetForm'] = editFetForm

        addSpecForm = AddSpecForm()
        addSpecForm.fields['parent_ctg_id'].widget.attrs[
            'value'] = request.GET.get('doc_id')
        context['addSpecForm'] = addSpecForm

        return render(request, 'catalog/feature.html', context=context)
    except Exception:
        # traceback.print_exc()
        logError(request)
        store_context_in_session(
            request, addSnackDataToContext(context, 'Unknown Error'))
        return redirect('go_cat_home')
예제 #8
0
def go_pr_config(request, context=None):
    try:
        context = get_context_in_session(request)

        if not context:
            context = {}

        # Get client and product
        client = UnoClient.objects.get(client_id=request.session['id'])
        product = CtgProduct.objects.get(ctg_doc_id=request.GET.get('doc_id'),
                                         client_id=client.client_id,
                                         active=True)

        product.itemcode = getDefCatalogCode(product.itemcode)
        context['client'] = client
        context['product'] = product

        context['reUrl'] = reverse('go_cat_home')

        # Load specs
        specs = CtgSpecification.objects.filter(
            parent_ctg_id=product.ctg_doc_id,
            active=True).order_by('-creation_time', 'leaf_name')
        context['specs'] = specs
        context['spCount'] = len(specs)

        # Load features
        features = CtgFeature.objects.filter(client=client,
                                             product=product,
                                             active=True).order_by(
                                                 '-creation_time', 'itemcode')
        for fet in features:
            fet.itemcode = getDefCatalogCode(fet.itemcode)
        context['features'] = features
        context['fetCount'] = len(features)

        # Initialize forms
        editPrForm = EditPrForm()
        editPrForm.fields['product_id'].widget.attrs['value'] = str(
            product.product_id).replace('-', '')
        editPrForm.fields['product_code'].widget.attrs[
            'value'] = product.itemcode
        editPrForm.fields['product_name'].widget.attrs['value'] = product.name
        editPrForm.fields['product_name'].widget.attrs[
            'data-name'] = product.name
        context['editPrForm'] = editPrForm

        addSpecForm = AddSpecForm()
        addSpecForm.fields['parent_ctg_id'].widget.attrs[
            'value'] = request.GET.get('doc_id')
        context['addSpecForm'] = addSpecForm

        addFetForm = AddFetForm()
        addFetForm.fields['product_id'].widget.attrs['value'] = str(
            product.product_id).replace('-', '')
        context['addFetForm'] = addFetForm
        context['limit_suffix'] = '(0 for unlimited)'

        return render(request, 'catalog/product.html', context=context)
    except Exception:
        # traceback.print_exc()
        logError(request)
        store_context_in_session(
            request, addSnackDataToContext(context, 'Unknown Error'))
        return redirect('go_cat_home')