Ejemplo n.º 1
0
def create_entry():
    entry_form = BaseEntryForm()
    if entry_form.validate_on_submit():
        title = request.form['title'].strip()
        type = request.form['type'].strip()
        if not title:
            flash('Property name cannot be empty', 'red')
        elif not type:
            flash('Types cannot be empty', 'red')
        elif Item.find_item(title):
            flash('Entry has been existed', 'yellow')
        else:
            status = Item.create_item(title, type)
            if status:
                Item.add_type(type)
                if current_user.is_authenticated:
                    current_user.add_create()
            return redirect(url_for('.item', title=title))
    else:
        for field, errors in entry_form.errors.items():
            for error in errors:
                flash(
                    "%s: %s" % (getattr(entry_form, field).label.text, error),
                    'red')
    types = Item.types()
    return render_template('create.html',
                           entry_form=entry_form,
                           title='create the entry',
                           types=types)
Ejemplo n.º 2
0
Archivo: items.py Proyecto: ThinkZ/pkyx
 def post(self):
     item = request.json or {}
     title = item.get('title', None)
     type = item.get('type', None)
     if title and type:
         id = Item.create_item(title, type)
         if id:
             return jsonify(status=True)
         else:
             return jsonify(status=False)
     return jsonify(status=False)
Ejemplo n.º 3
0
 def post(self):
     item = request.json or {}
     title = item.get('title', None)
     type = item.get('type', None)
     if title and type:
         id = Item.create_item(title, type)
         if id:
             return jsonify(status=True)
         else:
             return jsonify(status=False)
     return jsonify(status=False)
Ejemplo n.º 4
0
Archivo: views.py Proyecto: ThinkZ/pkyx
def create_entry():
    entry_form = BaseEntryForm()
    if entry_form.validate_on_submit():
        title = request.form['title'].strip()
        type = request.form['type'].strip()
        if not title:
            flash('属性不能为空', 'red')
        elif not type:
            flash('类型不能为空', 'red')
        elif Item.find_item(title):
            flash('词条已存在', 'yellow')
        else:
            status = Item.create_item(title, type)
            if status:
                Item.add_type(type)
                if current_user.is_authenticated:
                    current_user.add_create()
            return redirect(url_for('.item', title=title))
    else:
        for field, errors in entry_form.errors.items():
            for error in errors:
                flash("%s: %s" %(getattr(entry_form, field).label.text, error), 'red')
    types = Item.types()
    return render_template('create.html', entry_form=entry_form, title='创建条目', types=types)