本文整理汇总了Python中models.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dash
def dash(self, **params):
config = Config.readconfig()
# Attempts to read the config.
if config == 0:
# Else it uses the Arguements to create a config.
# organises make config data
data = {str(key):str(value) for key,value in params.items()}
url = []
for i, v in data.items():
url.append(v)
# makes config
Config.mkconfig(url)
else:
# If True it saves the data to a variable
URLS = config["URLS"]
refresh = config["refresh"]
# Runs the script in the Parsing Model. Parses the XML Files from URL
parse = Parsing.system()
refresh = config["refresh"]
# Returns the template with Parsed XML Data and The Refresh Integer from the Config.
return self.render_template('home/dash.html', template_vars={'data': parse, 'refresh': refresh})
示例2: set_config
def set_config(name, value):
config = Config.query.filter(Config.name==name).first()
if config is None:
config = Config(name = name, value=value)
else:
config.value = value
db.session.commit()
return config.value
示例3: is_open_or_close
def is_open_or_close():
c = Config.query().get()
if not c:
c = Config()
c.is_open = False
c.put()
return False
return c.is_open
示例4: set_auth_secret
def set_auth_secret(secret):
"""
Sets the auth secret.
"""
from models import Config
secret_config = Config()
secret_config.key = "auth_secret"
secret_config.value = secret
secret_config.put()
return secret_config
示例5: config_list
def config_list(user):
if request.method == "GET":
configs = [c.json() for c in user.configs]
return _json_response(configs)
elif request.method == "POST":
if request.json is None:
return Response(status=400)
c = Config(user, request.json)
db.session.add(c)
db.session.commit()
return _json_response(c.json())
示例6: load_instagram
def load_instagram():
access_token = Config.query(Config.name == 'instagram_access_token').order(-Config.date_added).get()
if access_token is None:
return Response(json.dumps({ 'error': 'instagram_access_token configuration was not found.' }), status=500, mimetype='application/json');
client_secret = Config.query(Config.name == 'instagram_client_secret').order(-Config.date_added).get()
if client_secret is None:
return Response(json.dumps({ 'error': 'instagram_client_secret configuration was not found.' }), status=500, mimetype='application/json');
return instagram_import.import_media(access_token.value, client_secret.value)
示例7: addclusterconfig
def addclusterconfig():
print request
if request.method == 'POST':
# save a new config
nc = Config()
nc.cluster_name = request.form['cluster_name']
nc.cluster_etcd_locator_url = request.form['cluster_etcd_locator_url']
nc.private_key = request.form['primary_key']
db.session.add(nc)
db.session.commit()
return json.dumps({'status': 'OK', 'cluster': {'id': nc.id, 'cluster_name': nc.cluster_name,
'cluster_etcd_locator_url': nc.cluster_etcd_locator_url}})
else:
print request
示例8: load_tracker
def load_tracker():
tracker_url = Config.query(Config.name == 'tracker_url').order(-Config.date_added).get()
if tracker_url is None:
return Response(json.dumps({ 'error': 'tracker_url configuration was not found.' }), status=500, mimetype='application/json');
tracker_type = Config.query(Config.name == 'tracker_type').order(-Config.date_added).get()
if tracker_type is None:
return Response(json.dumps({ 'error': 'tracker_type configuration was not found.' }), status=500, mimetype='application/json');
if tracker_type.value == 'delorme':
return delorme.load_data(tracker_url.value)
elif tracker_type.value == 'spot':
return Response(json.dumps({ 'error': 'tracker not supported.' }), status=400, mimetype='application/json');
else:
return Response(json.dumps({ 'error': 'tracker not supported.' }), status=400, mimetype='application/json');
示例9: api_edit_config
def api_edit_config():
config = Config.get()
# update all fields, no checks (TODO)
config_fields = config.fields_set(exclude_fields=['id', 'password'])
fields = config_fields & set(request.json.keys())
for field in fields:
setattr(config, field, request.json[field])
# change password if the "pw" field isnt empty
pw = request.json.get('pw')
if pw:
Config.change_password(pw)
db.session.merge(config)
db.session.commit()
Config.refresh_instance() # not necessary ?
return jsonify({'msg': 'Success !'})
示例10: confirmed
def confirmed(self, **params):
url = []
# setup update config data
for k, v in params.items():
if k != "refresh" and k != "time":
url.append(v)
elif k == "refresh":
refresh = v
elif k == "time":
time = v
# update config
Config.updateconfig(url, refresh, time)
# redirect to dashboard
raise cherrypy.HTTPRedirect("dash")
示例11: admin_settings_update
def admin_settings_update():
params = utils.flat_multi(request.form)
params.pop("csrf_token")
with app.app_context():
for key in params:
config = Config.query.filter_by(key=key).first()
if config is None:
config = Config(key, params[key])
else:
new = params[key]
if config.value != new:
config.value = params[key]
db.session.add(config)
db.session.commit()
return { "success": 1, "message": "Success!" }
示例12: new_feed_worker
def new_feed_worker(url, favicon_dir, answer_box, manager_box):
logger.info("Fetching feed... [%s]", url)
try:
fetched = fetch_and_parse_feed(url)
feed_dict, real_url = fetched['feed'], fetched['real_url']
except FetchingException:
return answer_box.put(Exception("Error with feed: " + url))
feed = FeedFromDict(feed_dict, Config.get())
feed.url = sanitize_url(real_url) # set the real feed url
logger.info("Fetching favicon... [%s]", feed.url)
feed.favicon_path = save_favicon(fetch_favicon(feed.url), favicon_dir)
db.session.add(feed)
for e in feed_dict['entries'][::-1]:
entry = EntryFromDict(e, feed.url)
entry.feed = feed # set the corresponding feed
db.session.add(entry)
db.session.commit()
most_recent_entry = feed.entries.order_by(Entry.updated.desc()).first()
feed.updated = most_recent_entry.updated
db.session.commit()
answer_box.put(feed)
manager_box.put({'type': 'new-deadline-worker', 'feed_id': feed.id})
manager_box.put({'type': 'refresh-cache', 'feed_id': feed.id})
示例13: logall
def logall():
config = Config.readconfig()
while config != 0:
url = config["URLS"]
if os.path.exists("logs"):
pass
else:
os.mkdir("logs")
thread_list = []
for m in url:
# Instantiates the thread
# (i) does not make a sequence, so (i,)
t = threading.Thread(target=logs.log, args=(m,))
# Sticks the thread in a list so that it remains accessible
thread_list.append(t)
# Starts threads
for thread in thread_list:
thread.start()
# This blocks the calling thread until the thread whose join() method is called is terminated.
# From http://docs.python.org/2/library/threading.html#thread-objects
for thread in thread_list:
thread.join()
示例14: index
def index(self):
config = Config.readconfig()
# Check if there is a config.
if config != 0:
# Else redirect the User to the Dashboard
raise cherrypy.HTTPRedirect("Home/dash")
else:
# If True Return the template
return self.render_template('home/index.html')
示例15: register
def register(request):
if request.method == "GET":
template = get_template('registration/register.html')
context = RequestContext(request, {})
return HttpResponse(template.render(context))
elif request.method == "POST":
username = strip_tags(request.POST.get('username'))
password = make_password(request.POST.get('password'))
title = "Pagina de " + username
user = User(username=username, password=password)
user.save()
user = User.objects.get(username=username)
config = Config(user=user, title=title, color='#D7C4B7', size=14)
config.save()
return HttpResponseRedirect("/")
else:
template = get_template('notfound.html')
return HttpResponseNotFound(template.render())