当前位置: 首页>>代码示例>>Python>>正文


Python Database.find方法代码示例

本文整理汇总了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!")
开发者ID:casinelli26,项目名称:Portfolio-App-V4,代码行数:31,代码来源:finance.py

示例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)
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:9,代码来源:app.py

示例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)
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:18,代码来源:app.py

示例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
                                                    })]
开发者ID:ashwillwink,项目名称:price-of-chair,代码行数:9,代码来源:alert.py

示例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})
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:9,代码来源:page.py

示例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
开发者ID:casinelli26,项目名称:Portfolio-App-V4,代码行数:10,代码来源:portfolio.py

示例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
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:10,代码来源:user.py

示例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)
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:10,代码来源:app.py

示例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
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:10,代码来源:user.py

示例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)
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:11,代码来源:award.py

示例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)
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:12,代码来源:app.py

示例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)
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:15,代码来源:user.py

示例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)
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:15,代码来源:app.py

示例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]
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:16,代码来源:permissions.py

示例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)
开发者ID:jslvtr,项目名称:AC41004-Team-2,代码行数:17,代码来源:app.py


注:本文中的src.common.database.Database.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。