コード例 #1
0
ファイル: views.py プロジェクト: trickysky/wemark-web
def set_index(request):
    subject = Subject.get_instance(request.session)
    user = subject.get_user_info()
    user_id = None if subject.has_role('root') else user.get("id")

    base_data = {
        'app_name': u'生产赋码',
        'page_name': CompanyService.get_company().get('name'),
        'page_desc': u'批次管理',
        'product_options': [],
        'factory_options': [],
        'products': []
    }
    products = ProductService.get_product_list(created_by=user_id)
    product_dict = {}
    if products and products['code'] == 0:
        for product in products['data']:
            prod_id = product['id']
            base_data['product_options'].append(
                {'text': product['name'], 'value': prod_id}
            )
            base_data['products'].append(product)
            product_dict[prod_id] = product
    factories = FactoryService.get_factory_list(created_by=user_id)
    if factories and factories['code'] == 0:
        for factory in factories['data']:
            base_data['factory_options'].append({'text': factory['factoryName'], 'value': factory['id']})
    base_data['batch_list'] = set_batch_list(BatchService.get_batch_list(created_by=user_id), product_dict)
    return base_data
コード例 #2
0
def authorize(request):
    subject = Subject.get_instance(request.session)
    code = OAuth2Utils.parse_auth_code(request)
    state = OAuth2Utils.parse_state(request)

    if subject.authenticate(request=request, auth_code=code):
        redirect_uri = state if state else '/report'
        return HttpResponseRedirect(redirect_to=redirect_uri)
    else:
        return HttpResponseRedirect(redirect_to=subject.redirect_to_authenticate(request=request, state=state))
コード例 #3
0
ファイル: views.py プロジェクト: trickysky/wemark-web
def batch(request):
    if request.method == 'POST':
        new_batch_response = new_batch(request)
        response = {'code': new_batch_response['code'],
                    'msg': 'new batch success' if new_batch_response['code'] == 0 else 'new batch error'}
        return JsonResponse(response)
    elif request.method == 'GET':
        subject = Subject.get_instance(request.session)
        user = subject.get_user_info()
        user_id = None if subject.has_role('root') else user.get("id")
        response = BatchService.get_batch_list(created_by=user_id)
        return JsonResponse(response)
コード例 #4
0
 def process_request(request):
     """
     :type request: HttpRequest
     """
     subject = Subject.get_instance(request.session)
     if request.path not in AuthenticationMiddleware.EXCEPTIONS and not subject.is_authenticated(
     ):
         redirect_uri = subject.redirect_to_authenticate(
             request=request, state=request.get_raw_uri())
         if redirect_uri:
             return HttpResponseRedirect(redirect_uri)
         else:
             return HttpResponseRedirect('/error')
     return None
コード例 #5
0
ファイル: views.py プロジェクト: trickysky/wemark-web
def new_batch(request):
    subject = Subject.get_instance(request.session)
    user = subject.get_user_info()
    body = request.POST
    return BatchService.create_batch(
        factory_id=body.get('factory_id'),
        incode_factory=body.get('incode_factory'),
        outcode_factory=body.get('outcode_factory'),
        casecode_factory=body.get('casecode_factory'),
        case_count=body.get('case_count'),
        case_size=body.get('case_size'),
        unit_count=body.get('unit_count'),
        barcode=body.get('barcode'),
        product_id=body.get('product_id'),
        expired_time=body.get('expired_time'),
        product_info=body.get('product_info'),
        callback_uri=body.get('callback_uri'),
        created_by=user['id'],
        updated_by=user['id']
    )
コード例 #6
0
ファイル: views.py プロジェクト: trickysky/wemark-web
def set_index(request):
    subject = Subject.get_instance(request.session)
    company_info = CompanyService.get_company()
    award_data = AwardSettingService.get_award_setting(
        activity_id=subject.get_user_info(request).get('id'))
    prize_name = ['谢谢参与奖', '一等奖', '二等奖', '三等奖', '四等奖']
    prize = []
    for i in range(len(award_data['proportion'])):
        prize.append({
            'name': prize_name[i],
            'proportion': award_data['proportion'][i],
            'amount': award_data['prize_amount'][i],
        })
    base_data = {
        'app_name':
        u'信息录入',
        'page_name':
        u'信息录入',
        'page_desc':
        u'',
        'factory_list': [],
        'product_list': [],
        'company_name':
        company_info.get('name') if company_info else None,
        'company_description':
        company_info.get('description') if company_info else None,
        'company_homepage':
        company_info.get('homepage') if company_info else None,
        'award_setting': {
            'total_prize': award_data['total_prize'],
            'total_num': award_data['total_num'],
            'amount_unit': award_data['amount_unit'],
            'prize': prize
        }
    }
    products = ProductService.get_product_list()
    if products and products.get('code') == 0:
        for product in products.get('data'):
            if subject.has_role('root') or product.get(
                    'createdBy') == subject.get_user_info(request).get('id'):
                base_data['product_list'].append({
                    'product_id':
                    product['id'],
                    'product_name':
                    product['name'],
                    'product_unit':
                    product['unit'],
                    'product_barcode':
                    product['barcode'],
                    'product_intro':
                    product['intro'],
                    'product_icon':
                    product['icon'],
                    'product_status':
                    product['status'],
                    'product_images':
                    product['images'],
                    'product_description':
                    product['description'],
                })
    factories = FactoryService.get_factory_list()
    if factories and factories.get('code') == 0:
        for factory in factories['data']:
            if subject.has_role('root') or factory.get(
                    'createdBy') == subject.get_user_info(request).get('id'):
                base_data['factory_list'].append({
                    'factory_id':
                    factory['id'],
                    'factory_name':
                    factory['factoryName'],
                    'factory_type':
                    factory['type'],
                    'factory_ip':
                    factory['location'],
                    'factory_region':
                    factory['region'],
                    'factory_status':
                    factory['status'],
                    'factory_owner':
                    factory['owner'],
                    'factory_owner_phone':
                    factory['ownerMobile'],
                    'factory_owner_email':
                    factory['ownerEmail'],
                })
    return base_data
コード例 #7
0
ファイル: views.py プロジェクト: trickysky/wemark-web
def get_user_info(request):
    subject = Subject.get_instance(request.session)
    return subject.get_user_info()
コード例 #8
0
def create_service(request):
    subject = Subject.get_instance(request.session)
    return ReportService(user_id=subject.get_user_info()['id'],
                         is_root=subject.has_role('root'))
コード例 #9
0
def logout(request):
    subject = Subject.get_instance(request.session)
    subject.logout()
    return HttpResponseRedirect(redirect_to=subject.redirect_to_authenticate(request=request))