本文整理汇总了Python中uliweb.functions.get_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_model函数的具体用法?Python get_model怎么用?Python get_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_model函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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})
开发者ID:chyhutu,项目名称:plugs,代码行数:30,代码来源:views.py
示例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
开发者ID:28sui,项目名称:uliweb,代码行数:59,代码来源:middle_recorder.py
示例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
开发者ID:naomhan,项目名称:uliweb-peafowl,代码行数:9,代码来源:common.py
示例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}
开发者ID:limodou,项目名称:uliweb-apps,代码行数:10,代码来源:views.py
示例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
开发者ID:uliwebext,项目名称:uliweb-peafowl,代码行数:14,代码来源:common.py
示例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
开发者ID:limodou,项目名称:uliweb,代码行数:30,代码来源:__init__.py
示例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':'删除成功'})
开发者ID:limodou,项目名称:uliweb-admin,代码行数:7,代码来源:views.py
示例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()
开发者ID:Kevin-Sun,项目名称:codepark,代码行数:30,代码来源:views.py
示例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})
开发者ID:Kevin-Sun,项目名称:codepark,代码行数:28,代码来源:views.py
示例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)
开发者ID:limodou,项目名称:uliweb-apps,代码行数:29,代码来源:views.py
示例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)
开发者ID:limodou,项目名称:uliweb-apps,代码行数:30,代码来源:daemon.py
示例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
开发者ID:28sui,项目名称:uliweb,代码行数:28,代码来源:__init__.py
示例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
开发者ID:limodou,项目名称:uliweb-apps,代码行数:7,代码来源:daemon.py
示例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()
开发者ID:28sui,项目名称:uliweb,代码行数:26,代码来源:datadict_subcommands.py
示例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
开发者ID:limodou,项目名称:uliweb-apps,代码行数:33,代码来源:__init__.py
示例16: teacher
def teacher(user):
"""
是否是教师角色
"""
Teacher = functions.get_model("class_teacher")
obj = Teacher.get(Teacher.c.teacher == user.id)
return bool(obj)
开发者ID:woerwin,项目名称:uliwebzone,代码行数:7,代码来源:__init__.py
示例17: _sync_parent
def _sync_parent(self, parent):
from sqlalchemy import select, func
from uliweb.orm import do_
M = functions.get_model('async_tasks')
sql = select([M.c.status, func.count('*')], M.c.parent_task==parent.task_id,
from_obj=[M.table]).group_by(M.c.status)
status = {}
for row in do_(sql):
status[row[0]] = row[1]
queued = status.get('0', 0)
success = status.get('1', 0)
started = status.get('2', 0)
error = status.get('E', 0)
failed = status.get('F', 0)
cancel = status.get('C', 0)
if started:
parent.status = '2'
elif failed:
parent.status = 'F'
elif error:
parent.status = 'E'
elif (queued and not filter(None, [success, started, error, failed, cancel])):
parent.status = '0'
elif (success and not filter(None, [queued, started, error, failed])):
parent.status = '1'
elif (cancel and not filter(None, [queued, success, started, error, failed])):
parent.status = 'C'
开发者ID:limodou,项目名称:uliweb-apps,代码行数:30,代码来源:__init__.py
示例18: downloadfile
def downloadfile(f_id):
from uliweb import request
import urllib2
fileserving = AttachmentsFileServing()
Attachment = functions.get_model('generic_attachment')
Tables = functions.get_models('tables')
obj = Attachment.get(int(f_id))
if not obj:
error(_("Can't find the file record of {0}").format(f_id))
#get tablename
tablename = Tables.get_tablename(obj.table_id)
check_func = settings.Generic_Attachment_Download_Checking.get(tablename)
if check_func:
enable = check_func(obj.content_object, request.user, 'download')
else:
enable = True
if enable:
alt_filename = urllib2.unquote(obj.filename)
_filename = fileserving.get_filename(filename, False, convert=False)
x_filename = filename
return fileserving.download(alt_filename, real_filename=_filename, x_filename=x_filename)
else:
raise Forbidden("You have no permission to download the file.")
开发者ID:chyhutu,项目名称:plugs,代码行数:27,代码来源:views.py
示例19: get_attachments
def get_attachments(slug_or_obj):
Attachments = functions.get_model('generic_attachment')
if isinstance(slug_or_obj, (str, unicode)):
query = Attachments.filter(Attachments.c.slug==slug_or_obj)
else:
query = Attachments.content_object.filter(slug_or_obj)
return query
开发者ID:chyhutu,项目名称:plugs,代码行数:8,代码来源:__init__.py
示例20: del_comment
def del_comment(id):
Note = functions.get_model('note')
n = Note.get(int(id))
if n:
n.delete()
return redirect(url_for(index))
else:
error("No such record [%s] existed" % id)
开发者ID:limodou,项目名称:uliweb-doc,代码行数:8,代码来源:views.py
注:本文中的uliweb.functions.get_model函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论