How to use pony - 10 common examples

To help you get started, we’ve selected a few pony examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yetone / collipa / collipa / controllers / topic.py View on Github external
    @orm.db_session
    def get(self, topic_id):
        topic_id = int(topic_id)
        page = force_int(self.get_argument('page', 0), 0)
        topic = Topic.get(id=topic_id)
        if not topic:
            raise tornado.web.HTTPError(404)
        category = self.get_argument('category', None)
        if not category:
            category = 'all'
        if category == 'all':
            reply_count = topic.reply_count
            url = topic.url
        elif category == 'hot':
            reply_count = orm.count(topic.get_replies(page=None,
                                                      category=category))
            url = topic.url + '?category=hot'
        page_count = (reply_count + config.reply_paged - 1) // config.reply_paged
        if page == 0:
            page = page_count
        replies = topic.get_replies(page=page, category=category)
        form = ReplyForm()
        return self.render("topic/index.html", topic=topic, replies=replies,
                           form=form, category=category, page=page,
                           page_count=page_count, url=url)
github yetone / collipa / collipa / controllers / user.py View on Github external
url += '/topics'
        elif view == 'replies':
            items = user.get_replies(page=page, category=category)
            item_count = orm.count(user.get_replies(page=None, category=category))
            url += '/replies'
        elif view == 'followings':
            items = user.get_followings(page=page)
            item_count = orm.count(user.get_followings(page=None))
            url += '/followings'
        elif view == 'followers':
            items = user.get_followers(page=page)
            item_count = orm.count(user.get_followers(page=None))
            url += '/followers'
        elif view == 'albums':
            items = user.get_albums(page=page)
            item_count = orm.count(user.get_albums(page=None))
            url += '/albums'
        page_count = (item_count + config.paged - 1) // config.paged
        return self.render("user/index.html", user=user, items=items,
                           view=view, category=category, page=page,
                           page_count=page_count, url=url)
github yetone / collipa / collipa / controllers / node.py View on Github external
    @orm.db_session
    def get(self):
        page = force_int(self.get_argument('page', 1), 1)
        page_count = 0
        nodes = []
        category = self.get_argument('category', None)
        hot_nodes = Node.get_nodes(category='hot', limit=8)
        new_nodes = Node.get_nodes(category='new', limit=8)
        url = '/nodes'
        if category == 'all':
            nodes = Node.get_nodes(category='all', page=page)
            node_count = orm.count(Node.get_nodes(page=None))
            page_count = (node_count + config.node_paged - 1) // config.node_paged
            url = '/nodes?category=' + category
        return self.render("node/show.html", hot_nodes=hot_nodes,
                           new_nodes=new_nodes, nodes=nodes, category=category, page=page,
                           page_count=page_count, url=url)
github yetone / collipa / collipa / controllers / user.py View on Github external
    @orm.db_session
    def get(self):
        page = force_int(self.get_argument('page', 1), 1)
        category = self.get_argument('category', None)
        limit = 12
        hot_users = User.get_users(category='hot', limit=limit)
        new_users = User.get_users(category='new', limit=limit)
        page_count = 0
        users = []
        url = '/users'
        if category == 'all':
            user_count = orm.count(User.get_users(page=None))
            page_count = (user_count + config.user_paged - 1) // config.user_paged
            users = User.get_users(page=page)
            url = '/users?category=all'
        elif category == 'online':
            online_members = User.get_online_members()
            online_members = [int(i) for i in online_members]
            user_count = len(online_members)
            online_members = online_members[(page - 1) * config.user_paged: page * config.user_paged]
            users = User.select(lambda rv: rv.id in online_members)
            page_count = (user_count + config.user_paged - 1) // config.user_paged
            url = '/users?category=online'
        return self.render("user/show.html", users=users, hot_users=hot_users,
                           new_users=new_users, page=page,
                           page_count=page_count, url=url, category=category)
github nvbn / series_list / tests / test_models.py View on Github external
    @db_session
    def test_create(self):
        """Test create episode"""
        series = Series(name='test')
        episode = Episode(
            series=series,
            season=1,
            number=2,
            name='test',
        )
        commit()
        Episode.get().should.be.equal(episode)
github sloria / PythonORMSleepy / tests / test_pony_app.py View on Github external
    @db_session
    def test_delete_item(self):
        item = Item[self.item.id]
        assert_in(item, Item.select()[:])
        res = self.client.delete("/api/v1/items/{0}".format(self.item.id))
        assert_not_in(self.item, Item.select())
github sloria / PythonORMSleepy / tests / test_pony_app.py View on Github external
def setUp(self):
        db.create_tables()
        # create some items
        with db_session:
            self.person = Person(firstname="Steve", lastname="Loria")
            self.person2 = Person(firstname="Monty", lastname="Python")
            self.item = Item(name="Foo", person=self.person)
            self.item2 = Item(name="Bar")
github Tribler / tribler / Tribler / Test / Core / Modules / MetadataStore / test_tracker_state.py View on Github external
    @db_session
    def test_canonicalize_tracker_state(self):
        ts = self.mds.TrackerState(url='http://tracker.tribler.org:80/announce/')
        self.assertEqual(self.mds.TrackerState.get(url='http://tracker.tribler.org/announce'), ts)
github Tribler / tribler / Tribler / Test / Core / Modules / MetadataStore / test_torrent_metadata.py View on Github external
def test_search_keyword(self):
        """
        Test searching in a database with some torrent metadata inserted
        """
        torrent1 = self.mds.TorrentMetadata.from_dict(dict(rnd_torrent(), title="foo bar 123"))
        torrent2 = self.mds.TorrentMetadata.from_dict(dict(rnd_torrent(), title="eee 123"))
        self.mds.TorrentMetadata.from_dict(dict(rnd_torrent(), title="xoxoxo bar"))
        self.mds.TorrentMetadata.from_dict(dict(rnd_torrent(), title="xoxoxo bar"))
        self.mds.TorrentMetadata.from_dict(dict(rnd_torrent(), title=u"\""))
        self.mds.TorrentMetadata.from_dict(dict(rnd_torrent(), title=u"\'"))
        orm.flush()

        # Search for torrents with the keyword 'foo', it should return one result
        results = self.mds.TorrentMetadata.search_keyword("foo")[:]
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].rowid, torrent1.rowid)

        # Search for torrents with the keyword 'eee', it should return one result
        results = self.mds.TorrentMetadata.search_keyword("eee")[:]
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].rowid, torrent2.rowid)

        # Search for torrents with the keyword '123', it should return two results
        results = self.mds.TorrentMetadata.search_keyword("123")[:]
        self.assertEqual(len(results), 2)
github tortoise / orm-benchmarks / src / pony / test_d.py View on Github external
import time

from models import Journal
from pony.orm import db_session, select

LEVEL_CHOICE = [10, 20, 30, 40, 50]
start = time.time()


count = 0

with db_session():
    for _ in range(10):
        for level in LEVEL_CHOICE:
            res = list(select(j for j in Journal if j.level == level))
            count += len(res)

now = time.time()

print(f'Pony ORM, D: Rows/sec: {count / (now - start): 10.2f}')