예제 #1
0
파일: views.py 프로젝트: johncanlam/opms
def create(request):
    if request.method == 'POST':
        new_customer = customer(customer_name = request_getutf8(request,'customer_name'),
                                customer_phone = request_getutf8(request, 'customer_phone'),
                                customer_add = request_getutf8(request,'customer_add') )
        new_customer.save()
        return {'Callback': ('HttpResponse',u'success')}
    else :
        return {}
예제 #2
0
파일: views.py 프로젝트: johncanlam/opms
def dialog_search(request):
    if request.method == 'POST':
        select_item = request_getutf8(request, 'select_item')
        select_value = request_getutf8(request, 'select_value')
        if select_item == 'customer_name' :
            customers = customer.objects.filter(customer_name__contains = select_value)
        else :
            customers = customer.objects.filter(customer_phone__contains = select_value)
        return {'customers': customers, }
    else :
        return {}
예제 #3
0
파일: views.py 프로젝트: johncanlam/opms
def copy_template(request):
    if request.method == 'POST':
        src_id = request_getutf8(request,'id')
        dest_name = request_getutf8(request,'dest_name')
        try :
            src = pub_template.objects.get(id=src_id)
        except pub_template.DoesNotExist,e:
            logger.error( str(e) + 'by id ' + src_id)
            return {'Callback':'HttpResponse', 'args':('copy_error',)}
        dest = copy.deepcopy(src)
        dest.pk = None
        dest.temp_name = dest_name
        dest.save()
        return {'Callback': 'HttpResponse', 'args':('success',)}
예제 #4
0
파일: views.py 프로젝트: johncanlam/opms
def edit_template(request):
    temp_id = request_getutf8(request, 'id')
    try :
        temp = pub_template.objects.get(id=temp_id)
    except pub_template.DoesNotExist,e:
        logger.error( str(e) + 'by id ' + str(temp_id))
        return {'Callback': 'HttpResponseRedirect', 'args':(request.META.get('HTTP_REFERER', '/'),)  }
예제 #5
0
파일: views.py 프로젝트: johncanlam/opms
def detail(request):
    publist_id = request_getutf8(request,'id')
    try :
        pub_task = pub_list.objects.get(id=publist_id)
    except pub_list.DoesNotExist,e:
        logger.error( str(e) + 'by id ' + str(pub_list_id))
        return {'Callback': 'HttpResponseRedirect', 'args':(request.META.get('HTTP_REFERER', '/'),)  }
예제 #6
0
파일: views.py 프로젝트: johncanlam/opms
def search(request):
    if request.method == 'POST':
        select_item = request_getutf8(request, 'select_item')
        select_value = request_getutf8(request, 'select_value')
        if select_item == 'order_id' :
            orders = order.objects.filter(order_id = select_value)
        elif select_item == 'customer_phone':
            orders = customer.objects.get(customer_phone = select_value).order_set.all()
        elif select_item == 'customer_name':
            orders = customer.objects.get(customer_name = select_value).order_set.all()
        else :
            orders = None
        for x in orders:
            x.cstatus = order_status.get(x.status)
            x.statuser = get_val_byid(User, x.status_id, 'username') 
        return {'orders': orders}
    else :
        return {}
예제 #7
0
파일: views.py 프로젝트: johncanlam/opms
def select_hosts(request):
    app_name = request_getutf8(request,'app')
    if app_name :
        try :
            data =  get_ip2app(app_name)
        except :
            return {'Callback':'HttpResponse', 'args':('get_app_error',)}
        return {'data': data}
    return {'data': None}
예제 #8
0
파일: views.py 프로젝트: johncanlam/opms
def rollback_temp(request):
    t_id = request_getutf8(request,'id')
    if t_id :
        template = pub_template.objects.get(id=t_id)
        template.rollback_args = json.loads(template.temp_content).get('rollback')
        logger.debug(template.rollback_args)
    else :
        template = None
    return {'t':template}
예제 #9
0
파일: views.py 프로젝트: johncanlam/opms
def index(request):
    data = json.loads(urllib2.urlopen(conf.get_url).read())
    keys = request_getutf8(request, 'key')
    if request.method == 'POST' and keys:
        regular = re.compile(keys)
        new_data = []
        for x in data:
            if regular.search(x.get('domain')):
                new_data.append(x)
        return {'data': new_data}
    return {'data': data}
예제 #10
0
파일: views.py 프로젝트: johncanlam/opms
def create_task(request):
    if request.method == 'POST':
        logger.debug(request.REQUEST.items())
        app_id = request_getutf8(request,'app_id')
        if app_id :
            try :
                app = pub_app.objects.get(id=app_id)
            except pub_app.DoesNotExist:
                return {'active':'create'}
            return {'app':app}
        run_user = request_getutf8(request,'run_user')
        run_pw = request_getutf8(request,'run_pw')
        hosts = []
        try :
            for x in request_getutf8(request,'pub_hosts').split(','):
                if x:
                    hosts.append(x)
        except AttributeError:
            logger.error(traceback.format_exc())
            return {'Callback': 'HttpResponseRedirect', 'args':(request.META.get('HTTP_REFERER', '/'),)  }
        logger.debug(hosts)
        batch = request_getutf8(request,'pub_batch')
        template_id = request_getutf8(request,'template_id')
        template_args = request_getutf8(request,'template_args')
        app = request_getutf8(request,'app_name')
        #每次创建任务重新判断关联应用与模板关系
        template = pub_template.objects.get(id = template_id)
        try :
            db_app = pub_app.objects.get(name = app)
        except pub_app.DoesNotExist:
            db_app = pub_app(name = app)
        finally :
            db_app.template_id = template
            db_app.template_args = template_args
            db_app.save()
        #获取当前创建用户
        current_user =  pub_user.objects.get(user_id = 'linxiao.jz')
        #创建发布任务
        new_task = pub_list(state = 255, pub_host_n = len(hosts), pub_batch = batch, 
                            creater_id = current_user, pub_app_id = db_app, template_id = template)
        new_task.save()
        #创建发布主机
        for x in hosts:
            new_task_host = pub_hosts(host_name = x, host_state = 1, pub_list_id = new_task)
            new_task_host.save()
        #通知cmdserver
        mq = settings.MQ
        mq.put(('start',new_task.id))
        return {'Callback': 'HttpResponse', 'args':('success',)}
    return {'active':'create'}
예제 #11
0
파일: views.py 프로젝트: johncanlam/opms
def register(request):
    if request.method == 'POST':
        pwd = request.REQUEST.get('pwd')
        loguser = request_getutf8(request, 'user')
        userexist = User.objects.filter(username=loguser)
        if userexist :
            return {'Callback': 'HttpResponse', 'args':("ERR",) }
        else :
            return {'Callback': 'HttpResponse', 'args':("OK",) }
    else :
        if request.REQUEST.get('reg') :
            return {}
        else :
            return {'Callback': 'HttpResponseRedirect', 'args':(request.META.get('HTTP_REFERER', '/'),)  }
예제 #12
0
파일: views.py 프로젝트: johncanlam/opms
def select_temp(request):
    app_id = request_getutf8(request,'app_id')
    if app_id :
        app = pub_app.objects.get(id=app_id)
        app.targs = json.loads(app.template_args)
    else :
        app = None
    data = pub_template.objects.all()
    for x in data:
        logger.debug(json.loads(x.temp_content).get('steps'))
        x.steps = json.loads(x.temp_content).get('steps')
        logger.debug(x.steps)
    res = chunks(data,3) 
    return {'data':res, 'app':app}
예제 #13
0
파일: views.py 프로젝트: johncanlam/opms
def Login(request):
    if request.method == 'POST':
        pwd = request.REQUEST.get('pwd')
        #loguser = request.REQUEST.get('user')
        loguser = request_getutf8(request, 'user')
        user = authenticate(username=loguser, password=pwd)
        if user is not None and user.is_active:
            login(request, user)
            return {'Callback': 'HttpResponse', 'args':("OK",) }
        else :
            return {'Callback': 'HttpResponse', 'args':("ERR",) }
    else:
        if request.REQUEST.get('login') :
            return {}
        else :
            return {'Callback': 'HttpResponseRedirect', 'args':(request.META.get('HTTP_REFERER', '/'),)  }
예제 #14
0
파일: views.py 프로젝트: johncanlam/opms
def del_template(request):
    if request.method == 'POST':
        del_id = request_getutf8(request,'id')
        try :
            del_temp = pub_template.objects.get(id=del_id)
        except pub_template.DoesNotExist,e:
            logger.error( str(e) + 'by id ' + del_id)
            return {'Callback':'HttpResponse', 'args':('del_error',)}
        t = json.loads(del_temp.temp_content)
        try :
            del_temp.delete()
        except ProtectedError:
            return {'Callback': 'HttpResponse', 'args':('cant_delete',)}
        for x in t.get('steps'):
            rm_plugin(x.get('step').get('script_name'))
        for x in t.get('rollback'):
            rm_plugin(x.get('step').get('script_name'))
        return {'Callback': 'HttpResponse', 'args':('success',)}
예제 #15
0
파일: views.py 프로젝트: johncanlam/opms
def create(request):
    if request.method == 'POST':
        thisorder = order(order_name = request_getutf8(request, 'order_name'),
                          photograph_time = request_getutf8(request,'photograph_time'),
                          photoselect_time = request_getutf8(request, 'photoselect_time'),
                          get_time = request_getutf8(request, 'get_time'),
                          payment = request_getutf8(request, 'payment'),
                          nopayment = request_getutf8(request, 'nopayment'),
                          total = request_getutf8(request, 'total') )
        thisorder.order_id = str(hash(datetime.datetime.now().strftime("%s") + request_getutf8(request, 'order_name')))[1:13]
        thisorder.status = 0
        thisorder.create_id = request.user.id
        thisorder.status_id = request.user.id
        #判断是否为新顾客,并在顾客表中以手机号查找是否存在,创建用户与其关联
        if int(request_getutf8(request,'customer_type')) == 1:
            if not customer.objects.filter(customer_phone = request_getutf8(request, 'customer_phone')):
                new_customer = customer(customer_name = request_getutf8(request,'customer_name'),
                                        customer_phone = request_getutf8(request, 'customer_phone'),
                                        customer_add = request_getutf8(request,'customer_add') )
                new_customer.save()
                thisorder.customer_id = new_customer
            else :
                thisorder.customer_id = customer.objects.get(id = get_id_bykey(customer, 'customer_phone' , request_getutf8(request, 'customer_phone')))
        else :
            thisorder.customer_id = customer.objects.get(id = get_id_bykey(customer, 'customer_phone' , request_getutf8(request, 'customer_phone')))
        thisorder.save()
        #获取商品子订单并保存与当前订单关联
        for x in xrange(0, int(request.REQUEST.get('commodity_sum')) + 1):
            try :
                assert(request_getutf8(request, 'commodity_%s_name' % x))
                suborder = sub_order(commodity = request_getutf8(request, 'commodity_%s_name' % x ),
                                     commodity_num = request_getutf8(request, 'commodity_%s_num' % x ) )
                suborder.money = 0
                suborder.pid = thisorder
            except AssertionError:
                continue
            else :
                suborder.save()
            return {'Callback': 'HttpResponse', 'args':'succeed'}
    else :
        if request.REQUEST.get('ajax') :
            return {}
        else :
            return {'Callback': 'HttpResponseRedirect','args': request.META.get('HTTP_REFERER', '/')}
예제 #16
0
파일: views.py 프로젝트: johncanlam/opms
def host_terminal(request):
    host_id = request_getutf8(request,'id')
    url = '?'.join([request.META.get('PATH_INFO'), request.META.get('QUERY_STRING')])
    return {'id':host_id, 'url':url }