本文整理汇总了Python中uliweb.functions.get_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_model函数的具体用法?Python get_model怎么用?Python get_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deletefile
def deletefile(f_id):
from uliweb.utils.common import log
fileserving = AttachmentsFileServing()
Attachment = functions.get_model('generic_attachment')
Tables = functions.get_model('tables')
obj = Attachment.get(int(f_id))
if obj:
#get tablename
tablename = Tables.get(obj.table_id)
check_func = settings.Generic_Attachment_Download_Checking.get(tablename)
if check_func:
enable = check_func(obj.content_object, request.user, 'delete')
else:
enable = True
if enable:
filename = obj.filepath
obj.delete()
try:
fileserving.delete_filename(filename)
except Exception as e:
log.exception(e)
else:
raise Forbidden("You have no permission to delete the file.")
return json({'success':True})
示例2: process_response
def process_response(self, request, response):
from uliweb import settings, functions, json_dumps
import base64
#if not debug status it'll quit
if not settings.get_var('GLOBAL/DEBUG'):
return response
S = functions.get_model('uliwebrecorderstatus')
s = S.all().one()
if not s or s.status == 'E':
return response
if settings.get_var('ULIWEBRECORDER/response_text'):
try:
text = response.data
except Exception as e:
text = str(e)
else:
text = ''
#test if post_data need to convert base64
if not request.content_type:
post_data_is_text = True
else:
post_data_is_text = self.test_text(request.content_type)
if not post_data_is_text:
post_data = base64.encodestring(request.data)
else:
post_data = json_dumps(request.POST.to_dict())
#test if response.data need to convert base64
response_data_is_text = self.test_text(response.content_type)
if not response_data_is_text:
response_data = base64.encodestring(text)
else:
response_data = text
R = functions.get_model('uliwebrecorder')
if request.user:
user_id = request.user.id
else:
user_id = None
max_content_length = settings.get_var('ULIWEBRECORDER/max_content_length')
if len(response_data) > max_content_length:
msg = "Content length is great than %d so it will be omitted." % max_content_length
log.info(msg)
response_data = msg
response_data_is_text = True
recorder = R(method=request.method,
url=request_url(request),
post_data_is_text=post_data_is_text,
post_data=post_data, user=user_id,
response_data=response_data,
response_data_is_text=response_data_is_text,
status_code=response.status_code,
)
recorder.save()
return response
示例3: __init__
def __init__(self, digital_name, content_name, entity=None):
self.panel = functions.get_model('dashboardpanel')
self.layout = functions.get_model('dashboardpanellayout')
self.digital_name = digital_name
self.content_name = content_name
if isinstance(entity, (tuple, list)) or isinstance(entity, orm.Model):
self.entity = entity
else:
self.entity = None
示例4: view_workflow
def view_workflow(self, id):
Job = functions.get_model('cron_job')
Task = functions.get_model('cron_task')
job = Job.get(int(id))
action = request.GET.get('action')
if action == 'get_tasks':
return self._do_get_tasks(job)
else:
return {'job':job}
示例5: __init__
def __init__(self, digital_name, content_name, entity=None):
self.panel = functions.get_model('dashboardpanel')
self.layout = functions.get_model('dashboardpanellayout')
self.tables = functions.get_model('tables')
self.digital_name = digital_name
self.content_name = content_name
self.entity = None
self.dashboard_type = None
if isinstance(entity, (tuple, list)) and len(entity) == 2:
self.entity = entity
self.dashboard_type = self.talbes.get_talbe(entity[0]).id
elif isinstance(entity, orm.Model):
self.entity = entity
self.dashboard_type = self.table.get_table(entity.__class__.tablename).id
示例6: get_model_columns
def get_model_columns(model, fields=None, meta="Table"):
"""
Get fields info according model class, the fields just like ListView fields definition
:param fields: A list
:param meta: if no fields, it'll use meta
"""
from copy import deepcopy
fields = fields or []
model = functions.get_model(model)
if not fields:
if hasattr(model, meta):
fields = getattr(model, meta).fields
else:
fields = [x for x, y in model._fields_list]
fields_list = []
for x in fields:
if isinstance(x, (str, unicode)):
f = get_grid_column(model, x)
elif isinstance(x, dict):
name = x["name"]
f = deepcopy(x)
if "title" not in x:
f.update(get_grid_column(model, name))
else:
raise ValueError("Field should be string or dict type, but {!r} found".format(x))
fields_list.append(f)
return fields_list
示例7: delete
def delete(self):
model = request.GET.get('model', '')
ids = request.POST.getlist('ids')
Model = functions.get_model(model)
Model.filter(Model.c.id.in_(ids)).remove()
return json({'success':True, 'message':'删除成功'})
示例8: view
def view(self, event_id):
"""
显示某个活动的详细信息
"""
Request = functions.get_model('eventrequest')
event = self.model.get(int(event_id))
if not event:
error("活动记录不存在")
def _has_register(obj):
if request.user:
if Request.filter((Request.c.event==obj.id) & (Request.c.user==request.user.id)).count() > 0:
return 'already'
else:
return 'not'
else:
return 'need_login'
def _get_users(obj):
User = functions.get_model('user')
users = []
for row in Request.filter((Request.c.event==obj.id) & (Request.c.user==User.c.id)).order_by(Request.c.create_date).values(User.c.username, User.c.id, Request.c.create_date):
users.append(row)
return users
template_data = {'has_register':_has_register(event), 'users':_get_users(event)}
view = functions.DetailView(self.model, obj=event, template_data=template_data)
return view.run()
示例9: req
def req(self, event_id):
"""
活动报名处理
返回值是json = {'success':True|False, 'message':xxxx, 'data':{'counts':number}}
"""
Request = functions.get_model('eventrequest')
event_id = int(event_id)
event = self.model.get(event_id)
if not event:
return json({'success':False, 'message':'活动不存在'})
#todo 检查活动是否已经结束
#检查用户是否已经登录
if request.user:
if Request.filter((Request.c.event==event_id) & (Request.c.user==request.user.id)).count() == 0:
obj = Request(event=event_id, user=request.user.id)
obj.save()
event.counts += 1
event.save()
return json({'success':True, 'message':'报名成功', 'data':{'counts':event.counts}})
else:
message = '你已经报过名了'
else:
message = '你还没登录,请登录后再报名'
return json({'success':False, 'message':message})
示例10: view
def view(self, id):
"""
查看某个作业的执行信息
"""
# Detail = functions.get_model('cron_job_details')
Task = functions.get_model('async_tasks')
job = functions.get_object('cron_job', int(id))
template_data = {'job_id':id, 'job':job}
# condition = Detail.c.cron_job==int(id)
fields_convert_map = ['view_details', 'status']
fields = [
{'name':'task_id', 'width':250},
{'name':'startup_time', 'width':150},
{'name':'started_time', 'width':150},
{'name':'finished_time', 'width':150},
{'name':'status', 'width':60},
{'name':'view_details', 'width':100},
]
return self._list('async_tasks',
query=job.instances.fields('id', 'task_id',
'startup_time', 'started_time',
'finished_time', 'status'
),
queryview=None,
template_data=template_data,
fields=fields,
# condition=condition,
order_by=Task.c.startup_time.desc(),
fields_convert_map=fields_convert_map)
示例11: call
def call(args, options, global_options):
from uliweb import settings
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
check_point = settings.get_var('ASYNC_TASKS/check_point')
log.info('=============================')
log.info(' Async Task Daemon Starting')
log.info('=============================')
log.info('Daemon process %d' % os.getpid())
log.info('Check point %ds' % check_point)
Task = functions.get_model('async_tasks')
query = Task.filter(~Task.c.status.in_([SUCCESS, CANCEL, FAILED])).\
order_by(Task.c.created_time)
redis = functions.get_redis()
while not is_exit:
Reset()
for row in query:
try:
#log.debug('Ready to process async task {} - {}'.format(row.task_id, row.command_name))
process_task(row)
except Exception as e:
log.exception(e)
beat = redis.brpop('async_tasks_beat', check_point)
#to prevent database submit slow than redis
time.sleep(0.5)
示例12: get_sequence
def get_sequence(key, default=1, step=1, retry_times=None, retry_waittime=None):
from uliweb.orm import SaveError
from uliweb import settings
assert step > 0 and default > 0
Sequence = functions.get_model('sequence')
i = 0
waittime = retry_waittime or settings.get_var('SEQUENCE/retry_waittime', 0.05)
retry_times = retry_times or settings.get_var('SEQUENCE/retry_times', 3)
while 1:
try:
row = Sequence.get(Sequence.c.key==key)
if row:
row.value = row.value + step
row.save(version=True)
else:
row = Sequence(key=key, value=(default+step-1))
row.save()
break
except SaveError:
i += 1
if i == retry_times:
raise
else:
sleep(waittime)
return row.value
示例13: get_jobs
def get_jobs():
global jobs
jobs = SortedDict()
Job = functions.get_model('cron_job')
for row in Job.filter(Job.c.enabled==True):
jobs[row.id] = row
示例14: _get_columns
def _get_columns(self, options, global_options, args, tables=None):
from uliweb import functions
from uliweb.orm import ManyToMany, ModelNotFound
from uliweb.contrib.orm.commands import get_tables, get_sorted_tables
if not tables:
if args:
apps = args
else:
apps = self.get_apps(global_options)
else:
apps = None
tables = get_sorted_tables(get_tables(global_options.apps_dir, apps, tables=tables,
engine_name=options.engine,
settings_file=global_options.settings,
local_settings_file=global_options.local_settings))
for tablename, table in tables:
try:
t = functions.get_model(tablename)
except ModelNotFound:
continue
for name, f in t._fields_list:
if not isinstance(f, ManyToMany):
yield tablename, f.to_column_info()
示例15: commit
def commit(self, session=None):
Task = functions.get_model('async_tasks')
if session:
Task = Task.use(session)
if self.parent_task and isinstance(self.parent_task, AsyncCommand):
parent_task_id = self.parent_task.task_id
else:
parent_task_id = self.parent_task
task = Task(task_id=self.task_id,
title=self.title,
parent_task=parent_task_id,
children_count=len(self.tasks),
command_name=self.name,
command_info=self._make_info(),
depend_tasks=self.depend_tasks,
startup_time=self.startup_time or date.now(),
timeout=self.timeout,
max_retry_times=self.max_retry_times,
retry_time_interval=self.retry_time_interval,
user_id=self.user_id,
src_ip=self.src_ip,
correlation=self.correlation,
correlation_link=self.correlation_link)
task.update(**self.kwargs)
task.save()
self.task = task
#commit child tasks
for t in self.tasks.values():
t.commit()
log.info('Commit a task %s' % self.task_id)
return task