예제 #1
0
def add_art(request):
    if request.method == 'POST':
        form = ArtForm(request.POST, request.FILES)
        if form.is_valid():
            new_art = form.save()
            art_id = new_art.id
            return HttpResponseRedirect(reverse('fcgt:picture', args=[art_id]))
    else:
        form = ArtForm()
    return render(request, 'fcgt/index.html', {'form': form})
예제 #2
0
def art_add():
    form = ArtForm()
    if form.validate_on_submit():
        data = form.data
        # 上传logo
        # uploads里面存的是图片文件
        # 数据库里存的是uploads里面的图片的文件名
        file = secure_filename(form.logo.data.filename)
        logo = change_name(file)
        # logo是时间加唯一标志服加图片文件后缀
        if not os.path.exists(app.config["UP"]):
            os.makedirs(app.config["UP"])
        form.logo.data.save(app.config["UP"] + "/" + logo)

        # 获取用户ID
        user = User.query.filter_by(name=session["user"]).first()
        user_id = user.id

        # 保存数据
        art = Art(
            title=data["title"],
            cate=data["cate"],
            user_id=user_id,
            logo=logo,
            content=data["content"],
            addtime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        db.session.add(art)
        db.session.commit()
        flash(u"发布文章成功", "ok")

    return render_template("art_add.html", title=u"发布文章", form=form)
예제 #3
0
def index():
  form = ArtForm()
  if form.is_submitted():

      ############################### Modifications #########################
      if form.urlName.data and form.urlLink.data:
          urlName = "./images/" + form.urlName.data + ".jpg"
          urlLink = form.urlLink.data


          response = requests.get(urlLink, stream=True)
          with open(urlName, "wb+") as out_file:
              shutil.copyfileobj(response.raw, out_file)
          del response
          imageName = form.urlName.data + ".jpg"
          ckpoint = request.form['style']
          endpoint = form.endpoint.data
          print("image: " + urlName + " ckpoint: " + ckpoint + " endpoint: " + endpoint, file=sys.stderr)
          make_request(urlName, imageName, ckpoint, endpoint)
          session['ImageName'] = "static/imgs/" + ckpoint + imageName;
          ImageName = session.get('ImageName', None)
          return render_template("index.html",form=form, valueImage = ImageName, scroll = 'result1')

      ############################### End Modifications #########################

  return render_template("index.html", form=form)
예제 #4
0
def art_add():
    form = ArtForm()
    if form.validate_on_submit():
        data = form.data
        print(data['category'],)
        if data['category'] == 1:
            category = '租房'
        if data['category'] == 2:
            category = '二手房'
        if data['category'] == 3:
            category = '商业地产'
        # 保存数据
        art = House(
            name= data['name'],
            category= category,
            number= data['number'],
            company= data['company'],
            address= data['address'],
            shop_address= data['shop_address'],
            created_time=datetime.datetime.now()
        )
        field.session.add(art)
        field.session.commit()
        flash(u"添加成功", 'ok')
    return render_template('art_add.html', title=u'添加', form=form)
예제 #5
0
def art_add():
    form = ArtForm()
    if form.validate_on_submit():
        data = form.data
        # 上传logo
        file = secure_filename(form.logo.data.filename)
        logo = change_name(file)
        if not os.path.exists(app.config['UP']):
            os.makedirs(app.config["UP"])

        # 保存文件
        form.logo.data.save(app.config["UP"] + "/" + logo)
        # 获取用户ID
        user = User.query.filter_by(name=session["user"]).first()
        user_id = user.id
        # 保存数据
        art = Art(
            title=data["title"],
            cate=data["cate"],
            user_id=user_id,
            logo=logo,
            content=data["content"],
            addtime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        )
        db.session.add(art)
        db.session.commit()
        flash("Post Article Successfully!", "ok")
    return render_template('art_add.html', title="Post Article", form=form)
예제 #6
0
def short_rull(request):
    form = ArtForm()
    return render(request, 'fcgt/short_rull.html',  {'form': form})
예제 #7
0
def index(request):
    # question = get_object_or_404(Question, pk=question_id)
    form = ArtForm()
    return render(request, 'fcgt/index.html',  {'form': form})