Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:wufeifei/cobra
Browse files Browse the repository at this point in the history
  • Loading branch information
FeeiCN committed Aug 29, 2016
2 parents 129f40d + f29f252 commit 0a0ca96
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions app/controller/backend/TasksController.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import datetime

from flask import redirect, render_template, request, jsonify
from flask import render_template, request, jsonify
from sqlalchemy.exc import SQLAlchemyError

from . import ADMIN_URL
from app import web, db
from app.CommonClass.ValidateClass import ValidateClass
from app.CommonClass.ValidateClass import ValidateClass, login_required
from app.models import CobraTaskInfo
from utils import config

Expand All @@ -18,9 +19,8 @@

# show all tasks
@web.route(ADMIN_URL + '/tasks/<int:page>', methods=['GET'])
@login_required
def tasks(page):
if not ValidateClass.check_login():
return redirect(ADMIN_URL + '/index')

per_page = 10
tasks = CobraTaskInfo.query.order_by(CobraTaskInfo.id.desc()).limit(per_page).offset((page - 1) * per_page).all()
Expand All @@ -37,29 +37,28 @@ def tasks(page):

# del the special task
@web.route(ADMIN_URL + '/del_task', methods=['POST'])
@login_required
def del_task():
if not ValidateClass.check_login():
return redirect(ADMIN_URL + '/index')

vc = ValidateClass(request, "id")
ret, msg = vc.check_args()
if not ret:
return jsonify(tag="danger", msg=msg)

task = CobraTaskInfo.query.filter_by(id=vc.vars.task_id).first()
task = CobraTaskInfo.query.filter_by(id=vc.vars.id).first()
try:
db.session.delete(task)
db.session.commit()
return jsonify(tag='success', msg='delete success.')
except:
except SQLAlchemyError as e:
print e
return jsonify(tag='danger', msg='unknown error.')


# edit the special task
@web.route(ADMIN_URL + '/edit_task/<int:task_id>', methods=['GET', 'POST'])
@login_required
def edit_task(task_id):
if not ValidateClass.check_login():
return redirect(ADMIN_URL + '/index')

if request.method == 'POST':

Expand Down Expand Up @@ -95,7 +94,8 @@ def edit_task(task_id):
db.session.add(task)
db.session.commit()
return jsonify(tag='success', msg='save success.')
except:
except SQLAlchemyError as e:
print e
return jsonify(tag='danger', msg='save failed. Try again later?')
else:
task = CobraTaskInfo.query.filter_by(id=task_id).first()
Expand Down

0 comments on commit 0a0ca96

Please sign in to comment.