def editreact_page(rname, rid): ''' This is a generic edit page for reactions ''' verify = verifyLogin( app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies) if verify: user = User() user.config = app.config user.get('uid', verify, g.rdb_conn) data = startData(user) data['active'] = 'dashboard' data['url'] = '/dashboard/edit-reactions/' + rname + '/' + rid tmpl = 'reactions/create.html' data['js_bottom'] = ['reactions/base.js', ] data['edit'] = True # Check Users Status if user.status != "active": data['url'] = '/dashboard/mod-subscription' tmpl = 'member/mod-subscription.html' else: reform = __import__( "reactionforms." + rname, globals(), locals(), ['ReactForm'], -1) form = reform.ReactForm(request.form) reaction = Reaction() reaction.config = app.config # If Edit get information reaction.get("rid", rid, g.rdb_conn) if reaction.uid == user.uid: data['reaction'] = { 'rid': reaction.rid, 'name': reaction.name, 'trigger': reaction.trigger, 'frequency': reaction.frequency, 'uid': reaction.uid, 'rtype': reaction.rtype, 'data': reaction.data } data['selects'] = [] for item in form.__iter__(): if item.type == "SelectField" or \ item.type == "SelectMultipleField": item.default = data['reaction']['data'][item.name] tmpl = 'reactions/create.html' if request.method == 'POST': if form.validate(): reaction2 = Reaction() reaction2.config = app.config reaction2.rid = reaction.rid reaction2.name = form.name.data reaction2.trigger = form.trigger.data reaction2.frequency = form.frequency.data reaction2.lastrun = reaction.lastrun reaction2.uid = user.uid reaction2.rtype = reaction.rtype tmpdata = {} for item in form.__iter__(): tmpdata[item.name] = item.data if item.type == "SelectField" or\ item.type == "SelectMultipleField": item.default = item.data reaction2.data = tmpdata data['reaction'] = { 'rid': reaction2.rid, 'name': reaction2.name, 'trigger': reaction2.trigger, 'frequency': reaction2.frequency, 'uid': reaction2.uid, 'rtype': reaction2.rtype, 'data': reaction2.data } if reaction.uid == user.uid: results = reaction2.editReaction(g.rdb_conn) else: results = False print("/dashboard/reactions/{0} - \ Reaction edit failed: not owner".format(rname)) flash("It doesn't appear that you own this reaction.", 'danger') if results == "exists": print("/dashboard/reactions/{0} - \ Reaction edit failed: exists".format(rname)) flash('This reaction seems to already exist. \ Try using a different name.', 'danger') elif results == "edit noexists": print("/dashboard/reactions/{0} - \ Reaction edit failed: exists".format(rname)) flash('This reaction can not be edited \ as it does not exist.', 'danger') elif results == "edit true": print("/dashboard/reactions/{0} - \ Reaction edit successful".format(rname)) flash('Reaction successfully edited.', 'success') elif results == "edit failed": print("/dashboard/reactions/{0} - \ Reaction edit failed: unknown".format(rname)) flash('Reaction not successfully edited.', 'danger') elif results is False: print("/dashboard/reactions/{0} - \ Reaction edit failed: unknown".format(rname)) flash('Could not create reaction.', 'danger') else: stathat.ez_count( app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Reaction Added', 1) print("/dashboard/reactions/{0} - \ Reaction edit success".format(rname)) flash('Reaction "{0}" successfully \ added.'.format(reaction2.name), 'danger') else: print("/dashboard/reactions/{0} - \ Reaction edit failed: form invalid".format(rname)) flash('Form is not valid.', 'danger') form.process() page = render_template(tmpl, data=data, form=form) return page else: flash('Please Login.', 'warning') return redirect(url_for('user.login_page'))
def addreaction_page(rname): verify = verifyLogin( app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies) if verify: user = User() user.config = app.config user.get('uid', verify, g.rdb_conn) data = startData(user) data['active'] = 'dashboard' data['url'] = '/dashboard/reactions/' + rname tmpl = 'reactions/create.html' data['js_bottom'] = ['reactions/base.js'] # Check Users Status if user.status != "active": data['url'] = '/dashboard/mod-subscription' tmpl = 'member/mod-subscription.html' else: reform = __import__( "reactionforms." + rname, globals(), locals(), ['ReactForm'], -1) form = reform.ReactForm(request.form) if request.method == 'POST': if form.validate(): reaction = Reaction() reaction.config = app.config reaction.name = form.name.data reaction.trigger = form.trigger.data reaction.frequency = form.frequency.data reaction.uid = user.uid reaction.rtype = rname tmpdata = {} for item in form.__iter__(): tmpdata[item.name] = item.data reaction.data = tmpdata if reaction.count(user.uid, g.rdb_conn) < data['rlimit']: results = reaction.createReaction(g.rdb_conn) else: results = "toomany" if results == "exists": print("/dashboard/reactions/{0} - \ Reaction creation failed: exists".format(rname)) flash('{0} seems to already exist. Try using a \ different name.'.format(reaction.name), 'danger') elif results == "edit noexists": print("/dashboard/reactions/{0} - Reaction \ edit failed: doesn't exist".format(rname)) flash('{0} cannot be edited as it does not \ exist.'.format(reaction.name), 'danger') elif results == "edit true": print("/dashboard/reactions/{0} - \ Reaction edit successful".format(rname)) flash('Reaction successfully edited: {0}.'.format( reaction.name), 'success') elif results == "edit failed": print("/dashboard/reactions/{0} - \ Reaction edit failed: unknown".format(rname)) flash('Reaction not successfully edited: {0}.'.format( reaction.name), 'danger') elif results == "toomany": print("/dashboard/reactions/{0} - \ Reaction creation failed: too many".format(rname)) flash('Could not create reaction: \ Too many reactions already created.', 'danger') elif results is False: print("/dashboard/reactions/{0} - \ Reaction creation failed: unknown".format(rname)) flash('Could not create reaction.', 'danger') else: stathat.ez_count( app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Reaction Added', 1) print("/dashboard/reactions/{0} - \ Reaction creation successful".format(rname)) flash('Reaction "{0}" successfully added.'.format( reaction.name), 'success') else: print("/dashboard/reactions/{0} - \ Reaction creation failed: form invalid".format(rname)) flash('Form is not valid.', 'success') page = render_template(tmpl, data=data, form=form) return page else: flash('Please Login.', 'warning') return redirect(url_for('user.login_page'))
def addreaction_page(rname): verify = verifyLogin(app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies) if verify: user = User() user.get('uid', verify, g.rdb_conn) data = startData(user) data['active'] = 'dashboard' data['url'] = '/dashboard/reactions/' + rname tmpl = 'reactions/' + rname + '.html' data['js_bottom'] = ['reactions/base.js', 'reactions/' + rname + '.js'] # Check Users Status if user.status != "active": data['url'] = '/dashboard/mod-subscription' tmpl = 'member/mod-subscription.html' else: reform = __import__("reactionforms." + rname, globals(), locals(), ['ReactForm'], -1) form = reform.ReactForm(request.form) if request.method == 'POST': if form.validate(): reaction = Reaction() reaction.name = form.name.data reaction.trigger = form.trigger.data reaction.frequency = form.frequency.data reaction.uid = user.uid reaction.rtype = rname tmpdata = {} for item in form.__iter__(): tmpdata[item.name] = item.data reaction.data = tmpdata if reaction.count(user.uid, g.rdb_conn) < data['rlimit']: results = reaction.createReaction(g.rdb_conn) else: results = "toomany" if results == "exists": data[ 'msg'] = "This reaction seems to already exist, try using a different name: %s" % reaction.name print( "/dashboard/reactions/%s - Reaction creation failed: exists" ) % rname data['error'] = True elif results == "edit noexists": data[ 'msg'] = "This reaction can not be edited as it does not exist: %s" % reaction.name print( "/dashboard/reactions/%s - Reaction edit failed: doesnt exist" ) % rname data['error'] = True elif results == "edit true": data[ 'msg'] = "Reaction successfully edited: %s" % reaction.name print( "/dashboard/reactions/%s - Reaction edit successful" ) % rname data['error'] = False elif results == "edit false": data[ 'msg'] = "Reaction not successfully edited: %s" % reaction.name print( "/dashboard/reactions/%s - Reaction edit failed: unknown" ) % rname data['error'] = True elif results == "toomany": data[ 'msg'] = "Could not create reaction: Too many reactions already created [%d]" % data[ 'rlimit'] print( "/dashboard/reactions/%s - Reaction creation failed: too many" ) % rname data['error'] = True elif results is False: data['msg'] = "Could not create reaction" print( "/dashboard/reactions/%s - Reaction creation failed: unknown" ) % rname data['error'] = True else: stathat.ez_count( app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Reaction Added', 1) data[ 'msg'] = 'Reaction "%s" successfully added' % reaction.name print( "/dashboard/reactions/%s - Reaction creation successful" ) % rname data['error'] = False else: data['msg'] = "Form is not valid" print( "/dashboard/reactions/%s - Reaction creation failed: form invalid" ) % rname data['error'] = True page = render_template(tmpl, data=data, form=form) return page else: return redirect(url_for('user.login_page'))
def editreact_page(rname, rid): ''' This is a generic edit page for reactions ''' verify = verifyLogin(app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies) if verify: user = User() user.get('uid', verify, g.rdb_conn) data = startData(user) data['active'] = 'dashboard' data['url'] = '/dashboard/edit-reactions/' + rname + '/' + rid tmpl = 'reactions/index.html' data['js_bottom'] = ['reactions/base.js', 'reactions/' + rname + '.js'] data['edit'] = True # Check Users Status if user.status != "active": data['url'] = '/dashboard/mod-subscription' tmpl = 'member/mod-subscription.html' else: reform = __import__("reactionforms." + rname, globals(), locals(), ['ReactForm'], -1) form = reform.ReactForm(request.form) reaction = Reaction() # If Edit get information reaction.get("rid", rid, g.rdb_conn) if reaction.uid == user.uid: data['reaction'] = { 'rid': reaction.rid, 'name': reaction.name, 'trigger': reaction.trigger, 'frequency': reaction.frequency, 'uid': reaction.uid, 'rtype': reaction.rtype, 'data': reaction.data } data['selects'] = [] for item in form.__iter__(): if item.type == "SelectField" or \ item.type == "SelectMultipleField": item.default = data['reaction']['data'][item.name] tmpl = 'reactions/' + rname + '.html' if request.method == 'POST': if form.validate(): reaction2 = Reaction() reaction2.rid = reaction.rid reaction2.name = form.name.data reaction2.trigger = form.trigger.data reaction2.frequency = form.frequency.data reaction2.lastrun = reaction.lastrun reaction2.uid = user.uid reaction2.rtype = reaction.rtype tmpdata = {} for item in form.__iter__(): tmpdata[item.name] = item.data if item.type == "SelectField" or\ item.type == "SelectMultipleField": item.default = item.data reaction2.data = tmpdata data['reaction'] = { 'rid': reaction2.rid, 'name': reaction2.name, 'trigger': reaction2.trigger, 'frequency': reaction2.frequency, 'uid': reaction2.uid, 'rtype': reaction2.rtype, 'data': reaction2.data } if reaction.uid == user.uid: results = reaction2.editReaction(g.rdb_conn) else: results = False data[ 'msg'] = "It doesn't appear that you own this reaction" print( "/dashboard/reactions/%s - Reaction edit failed: not owner" ) % rname data['error'] = True if results == "exists": data[ 'msg'] = "This reaction seems to already exist, try using a different name: %s" % reaction2.name print( "/dashboard/reactions/%s - Reaction edit failed: exists" ) % rname data['error'] = True elif results == "edit noexists": data[ 'msg'] = "This reaction can not be edited as it does not exist: %s" % reaction2.name print( "/dashboard/reactions/%s - Reaction edit failed: exists" ) % rname data['error'] = True elif results == "edit true": data[ 'msg'] = "Reaction successfully edited: %s" % reaction2.name print( "/dashboard/reactions/%s - Reaction edit successful" ) % rname data['error'] = False elif results == "edit false": data[ 'msg'] = "Reaction not successfully edited: %s" % reaction2.name print( "/dashboard/reactions/%s - Reaction edit failed: unknown" ) % rname data['error'] = True elif results is False: data['msg'] = "Could not create reaction" print( "/dashboard/reactions/%s - Reaction edit failed: unknown" ) % rname data['error'] = True else: stathat.ez_count( app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Reaction Added', 1) data[ 'msg'] = 'Reaction "%s" successfully added' % reaction2.name print("/dashboard/reactions/%s - Reaction edit success" ) % rname data['error'] = False else: data['msg'] = "Form is not valid" print( "/dashboard/reactions/%s - Reaction edit failed: form invalid" ) % rname data['error'] = True form.process() page = render_template(tmpl, data=data, form=form) return page else: return redirect(url_for('user.login_page'))
def addreaction_page(rname): verify = verifyLogin( app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies) if verify: user = User() user.get('uid', verify, g.rdb_conn) data = startData(user) data['active'] = 'dashboard' data['url'] = '/dashboard/reactions/' + rname tmpl = 'reactions/' + rname + '.html' data['js_bottom'] = ['reactions/base.js', 'reactions/' + rname + '.js'] # Check Users Status if user.status != "active": data['url'] = '/dashboard/mod-subscription' tmpl = 'member/mod-subscription.html' else: reform = __import__( "reactionforms." + rname, globals(), locals(), ['ReactForm'], -1) form = reform.ReactForm(request.form) if request.method == 'POST': if form.validate(): reaction = Reaction() reaction.name = form.name.data reaction.trigger = form.trigger.data reaction.frequency = form.frequency.data reaction.uid = user.uid reaction.rtype = rname tmpdata = {} for item in form.__iter__(): tmpdata[item.name] = item.data reaction.data = tmpdata if reaction.count(user.uid, g.rdb_conn) < data['rlimit']: results = reaction.createReaction(g.rdb_conn) else: results = "toomany" if results == "exists": print("/dashboard/reactions/{0} - \ Reaction creation failed: exists".format(rname)) flash('{0} seems to already exist. Try using a \ different name.'.format(reaction.name), 'danger') elif results == "edit noexists": print("/dashboard/reactions/{0} - Reaction \ edit failed: doesn't exist".format(rname)) flash('{0} cannot be edited as it does not \ exist.'.format(reaction.name), 'danger') elif results == "edit true": print("/dashboard/reactions/{0} - \ Reaction edit successful".format(rname)) flash('Reaction successfully edited: {0}.'.format( reaction.name), 'success') elif results == "edit failed": print("/dashboard/reactions/{0} - \ Reaction edit failed: unknown".format(rname)) flash('Reaction not successfully edited: {0}.'.format( reaction.name), 'danger') elif results == "toomany": print("/dashboard/reactions/{0} - \ Reaction creation failed: too many".format(rname)) flash('Could not create reaction: \ Too many reactions already created.', 'danger') elif results is False: print("/dashboard/reactions/{0} - \ Reaction creation failed: unknown".format(rname)) flash('Could not create reaction.', 'danger') else: stathat.ez_count( app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Reaction Added', 1) print("/dashboard/reactions/{0} - \ Reaction creation successful".format(rname)) flash('Reaction "{0}" successfully added.'.format( reaction.name), 'success') else: print("/dashboard/reactions/{0} - \ Reaction creation failed: form invalid".format(rname)) flash('Form is not valid.', 'success') page = render_template(tmpl, data=data, form=form) return page else: flash('Please Login.', 'warning') return redirect(url_for('user.login_page'))
def addreaction_page(rname): verify = verifyLogin( app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies) if verify: user = User() user.get('uid', verify, g.rdb_conn) data = startData(user) data['active'] = 'dashboard' data['url'] = '/dashboard/reactions/' + rname tmpl = 'reactions/' + rname + '.html' data['js_bottom'] = ['reactions/base.js', 'reactions/' + rname + '.js'] # Check Users Status if user.status != "active": data['url'] = '/dashboard/mod-subscription' tmpl = 'member/mod-subscription.html' else: reform = __import__( "reactionforms." + rname, globals(), locals(), ['ReactForm'], -1) form = reform.ReactForm(request.form) if request.method == 'POST': if form.validate(): reaction = Reaction() reaction.name = form.name.data reaction.trigger = form.trigger.data reaction.frequency = form.frequency.data reaction.uid = user.uid reaction.rtype = rname tmpdata = {} for item in form.__iter__(): tmpdata[item.name] = item.data reaction.data = tmpdata if reaction.count(user.uid, g.rdb_conn) < data['rlimit']: results = reaction.createReaction(g.rdb_conn) else: results = "toomany" if results == "exists": data['msg'] = "This reaction seems to already exist, try using a different name: %s" % reaction.name print("/dashboard/reactions/%s - Reaction creation failed: exists") % rname data['error'] = True elif results == "edit noexists": data['msg'] = "This reaction can not be edited as it does not exist: %s" % reaction.name print("/dashboard/reactions/%s - Reaction edit failed: doesnt exist") % rname data['error'] = True elif results == "edit true": data['msg'] = "Reaction successfully edited: %s" % reaction.name print("/dashboard/reactions/%s - Reaction edit successful") % rname data['error'] = False elif results == "edit false": data['msg'] = "Reaction not successfully edited: %s" % reaction.name print("/dashboard/reactions/%s - Reaction edit failed: unknown") % rname data['error'] = True elif results == "toomany": data['msg'] = "Could not create reaction: Too many reactions already created [%d]" % data['rlimit'] print("/dashboard/reactions/%s - Reaction creation failed: too many") % rname data['error'] = True elif results is False: data['msg'] = "Could not create reaction" print("/dashboard/reactions/%s - Reaction creation failed: unknown") % rname data['error'] = True else: stathat.ez_count( app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Reaction Added', 1) data['msg'] = 'Reaction "%s" successfully added' % reaction.name print("/dashboard/reactions/%s - Reaction creation successful") % rname data['error'] = False else: data['msg'] = "Form is not valid" print("/dashboard/reactions/%s - Reaction creation failed: form invalid") % rname data['error'] = True page = render_template(tmpl, data=data, form=form) return page else: return redirect(url_for('user.login_page'))
def editreact_page(rname, rid): ''' This is a generic edit page for reactions ''' verify = verifyLogin(app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies) if verify: user = User() user.get('uid', verify, g.rdb_conn) data = startData(user) data['active'] = 'dashboard' data['url'] = '/dashboard/edit-reactions/' + rname + '/' + rid tmpl = 'reactions/index.html' data['js_bottom'] = [ 'reactions/base.js', 'reactions/' + rname + '.js' ] data['edit'] = True ## Check Users Status if user.status != "active": data['url'] = '/dashboard/mod-subscription' tmpl = 'mod-subscription.html' else: reform = __import__("reactionforms." + rname, globals(), locals(), ['ReactForm'], -1) form = reform.ReactForm(request.form) reaction = Reaction() ## If Edit get information reaction.get("rid", rid, g.rdb_conn) if reaction.uid == user.uid: data['reaction'] = { 'rid': reaction.rid, 'name': reaction.name, 'trigger': reaction.trigger, 'frequency': reaction.frequency, 'uid': reaction.uid, 'rtype': reaction.rtype, 'data': reaction.data } data['selects'] = [] for item in form.__iter__(): if item.type == "SelectField" or item.type == "SelectMultipleField": item.default = data['reaction']['data'][item.name] tmpl = 'reactions/' + rname + '.html' if request.method == 'POST': if form.validate(): reaction2 = Reaction() reaction2.rid = reaction.rid reaction2.name = form.name.data reaction2.trigger = form.trigger.data reaction2.frequency = form.frequency.data reaction2.uid = user.uid reaction2.rtype = reaction.rtype tmpdata = {} for item in form.__iter__(): tmpdata[item.name] = item.data if item.type == "SelectField" or item.type == "SelectMultipleField": item.default = item.data reaction2.data = tmpdata data['reaction'] = { 'rid': reaction2.rid, 'name': reaction2.name, 'trigger': reaction2.trigger, 'frequency': reaction2.frequency, 'uid': reaction2.uid, 'rtype': reaction2.rtype, 'data': reaction2.data } if reaction.uid == user.uid: results = reaction2.editReaction(g.rdb_conn) else: results = False data['msg'] = "I Doesn't appear that you own this reaction" print("/dashboard/reactions/%s - Reaction edit failed: not owner") % rname data['error'] = True if results == "exists": data['msg'] = "This reaction seems to already exist, try using a different name: %s" % reaction2.name print("/dashboard/reactions/%s - Reaction edit failed: exists") % rname data['error'] = True elif results == "edit noexists": data['msg'] = "This reaction can not be edited as it does not exist: %s" % reaction2.name print("/dashboard/reactions/%s - Reaction edit failed: exists") % rname data['error'] = True elif results == "edit true": data['msg'] = "Reaction successfully edited: %s" % reaction2.name print("/dashboard/reactions/%s - Reaction edit successful") % rname data['error'] = False elif results == "edit false": data['msg'] = "Reaction not successfully edited: %s" % reaction2.name print("/dashboard/reactions/%s - Reaction edit failed: unknown") % rname data['error'] = True elif results == False: data['msg'] = "Could not create reaction" print("/dashboard/reactions/%s - Reaction edit failed: unknown") % rname data['error'] = True else: stathat.ez_count(app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Reaction Added', 1) data['msg'] = 'Reaction "%s" successfully added' % reaction2.name print("/dashboard/reactions/%s - Reaction edit success") % rname data['error'] = False else: data['msg'] = "Form is not valid" print("/dashboard/reactions/%s - Reaction edit failed: form invalid") % rname data['error'] = True form.process() page = render_template(tmpl, data=data, form=form) return page else: return redirect(url_for('login_page'))