本文整理汇总了Python中utils.db_utils.db函数的典型用法代码示例。如果您正苦于以下问题:Python db函数的具体用法?Python db怎么用?Python db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, name=None,
# portal_plan_id=None,
logo_file_id=None,
company_owner=None,
favicon_file_id=None,
lang='uk',
host=None, divisions=[], portal_layout_id=None):
self.name = name
self.lang = lang
self.logo_file_id = logo_file_id
self.favicon_file_id = favicon_file_id
self.host = host
self.divisions = divisions
self.portal_layout_id = portal_layout_id if portal_layout_id else db(PortalLayout).first().id
self.own_company = company_owner
self.company_members = [
MemberCompanyPortal(portal=self, company=company_owner, status=MemberCompanyPortal.STATUSES['ACTIVE'],
plan=db(MemberCompanyPortalPlan).first())]
# self.own_company.company_portals = db(MemberCompanyPortalPlan).first()
# db(MemberCompanyPortalPlan).first().portal_companies.add(MemberCompanyPortal(company=self.own_company))
# self.company_assoc = [MemberCompanyPortal(portal = self,
# company = self.own_company,
# company_portal_plan_id=db(MemberCompanyPortalPlan).first().id)]
pass
开发者ID:spaun299,项目名称:profireader,代码行数:35,代码来源:portal.py
示例2: list_reader_load
def list_reader_load(json):
next_page = json.get('next_page') if json.get('next_page') else 1
search_text = request.args.get('search_text') or ''
article_fields = 'title|id|subtitle|short|image_file_id|subtitle|publishing_tm|read_count,company.name|logo_file_id|id,' \
'division.name,portal.name|host|logo_file_id|id'
favorite = request.args.get('favorite') == 'True'
localtime = time.gmtime(time.time())
filter = and_(Publication.portal_division_id == db(PortalDivision).filter(
PortalDivision.portal_id == db(UserPortalReader, user_id=g.user.id).subquery().c.portal_id).subquery().c.id,
Publication.status == Publication.STATUSES['PUBLISHED'],
Publication.publishing_tm < datetime.datetime(*localtime[:6])) if not favorite\
else (Publication.id == db(ReaderPublication, user_id=g.user.id,
favorite=True).subquery().c.article_portal_division_id)
articles, pages, page = Search().search({'class': Publication,
'filter': filter,
'tags': True, 'return_fields': article_fields}, page=1,
items_per_page=5*next_page,
search_text=search_text)
list_articles = Publication.get_list_reader_articles(articles)
return {
'end': True if pages == 1 or pages == 0 else False,
'articles': list_articles,
'pages': pages,
'current_page': page,
'page_buttons': Config.PAGINATION_BUTTONS,
# 'portals': portals,
'favorite': favorite
}
开发者ID:CNazar,项目名称:profireader,代码行数:28,代码来源:views_reader.py
示例3: crop_image
def crop_image(image_id, coordinates, zoom, params):
from ..models.company import Company
image_query = db(File, id=image_id).one() # get file object
company_owner = db(Company).filter(or_(
Company.system_folder_file_id == image_query.root_folder_id,
Company.journalist_folder_file_id == image_query.root_folder_id)).one() # get company file owner
return File.crop(image_query, coordinates, zoom, company_owner, params)
开发者ID:Greckas,项目名称:profireader,代码行数:7,代码来源:views_file.py
示例4: subquery_company_articles
def subquery_company_articles(search_text=None, company_id=None, **kwargs):
sub_query = db(ArticleCompany, company_id=company_id)
if 'filter' in kwargs.keys():
if 'material_status' in kwargs['filter'].keys():
sub_query = db(ArticleCompany, company_id=company_id, status=kwargs['filter']['material_status'])
if 'publication_status' in kwargs['filter'].keys() or 'portals' in kwargs['filter'].keys():
sub_query = sub_query.join(ArticlePortalDivision,
ArticlePortalDivision.article_company_id == ArticleCompany.id)
if 'publication_status' in kwargs['filter'].keys():
sub_query = sub_query.filter(ArticlePortalDivision.status == kwargs['filter']['publication_status'])
if 'portals' in kwargs['filter'].keys():
sub_query = sub_query.join(PortalDivision,
PortalDivision.id == ArticlePortalDivision.portal_division_id). \
filter(PortalDivision.portal_id == kwargs['filter']['portals'])
if search_text:
if 'title' in search_text:
sub_query = sub_query.filter(ArticleCompany.title.ilike("%" + search_text['title'] + "%"))
if 'sort' in kwargs.keys():
if 'date' in kwargs['sort'].keys():
sub_query = sub_query.order_by(ArticleCompany.md_tm.asc()) if kwargs[
'sort']['date'] == 'asc' else sub_query.order_by(
ArticleCompany.md_tm.desc())
else:
sub_query = sub_query.order_by(expression.desc(ArticleCompany.md_tm))
return sub_query
开发者ID:bubanoid,项目名称:profireader,代码行数:26,代码来源:articles.py
示例5: get_allowed_statuses
def get_allowed_statuses(company_id=None, portal_id=None):
if company_id:
sub_query = db(MemberCompanyPortal, company_id=company_id).filter(
MemberCompanyPortal.status != "DELETED").all()
else:
sub_query = db(MemberCompanyPortal, portal_id=portal_id)
return sorted(list({partner.status for partner in sub_query}))
开发者ID:CNazar,项目名称:profireader,代码行数:7,代码来源:company.py
示例6: validate
def validate(self):
ret = {'errors': {}, 'warnings': {}, 'notices': {}}
if db(Portal, company_owner_id=self.company_owner_id).count():
ret['errors']['ok'] = 'portal for company already exists'
if not re.match('[^\s]{3,}', self.name):
ret['errors']['name'] = 'pls enter a bit longer name'
if not re.match(
'^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9]{1,})$',
self.host):
ret['errors']['host'] = 'pls enter valid host name'
grouped = {}
for div in self.divisions:
if div.portal_division_type_id in grouped:
grouped[div.portal_division_type_id] += 1
else:
grouped[div.portal_division_type_id] = 1
for check_division in db(PortalDivisionType).all():
if check_division.id not in grouped:
grouped[check_division.id] = 0
if check_division.min > grouped[check_division.id]:
ret['errors'][
'division_%s' % (check_division.id,)] = 'you need at least %s `%s`' % (
check_division.min, check_division.id)
if grouped[check_division.id] == 0:
ret['errors']['add_division'] = 'add at least one `%s`' % (check_division.id,)
if check_division.max < grouped[check_division.id]:
ret['errors'][
'division_%s' % (check_division.id,)] = 'you you can have only %s `%s`' % (
check_division.max, check_division.id)
return ret
开发者ID:tarasmatsyuk,项目名称:profireader,代码行数:34,代码来源:portal.py
示例7: subquery_user_articles
def subquery_user_articles(search_text=None, user_id=None, **kwargs):
article_filter = db(ArticleCompany, article_id=Article.id, **kwargs)
if search_text:
article_filter = article_filter.filter(ArticleCompany.title.ilike(
"%" + repr(search_text).strip("'") + "%"))
return db(Article, author_user_id=user_id).filter(article_filter.exists())
开发者ID:JohnDziurakh,项目名称:profireader,代码行数:7,代码来源:articles.py
示例8: create_company
def create_company(self, data, file):
comp_dict = {"author_user_id": g.user_dict["id"]}
status = STATUS()
for x, y in zip(data.keys(), data.values()):
comp_dict[x] = y
company = Company(**comp_dict)
db_session.add(company)
db_session.commit()
user_rbac = UserCompany(user_id=company.author_user_id, company_id=company.id, status=status.ACTIVE())
db(Company, id=company.id).update(
{
"logo_file": File.upload(
file=file,
company_id=company.id,
parent_id=company.corporate_folder_file_id,
author=g.user_dict["name"],
author_user_id=g.user_dict["id"],
)
}
)
db_session.add(user_rbac)
db_session.commit()
r = Right()
r.add_rights(company.author_user_id, company.id, COMPANY_OWNER)
开发者ID:promko,项目名称:profireader,代码行数:26,代码来源:company.py
示例9: companies_load
def companies_load(json):
companies, pages, page, count = pagination(query=db(Company)
.filter(
Company.id == db(UserCompany, user_id=g.user.id).subquery().c.company_id), page=1,
items_per_page=6 * json.get('next_page') if json.get('next_page') else 6)
return {'companies': [usr_cmp.get_client_side_dict() for usr_cmp in companies],
'user_id': g.user.id, 'end': True if pages == 1 or pages == 0 else False}
开发者ID:alinelle,项目名称:profireader,代码行数:7,代码来源:views_company.py
示例10: publications_load
def publications_load(json, company_id):
portal = db(Company, id=company_id).one().own_portal
if not portal:
return dict(portal_not_exist=True)
current_page = json.get('page') or 1
params = {'search_text': json.get('search_text'), 'portal_id': portal.id}
if json.get('status'):
params['status'] = json.get('status')
subquery = ArticlePortalDivision.subquery_portal_articles(**params)
if json.get('company_id'):
subquery = subquery.filter(db(ArticleCompany,
company_id=json.get('company_id'),
id=ArticlePortalDivision.article_company_id).exists())
articles, pages, current_page = pagination(subquery,
page=current_page)
companies = ArticlePortalDivision.get_companies_which_send_article_to_portal(portal.id)
statuses = {status: status for status in ARTICLE_STATUS_IN_PORTAL.all}
publications = []
for a in articles:
a = a.get_client_side_dict()
del a['long']
publications.append(a)
return {'publications': publications,
'companies': companies,
'pages': {'total': pages,
'current_page': current_page,
'page_buttons': Config.PAGINATION_BUTTONS},
'statuses': statuses}
开发者ID:thewebarea,项目名称:profireader,代码行数:30,代码来源:views_portal.py
示例11: subquery_search
def subquery_search(filters=None, sorts=None, edit=None):
sub_query = db(TranslateTemplate)
list_filters = []; list_sorts = []
if edit:
exist = db(TranslateTemplate, template=edit['template'], name=edit['name']).first()
i = datetime.datetime.now()
TranslateTemplate.get(exist.id).attr({edit['col']: edit['newValue'], 'md_tm':i}).save().get_client_side_dict()
if 'url' in filters:
list_filters.append({'type': 'select', 'value': filters['url'], 'field': TranslateTemplate.url})
if 'template' in filters:
list_filters.append({'type': 'select', 'value': filters['template'], 'field': TranslateTemplate.template})
if 'name' in filters:
list_filters.append({'type': 'text', 'value': filters['name'], 'field': TranslateTemplate.name})
if 'uk' in filters:
list_filters.append({'type': 'text', 'value': filters['uk'], 'field': TranslateTemplate.uk})
if 'en' in filters:
list_filters.append({'type': 'text', 'value': filters['en'], 'field': TranslateTemplate.en})
if 'portal.name' in filters:
sub_query = sub_query.join(Portal,
Portal.id == TranslateTemplate.portal_id)
list_filters.append({'type': 'text', 'value': filters['portal.name'], 'field': Portal.name})
if 'cr_tm' in sorts:
list_sorts.append({'type': 'date', 'value': sorts['cr_tm'], 'field': TranslateTemplate.cr_tm})
elif 'ac_tm' in sorts:
list_sorts.append({'type': 'date', 'value': sorts['ac_tm'], 'field': TranslateTemplate.ac_tm})
else:
list_sorts.append({'type': 'date', 'value': 'desc', 'field': TranslateTemplate.cr_tm})
sub_query = Grid.subquery_grid(sub_query, list_filters, list_sorts)
return sub_query
开发者ID:Ivasyuk,项目名称:profireader,代码行数:29,代码来源:translate.py
示例12: __init__
def __init__(self, name=None,
# portal_plan_id=None,
logo_file_id=None,
company_owner=None,
host=None, divisions=[], portal_layout_id=None):
self.name = name
self.logo_file_id = logo_file_id
# self.company_owner_id = company_owner_id
# self.articles = articles
self.host = host
self.divisions = divisions
# self.portal_plan_id = portal_plan_id if portal_plan_id else db(MemberCompanyPortalPlan).first().id
self.portal_layout_id = portal_layout_id if portal_layout_id else db(PortalLayout).first().id
self.own_company = company_owner
self.company_members = [
MemberCompanyPortal(portal=self, company=company_owner, plan=db(MemberCompanyPortalPlan).first())]
# self.own_company.company_portals = db(MemberCompanyPortalPlan).first()
# db(MemberCompanyPortalPlan).first().portal_companies.add(MemberCompanyPortal(company=self.own_company))
# self.company_assoc = [MemberCompanyPortal(portal = self,
# company = self.own_company,
# company_portal_plan_id=db(MemberCompanyPortalPlan).first().id)]
pass
开发者ID:JohnDziurakh,项目名称:profireader,代码行数:32,代码来源:portal.py
示例13: list_reader_load
def list_reader_load(json):
favorite = request.args.get("favorite") == "True"
localtime = time.gmtime(time.time())
if favorite:
publication_filter = (
Publication.id == db(ReaderPublication, user_id=g.user.id, favorite=True).subquery().c.publication_id
)
else:
division_filter = and_(
PortalDivision.portal_id == db(UserPortalReader, user_id=g.user.id).subquery().c.portal_id
)
publication_filter = and_(
Publication.portal_division_id == db(PortalDivision).filter(division_filter).subquery().c.id,
Publication.status == Publication.STATUSES["PUBLISHED"],
Publication.publishing_tm < datetime.datetime(*localtime[:6]),
)
publications, next_page = Publication.get_page(
filter=publication_filter, order_by=desc(Publication.publishing_tm), page=json.get("next_page"), per_page=10
)
return {
"next_page": next_page,
"end": next_page < 0,
"articles": [p.create_article() for p in publications],
"favorite": favorite,
}
开发者ID:Greckas,项目名称:profireader,代码行数:27,代码来源:views_index.py
示例14: crop_image
def crop_image(image_id, coordinates):
image_query = db(File, id=image_id).one()
if db(ImageCroped, original_image_id=image_id).count():
return update_croped_image(image_id, coordinates)
company_owner = db(Company).filter(or_(
Company.system_folder_file_id == image_query.root_folder_id,
Company.journalist_folder_file_id == image_query.root_folder_id)).one()
bytes_file = crop_with_coordinates(image_query, coordinates)
if bytes_file:
croped = File()
croped.md_tm = strftime("%Y-%m-%d %H:%M:%S", gmtime())
croped.size = sys.getsizeof(bytes_file.getvalue())
croped.name = image_query.name + '_cropped'
croped.parent_id = company_owner.system_folder_file_id
croped.root_folder_id = company_owner.system_folder_file_id
croped.mime = image_query.mime
fc = FileContent(content=bytes_file.getvalue(), file=croped)
copy_original_image_to_system_folder = \
File(parent_id=company_owner.system_folder_file_id, name=image_query.name+'_original',
mime=image_query.mime, size=image_query.size, user_id=g.user.id,
root_folder_id=company_owner.system_folder_file_id, author_user_id=g.user.id)
cfc = FileContent(content=image_query.file_content.content,
file=copy_original_image_to_system_folder)
g.db.add_all([croped, fc, copy_original_image_to_system_folder, cfc])
g.db.flush()
ImageCroped(original_image_id=copy_original_image_to_system_folder.id,
croped_image_id=croped.id,
x=float(coordinates['x']), y=float(coordinates['y']),
width=float(coordinates['width']),
height=float(coordinates['height']), rotate=int(coordinates['rotate'])).save()
return croped.id
else:
return image_query.id
开发者ID:bubanoid,项目名称:profireader,代码行数:34,代码来源:views_file.py
示例15: update_article_portal
def update_article_portal(json, article_id):
db(ArticlePortalDivision, id=article_id).update({'status': json.get('new_status')})
article = db(ArticlePortalDivision, id=article_id).one().get_client_side_dict()
allowed_statuses = ArticlePortalDivision.STATUSES.keys()
json['allowed_statuses'] = allowed_statuses
json['article']['status'] = json.get('new_status')
return json
开发者ID:alinelle,项目名称:profireader,代码行数:7,代码来源:views_portal.py
示例16: update_article_portal
def update_article_portal(json, article_id):
db(ArticlePortalDivision, id=article_id).update({'status': json.get('new_status')})
json['article']['status'] = json.get('new_status')
json['new_status'] = ARTICLE_STATUS_IN_PORTAL.published \
if json.get('new_status') != ARTICLE_STATUS_IN_PORTAL.published \
else ARTICLE_STATUS_IN_PORTAL.declined
return json
开发者ID:JohnDziurakh,项目名称:profireader,代码行数:7,代码来源:views_portal.py
示例17: search_for_portal_to_join
def search_for_portal_to_join(company_id, searchtext):
"""This method return all portals which are not partners current company"""
return [port.get_client_side_dict() for port in
db(Portal).filter(~db(MemberCompanyPortal,
company_id=company_id,
portal_id=Portal.id).exists()
).filter(Portal.name.ilike("%" + searchtext + "%")).all()]
开发者ID:JohnDziurakh,项目名称:profireader,代码行数:7,代码来源:portal.py
示例18: apply_company_to_portal
def apply_company_to_portal(company_id, portal_id):
"""Add company to MemberCompanyPortal table. Company will be partner of this portal"""
g.db.add(MemberCompanyPortal(company=db(Company, id=company_id).one(),
portal=db(Portal, id=portal_id).one(),
company_portal_plan_id=db(Portal, id=portal_id).one().
portal_plan_id))
g.db.flush()
开发者ID:JohnDziurakh,项目名称:profireader,代码行数:7,代码来源:portal.py
示例19: save_all
def save_all(id_f, attr, new_id):
del attr['name']
lists = File.get_all_dir(id_f, new_id)
files = [file for file in db(File, parent_id=id_f) if file.mime != 'directory']
f = File.save_files(files, new_id, attr)
new_list = []
old_list = []
for dir in lists:
if dir.parent_id == id_f:
old_list.append(dir.id)
attr['parent_id'] = new_id
files = [file for file in db(File, parent_id=dir.id) if file.mime != 'directory']
dir.detach().attr(attr)
dir.save()
new_list.append(dir)
File.save_files(files, dir.id, attr)
else:
old_list.append(dir.id)
files = [file for file in db(File, parent_id=dir.id) if file.mime != 'directory']
parent = File.get(dir.parent_id)
index = File.get_index(parent, old_list)
attr['parent_id'] = new_list[index].id
dir.detach().attr(attr)
dir.save()
new_list.append(dir)
File.save_files(files, dir.id, attr)
return old_list, new_list
开发者ID:thewebarea,项目名称:profireader,代码行数:27,代码来源:files.py
示例20: __search_start
def __search_start(self, *args: dict, **kwargs):
""" Don't use this method, use Search().search() method """
subquery_search = self.__get_subquery(*args, ord_by=kwargs.get('order_by'))
if self.__pagination:
from ..controllers.pagination import pagination as pagination_func
subquery_search, self.__pages, page, _ = pagination_func(subquery_search, page=self.__page,
items_per_page=self.__items_per_page)
subquery_search = subquery_search.subquery()
join_search = []
for arg in args:
join_params = arg.get('join') or arg['class']
join_search.append(db(subquery_search).join(join_params,
arg['class'].id == subquery_search.c.index).subquery())
objects = collections.OrderedDict()
to_order = {}
_order_by = kwargs.get('order_by') or Search.ORDER_MD_TM
ord_by = 'text' if type(_order_by) in (str, list, tuple) \
else self.__order_by_to_str[_order_by]
for search in join_search:
for cls in db(search).all():
objects[cls.index] = {'id': cls.index, 'table_name': cls.table_name,
'order': getattr(cls, ord_by), 'md_tm': cls.md_tm}
to_order[cls.index] = (getattr(cls, ord_by), getattr(cls, 'md_tm'))
objects = {obj['id']: obj for obj in
collections.OrderedDict(sorted(objects.items())).values()}
ordered = sorted(tuple(to_order.items()), reverse=False if self.__desc_asc == 'asc' else True,
key=operator.itemgetter(1))
self.__reload_func(len(ordered), *args)
if self.__return_objects:
objects = self.__get_objects_from_db(*args, ordered_objects_list=ordered)
else:
objects = collections.OrderedDict((id, objects[id]) for id, ord in ordered)
return objects, self.__pages, self.__page
开发者ID:alinelle,项目名称:profireader,代码行数:33,代码来源:pr_base.py
注:本文中的utils.db_utils.db函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论