예제 #1
0
파일: views.py 프로젝트: cash2one/tstpthon
def add(request):
    c = {}
    c.update(csrf(request))
    isvalid = True
    u = Demand
    if request.method == "POST":
        u = Demand()
        member_id = request.POST["member_id"]
        name_en = request.POST["name_en"]
        if member_id == "0" or member_id == "":
            isvalid = False
            messages.warning(request, "please select member")
        if name_en == "":
            isvalid = False
            messages.warning(request, "please input english name")
        # _bind_data(request, u)
        if isvalid:
            try:
                u.save()
                _save_items(request, u)
                return redirect("demand.index")
            except Exception, e:
                messages.warning(request, e.message)
                logging.error(e.message)
                logging.debug(e.message)
예제 #2
0
def createDemand():
    """
    The '/createDemand' route directs a client to the form where he/she can
    create and post a demand on the Turk System.
    """
    if 'username' not in session:
        return redirect(url_for('login'))

    if session['role'] != 'client':
        return render_template('access_denied.html')

    form = DemandForm()

    if request.method == 'POST':
        if form.validate():
            format = '%m-%d-%Y %I:%M %p'
            dt_bid = form.bidding_deadline.data.strftime(format)
            dt_submit = form.submission_deadline.data.strftime(format)

            Demand(session['username'], form.title.data, form.tags.data,
                   form.specifications.data, dt_bid, dt_submit)
            new_demand_id = Demand.get_most_recent_demand_id()

            return redirect(url_for('bidInfo', demand_id=new_demand_id))
        else:
            return render_template('createDemand.html', form=form)
    elif request.method == 'GET':
        return render_template('createDemand.html', form=form)
예제 #3
0
파일: views.py 프로젝트: cash2one/tstpthon
def save(request):
    response_data = {}
    response_data['result'] = 'failed'
    if request.method == "POST":
        try:
            name_en = request.POST["name_en"]
            name_cn = request.POST["name_cn"]
            if name_en == "" and name_cn == "":
                response_data['message'] = _("please input demand name")
            else:
                #check stock_symbol is correct
                company_stock_symbol = request.POST.get(
                    "company_stock_symbol", False)
                is_list_company = int(request.POST.get("is_list_company", 0))
                if company_stock_symbol and is_list_company == 1:
                    checksymbolExsit = ListedCompany.objects.filter(
                        stock_symbol=company_stock_symbol)
                    if len(checksymbolExsit) == 0:
                        response_data['message'] = 'symbolNotExsit'
                        return HttpResponse(simplejson.dumps(response_data),
                                            content_type="text/plain")
                submitStatus = request.POST["submitStatus"]
                u = Demand()
                isExsit = False
                id_post = request.POST.get("id", False)
                #check the demand is exsit with member_id
                condition = Q(member_id=request.POST.get("member_id"))
                condition2 = Q()
                if id_post:
                    condition = condition & ~Q(pk=id_post)
                if name_cn.strip() != "":
                    condition2 = condition2 | Q(name_cn=name_cn.strip())

                if name_en.strip() != "":
                    condition2 = condition2 | Q(name_en=name_en.strip())

                project = Demand.objects.filter(condition & condition2)
                if project:
                    isExsit = True
                    response_data['message'] = "demandExsit"

                if isExsit is False:
                    if id_post:
                        u = Demand.objects.get(pk=id_post)
                    # if submitStatus == "draft":
                    #     u.status = StatusDemand.draft
                    # else:
                    #     u.status = StatusDemand.pending
                    bool, msg = _bind_data(request, u)
                    if bool:
                        response_data['result'] = 'success'
                        response_data['id'] = u.id
                        response_data['message'] = '操作成功'
                    else:
                        response_data['message'] = msg

        except Exception, e:
            logger.error(e.message)
            response_data['message'] = e.message
예제 #4
0
def DemandRegister():
    demand = request.get_json()
    db.session.add(
        Demand(field_demands=Field.query.filter_by(
            name=demand['field_name']).first(),
               local_demands=Local.query.filter_by(
                   name=demand['local_name']).first()))
    db.session.commit()
    return Response(status=200, mimetype='application/json')
예제 #5
0
    def post(self):
        # client
        # client = Client(name='Joãoson', email='*****@*****.**', password='******')
        # db.session.add(client)
        # print(Client.query.all())

        requestData = request.get_json()
        date = datetime.datetime.strptime(requestData.get('maxDate'), '%d/%m/%Y')
        demand = Demand(name=requestData.get('name'), description=requestData.get('description'), funcionalities=requestData.get('funcionalities'),
                        final_date=date, platform='desktop', client_id='1')
        db.session.add(demand)
        db.session.commit()
        print(Demand.query.all())
        return {'status': 'criada'}
예제 #6
0
    def post(self):

        requestData = request.get_json()
        date = datetime.datetime.strptime(requestData.get('maxDate'),
                                          '%d/%m/%Y')
        demand = Demand(name=requestData.get('name'),
                        description=requestData.get('description'),
                        funcionalities=requestData.get('funcionalities'),
                        final_date=date,
                        platform='desktop',
                        client_id=requestData.get('user_id'))
        db.session.add(demand)
        db.session.commit()
        print(Demand.query.all())
        return {'status': 'criada'}