How to use the ming.schema.ObjectId function in Ming

To help you get started, we’ve selected a few Ming 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 apache / allura / ForgeSCM / forgescm / model / artifacts.py View on Github external
class Repository(Artifact):
    class __mongometa__:
        name='repository'
    type_s = 'ForgeSCM Repository'

    _id = FieldProperty(schema.ObjectId)
    description = FieldProperty(str)
    status = FieldProperty(str)
    parent = FieldProperty(str)
    type = FieldProperty(str, if_missing='hg')
    pull_requests = FieldProperty([str])
    repo_dir = FieldProperty(str)
    cloned_from = FieldProperty(str)
    forks = FieldProperty([dict(
                project_id=schema.ObjectId,
                app_config_id=schema.ObjectId(if_missing=None))])
    forked_from = FieldProperty(dict(
            project_id=schema.ObjectId,
            app_config_id=schema.ObjectId(if_missing=None)))

    commits = RelationProperty('Commit', via='repository_id',
                               fetch=False)

    def ordered_commits(self, limit=None):
        q = self.commits
        q = q.sort([('rev', pymongo.DESCENDING),
                    ('date', pymongo.DESCENDING)])
        if limit:
            q = q.limit(limit)
        return q

    def scmlib(self):
github apache / allura / ForgeUserStats / forgeuserstats / model / stats.py View on Github external
from allura.lib import plugin
from allura.model.session import main_orm_session
from allura.model import Stats


class UserStats(Stats):

    class __mongometa__:
        name = 'userstats'
        session = main_orm_session
        unique_indexes = ['_id', 'user_id']

    tot_logins_count = FieldProperty(int, if_missing=0)
    last_login = FieldProperty(datetime)
    lastmonthlogins = FieldProperty([datetime])
    user_id = FieldProperty(S.ObjectId)

    @classmethod
    def create(cls, user):
        auth_provider = plugin.AuthenticationProvider.get(request)
        reg_date = auth_provider.user_registration_date(user)
        stats = cls.query.get(user_id=user._id)
        if stats:
            return stats
        stats = cls(user_id=user._id, registration_date=reg_date)
        user.stats_id = stats._id
        return stats

    def getLastMonthLogins(self):
        self.checkOldArtifacts()
        return len(self.lastmonthlogins)
github apache / allura / HelloForge / helloforge / model / wiki.py View on Github external
except OperationFailure:
                sleep(0.1)
                continue

    def root_comments(self):
        if '_id' in self:
            return Comment.query.find(dict(page_id=self._id, parent_id=None))
        else:
            return []

class Comment(Message):
    """Comment class, threaded, persisted in mongo on a per-page basis"""
    
    class __mongometa__:
        name='hello_comment'
    page_id=FieldProperty(schema.ObjectId)

    def index(self):
        result = Message.index(self)
        author = self.author()
        result.update(
            title_s='Comment on page %s by %s' % (
                self.page.title, author.display_name),
            type_s='Comment on WikiPage',
            page_title_t=self.page.title)
        return result

    @property
    def page(self):
        """The page this comment connects too"""
        return Page.query.get(_id=self.page_id)
github apache / allura / Allura / allura / model / artifact.py View on Github external
indexes = [
            'pubdate',
            ('artifact_ref.project_id', 'artifact_ref.mount_point'),
            (('ref_id', pymongo.ASCENDING),
             ('pubdate', pymongo.DESCENDING)),
            (('project_id', pymongo.ASCENDING),
             ('app_config_id', pymongo.ASCENDING),
             ('pubdate', pymongo.DESCENDING)),
            # used in ext/user_profile/user_main.py for user feeds
            'author_link',
            # used in project feed
            (('project_id', pymongo.ASCENDING),
             ('pubdate', pymongo.DESCENDING)),
        ]

    _id = FieldProperty(S.ObjectId)
    ref_id = ForeignIdProperty('ArtifactReference')
    neighborhood_id = ForeignIdProperty('Neighborhood')
    project_id = ForeignIdProperty('Project')
    app_config_id = ForeignIdProperty('AppConfig')
    tool_name = FieldProperty(str)
    title = FieldProperty(str)
    link = FieldProperty(str)
    pubdate = FieldProperty(datetime, if_missing=datetime.utcnow)
    description = FieldProperty(str)
    description_cache = FieldProperty(MarkdownCache)
    unique_id = FieldProperty(str, if_missing=lambda: h.nonce(40))
    author_name = FieldProperty(str, if_missing=lambda: c.user.get_pref(
        'display_name') if hasattr(c, 'user') else None)
    author_link = FieldProperty(
        str, if_missing=lambda: c.user.url() if hasattr(c, 'user') else None)
    artifact_reference = FieldProperty(S.Deprecated)
github apache / allura / Allura / allura / model / stats.py View on Github external
from ming.orm import FieldProperty
from ming.orm.declarative import MappedClass
from datetime import timedelta
import difflib

from allura.model.session import main_orm_session


class Stats(MappedClass):

    class __mongometa__:
        name = 'basestats'
        session = main_orm_session
        unique_indexes = ['_id']

    _id = FieldProperty(S.ObjectId)

    visible = FieldProperty(bool, if_missing=True)
    registration_date = FieldProperty(datetime)
    general = FieldProperty([dict(
        category=S.ObjectId,
        messages=[dict(
            messagetype=str,
            created=int,
            modified=int)],
        tickets=dict(
            solved=int,
            assigned=int,
            revoked=int,
            totsolvingtime=int),
        commits=[dict(
            lines=int,
github apache / allura / ForgeSCM / forgescm / model / artifacts.py View on Github external
from ming.orm.property import FieldProperty, RelationProperty, ForeignIdProperty

from pyforge.lib.helpers import push_config, set_context, encode_keys
from pyforge.model import Project, Artifact, AppConfig
from pymongo import bson
import sys
import forgescm.lib

log = logging.getLogger(__name__)

class Repository(Artifact):
    class __mongometa__:
        name='repository'
    type_s = 'ForgeSCM Repository'

    _id = FieldProperty(schema.ObjectId)
    description = FieldProperty(str)
    status = FieldProperty(str)
    parent = FieldProperty(str)
    type = FieldProperty(str, if_missing='hg')
    pull_requests = FieldProperty([str])
    repo_dir = FieldProperty(str)
    cloned_from = FieldProperty(str)
    forks = FieldProperty([dict(
                project_id=schema.ObjectId,
                app_config_id=schema.ObjectId(if_missing=None))])
    forked_from = FieldProperty(dict(
            project_id=schema.ObjectId,
            app_config_id=schema.ObjectId(if_missing=None)))

    commits = RelationProperty('Commit', via='repository_id',
                               fetch=False)
github apache / allura / Allura / allura / model / multifactor.py View on Github external
log = logging.getLogger(__name__)


class TotpKey(MappedClass):
    '''
    For use with "mongodb" TOTP service
    '''

    class __mongometa__:
        session = main_orm_session
        name = 'multifactor_totp'
        unique_indexes = ['user_id']

    _id = FieldProperty(S.ObjectId)
    user_id = FieldProperty(S.ObjectId, required=True)
    key = FieldProperty(bytes, required=True)


class RecoveryCode(MappedClass):
    '''
    For use with "mongodb" recovery code service
    '''

    class __mongometa__:
        session = main_orm_session
        name = 'multifactor_recovery_code'
        indexes = ['user_id']

    _id = FieldProperty(S.ObjectId)
    user_id = FieldProperty(S.ObjectId, required=True)
    code = FieldProperty(str, required=True)
github apache / allura / Allura / allura / model / auth.py View on Github external
localization = FieldProperty(dict(city=str, country=str))
    timezone = FieldProperty(str)
    sent_user_message_times = FieldProperty([S.DateTime])
    inactiveperiod = FieldProperty([dict(
        start_date=S.DateTime,
        end_date=S.DateTime)])

    # Additional contacts
    socialnetworks = FieldProperty([dict(socialnetwork=str, accounturl=str)])
    telnumbers = FieldProperty([str])
    skypeaccount = FieldProperty(str)
    webpages = FieldProperty([str])

    # Skills list
    skills = FieldProperty([dict(
        category_id=S.ObjectId,
        level=S.OneOf('low', 'high', 'medium'),
        comment=str)])

    # Statistics
    stats_id = FieldProperty(S.ObjectId, if_missing=None)
    last_access = FieldProperty(dict(
        login_date=S.DateTime,
        login_ip=str,
        login_ua=str,
        session_date=S.DateTime,
        session_ip=str,
        session_ua=str))

    def __repr__(self):
        return (u''.format(s=self))
github apache / allura / ForgeChat / forgechat / model / chat.py View on Github external
from allura import model as M
from allura.model.types import MarkdownCache


class ChatChannel(MappedClass):

    class __mongometa__:
        name = 'globals'
        session = M.main_orm_session
        indexes = ['project_id']
        unique_indexes = ['channel']

    _id = FieldProperty(S.ObjectId)
    project_id = FieldProperty(S.ObjectId)
    app_config_id = FieldProperty(S.ObjectId)
    channel = FieldProperty(str)


class ChatMessage(M.Artifact):

    class __mongometa__:
        name = 'chat_message'
        indexes = ['timestamp']
    type_s = 'Chat Message'

    timestamp = FieldProperty(datetime, if_missing=datetime.utcnow)
    sender = FieldProperty(str, if_missing='')
    channel = FieldProperty(str, if_missing='')
    text = FieldProperty(str, if_missing='')
    text_cache = FieldProperty(MarkdownCache)
github apache / allura / Allura / allura / model / index.py View on Github external
from ming.orm import ForeignIdProperty, RelationProperty

from allura.lib import helpers as h

from .session import main_doc_session, main_orm_session
from .project import Project

log = logging.getLogger(__name__)

# Collection definitions
ArtifactReferenceDoc = collection(
    'artifact_reference', main_doc_session,
    Field('_id', str),
    Field('artifact_reference', dict(
        cls=S.Binary(),
        project_id=S.ObjectId(),
        app_config_id=S.ObjectId(),
        artifact_id=S.Anything(if_missing=None))),
    Field('references', [str], index=True),
    Index('artifact_reference.project_id'),  # used in ReindexCommand
)

ShortlinkDoc = collection(
    'shortlink', main_doc_session,
    Field('_id', S.ObjectId()),
    # index needed for from_artifact() and index_tasks.py:del_artifacts
    Field('ref_id', str, index=True),
    Field('project_id', S.ObjectId()),
    Field('app_config_id', S.ObjectId()),
    Field('link', str),
    Field('url', str),
    # used by from_links()  More helpful to have project_id first, for other