本文整理汇总了Python中src.common.database.Database.find方法的典型用法代码示例。如果您正苦于以下问题:Python Database.find方法的具体用法?Python Database.find怎么用?Python Database.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.common.database.Database
的用法示例。
在下文中一共展示了Database.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_portfolio
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def calculate_portfolio(self, portfolio_id):
finance_data = Database.find_one('financedata', {"portfolio_id": self.portfolio_id})
if finance_data is not None:
Database.remove('financedata', {"portfolio_id": self.portfolio_id})
stock_data = Database.find('stockdata', {"portfolio_id": portfolio_id})
current_value_list = []
add_price_list = []
qty_list = []
for data in stock_data:
current_price = (data['current_price'])
add_price = (data['add_price'])
qty = (data['qty'])
current_value_list.append(current_price)
add_price_list.append(add_price)
qty_list.append(qty)
total_qty = sum(qty_list)
total_current_value = sum(current_value_list)
total_add_price = sum(add_price_list)
print(total_current_value)
try:
total_purchase_value = total_add_price * total_qty
total_current_value = total_current_value * total_qty
percent_change = (total_current_value - total_purchase_value) / total_current_value
finance = Finance(portfolio_id=portfolio_id, percent_change=percent_change,
total_purchase_value=total_purchase_value, total_current_value=total_current_value)
finance.save_to_database()
except ZeroDivisionError:
print("You need to add data first!")
示例2: admin_edit_profile_page
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def admin_edit_profile_page(user):
universities = University.get_uni_list()
profile = User.find_by_email(user)
mypermissions = User.get_user_permissions(session['email'])
permissions = [permission_level for permission_level in Database.find(Permissions.COLLECTION, {})]
return render_template('edit-profile.html', user=user, universities=universities, profile=profile,
permissions=permissions, mypermissions=mypermissions)
示例3: index
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def index():
news = [article for article in Database.find("articles",
{"page_id": uuid.UUID('{00000000-0000-0000-0000-000000000000}')},
sort='date',
direction=pymongo.DESCENDING,
limit=3)]
events = [event for event in Database.find("events", {}, sort='start', direction=pymongo.DESCENDING, limit=3)]
for article in news:
article['summary'] = Utils.clean_for_homepage(article['summary'])
for event in events:
event['description'] = Utils.clean_for_homepage(event['description'])
return render_template('home.html',
events=events,
news=news)
示例4: find_needing_update
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def find_needing_update(cls, minutes_since_update=AlertConstants.ALERT_TIMEOUT):
last_updated_limit = datetime.datetime.utcnow() - datetime.timedelta(minutes=minutes_since_update)
return [cls(**elem) for elem in Database.find(AlertConstants.COLLECTION,
{"last_checked":
{"$lte": last_updated_limit},
"active": True
})]
示例5: remove_from_db
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def remove_from_db(self):
if self._feed:
news = [article for article in Database.find("articles", {"page_id" : uuid.UUID('{00000000-0000-0000-0000-000000000000}')})]
for article in news:
article = Article.get_by_id(article['_id'])
article.remove_from_db()
Database.remove(self.COLLECTION, {'_id': self._id})
示例6: calculate_total
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def calculate_total(portfolio_id):
data = Database.find('stockdata', {"portfolio_id": portfolio_id})
li = []
for total in data:
value = (data['total_price'])
li.append(value)
total_value = sum(li)
return total_value
示例7: get_registered_events
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def get_registered_events(user):
events_registered_for = Database.find("registrations", {"user": user})
if events_registered_for is not None:
events = list()
for event in events_registered_for:
events.append(Database.find_one("events", {"_id": event["event"]}))
return events
return None
示例8: events_list_page
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def events_list_page():
events = [event for event in Database.find("events", {}, sort='start', direction=pymongo.DESCENDING)]
for event in events:
event['description'] = Utils.clean_for_homepage(event['description'])
return render_template('items/events-list.html',
events=events)
示例9: get_all_attended
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def get_all_attended(user):
events_attended = Database.find("registrations", {"user": user, "attended": "Yes"})
if events_attended is not None:
events = list()
for event in events_attended:
events.append(Database.find_one("events", {"_id": event["event"]}))
return events
return None
示例10: check_user_awards
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def check_user_awards(cls, user_points):
awards_db = [award for award in Database.find(collection=Award.COLLECTION,
query={})]
awards = []
for award_db in awards_db:
del award_db['_id']
awards.append(cls(**award_db))
return Award.check_awards(awards, user_points)
示例11: point_types_get_admin
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def point_types_get_admin():
point_types = [type for type in Database.find(PointType.COLLECTION, {})]
point_types_objects = []
for type in point_types:
del type['_id']
type_obj = PointType(**type)
type_obj.total = type_obj.users_with_point()
point_types_objects.append(type_obj)
return render_template('admin-point-types.html', point_types=point_types_objects)
示例12: get_point_rank
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def get_point_rank(self):
users = [user for user in Database.find(self.COLLECTION, {})]
top_points_user = 0
for user in users:
total_points = 0
for key in user["points"].keys():
total_points += user["points"][key]
if total_points > top_points_user:
top_points_user = total_points
current_user_points = self.total_points()
return 100 - (current_user_points / top_points_user * 100)
示例13: news_page
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def news_page(page_id=None):
if page_id is None:
page_id = uuid.UUID('{00000000-0000-0000-0000-000000000000}')
news = [article for article in Database.find("articles",
{"page_id": page_id},
sort='date',
direction=pymongo.DESCENDING)]
for article in news:
article['summary'] = Utils.clean_for_homepage(article['summary'])
return render_template('news.html',
news=news)
示例14: access_to
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def access_to(cls, type):
"""
Returns what access levels are allowed to visit a specific type of page or artifact
When accessing the admin page, call user.permissions.allowed(Permissions.access_to('admin'))
:param type:
:return:
"""
if type not in Permissions.TYPES:
raise PermissionsCreationError(
"The type parameter had an access type that is not allowed (only use {})".format(Permissions.TYPES))
access_levels = Database.find(cls.COLLECTION, {"access": {'$in': [type]}})
return [level['name'] for level in access_levels]
示例15: get_page
# 需要导入模块: from src.common.database import Database [as 别名]
# 或者: from src.common.database.Database import find [as 别名]
def get_page(title):
try:
page = Page.get_by_title(title)
news = []
if page.get_feed():
news = [article for article in Database.find("articles",
{"page_id": page.get_id()},
sort='date',
direction=pymongo.DESCENDING,
limit=3)]
for article in news:
article['summary'] = Utils.clean_for_homepage(article['summary'])
return render_template('page.html', page=page.to_json(), news=news)
except NoSuchPageExistException as e:
abort(401)