How to use the ming.schema.OneOf 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 / Allura / allura / model / discuss.py View on Github external
class Post(Message, VersionedArtifact, ActivityObject, ReactableArtifact):

    class __mongometa__:
        name = 'post'
        history_class = PostHistory
        indexes = [
            # used in general lookups, last_post, etc
            ('discussion_id', 'status', 'timestamp'),
            'thread_id'
        ]
    type_s = 'Post'

    thread_id = ForeignIdProperty(Thread)
    discussion_id = ForeignIdProperty(Discussion)
    subject = FieldProperty(schema.Deprecated)
    status = FieldProperty(schema.OneOf('ok', 'pending', 'spam',
                                        if_missing='pending'))
    last_edit_date = FieldProperty(datetime, if_missing=None)
    last_edit_by_id = AlluraUserProperty()
    edit_count = FieldProperty(int, if_missing=0)
    spam_check_id = FieldProperty(str, if_missing='')
    text_cache = FieldProperty(MarkdownCache)
    # meta comment - system generated, describes changes to an artifact
    is_meta = FieldProperty(bool, if_missing=False)

    thread = RelationProperty(Thread)
    discussion = RelationProperty(Discussion)

    def __json__(self):
        author = self.author()
        return dict(
            _id=str(self._id),
github apache / allura / Allura / allura / model / repository.py View on Github external
log = logging.getLogger(__name__)
config = utils.ConfigProxy(
    common_suffix='forgemail.domain',
)

README_RE = re.compile('^README(\.[^.]*)?$', re.IGNORECASE)
VIEWABLE_EXTENSIONS = frozenset([
    '.php', '.py', '.js', '.java', '.html', '.htm', '.yaml', '.sh',
    '.rb', '.phtml', '.txt', '.bat', '.ps1', '.xhtml', '.css', '.cfm', '.jsp', '.jspx',
    '.pl', '.php4', '.php3', '.rhtml', '.svg', '.markdown', '.json', '.ini', '.tcl', '.vbs', '.xsl'])


# Some schema types
SUser = dict(name=str, email=str, date=datetime)
SObjType = S.OneOf('blob', 'tree', 'submodule')

# Used for when we're going to batch queries using $in
QSIZE = 100
BINARY_EXTENSIONS = frozenset([
    ".3ds", ".3g2", ".3gp", ".7z", ".a", ".aac", ".adp", ".ai", ".aif", ".apk", ".ar", ".asf", ".au", ".avi", ".bak",
    ".bin", ".bk", ".bmp", ".btif", ".bz2", ".cab", ".caf", ".cgm", ".cmx", ".cpio", ".cr2", ".dat", ".deb", ".djvu",
    ".dll", ".dmg", ".dng", ".doc", ".docx", ".dra", ".DS_Store", ".dsk", ".dts", ".dtshd", ".dvb", ".dwg", ".dxf",
    ".ecelp4800", ".ecelp7470", ".ecelp9600", ".egg", ".eol", ".eot", ".epub", ".exe", ".f4v", ".fbs", ".fh", ".fla",
    ".flac", ".fli", ".flv", ".fpx", ".fst", ".fvt", ".g3", ".gif", ".gz", ".h261", ".h263", ".h264", ".ico", ".ief",
    ".img", ".ipa", ".iso", ".jar", ".jpeg", ".jpg", ".jpgv", ".jpm", ".jxr", ".ktx", ".lvp", ".lz", ".lzma", ".lzo",
    ".m3u", ".m4a", ".m4v", ".mar", ".mdi", ".mid", ".mj2", ".mka", ".mkv", ".mmr", ".mng", ".mov", ".movie", ".mp3",
    ".mp4", ".mp4a", ".mpeg", ".mpg", ".mpga", ".mxu", ".nef", ".npx", ".o", ".oga", ".ogg", ".ogv", ".otf", ".pbm",
    ".pcx", ".pdf", ".pea", ".pgm", ".pic", ".png", ".pnm", ".ppm", ".psd", ".pya", ".pyc", ".pyo", ".pyv", ".qt",
    ".rar", ".ras", ".raw", ".rgb", ".rip", ".rlc", ".rz", ".s3m", ".s7z", ".scpt", ".sgi", ".shar", ".sil", ".smv",
    ".so", ".sub", ".swf", ".tar", ".tbz2", ".tga", ".tgz", ".tif", ".tiff", ".tlz", ".ttf", ".uvh", ".uvi",
    ".uvm", ".uvp", ".uvs", ".uvu", ".viv", ".vob", ".war", ".wav", ".wax", ".wbmp", ".wdp", ".weba", ".webm", ".webp",
github apache / allura / ForgeOrganization / forgeorganization / organization / model / organization.py View on Github external
def setStatus(self, status):
        if status=='active' and self.status!='active':
            self.startdate = datetime.utcnow()
        elif status=='closed':
            self.closeddate = datetime.utcnow()
        self.status = status

class ProjectInvolvement(MappedClass):
    class __mongometa__:
        session = main_orm_session
        name='project_involvement'

    _id=FieldProperty(S.ObjectId)
    status=FieldProperty(S.OneOf('active', 'closed', 'invitation', 'request'))
    collaborationtype=FieldProperty(S.OneOf('cooperation', 'participation'))
    organization_id=ForeignIdProperty('Organization')
    project_id=ForeignIdProperty('Project')
    startdate = FieldProperty(S.DateTime, if_missing=None)
    closeddate = FieldProperty(S.DateTime, if_missing=None)

    organization = RelationProperty('Organization')
    project = RelationProperty('Project')
    
    @classmethod
    def insert(cls, status, collaborationtype, organization_id, project_id):
        p = cls.query.find(dict(
            organization_id=organization_id, 
            project_id=project_id))
        for el in p:
            if p.status != 'closed':
                return None
github apache / allura / ForgeOrganization / forgeorganization / organization / model / organization.py View on Github external
return cls.query.get(_id=membershipid)

    def setStatus(self, status):
        if status=='active' and self.status!='active':
            self.startdate = datetime.utcnow()
        elif status=='closed':
            self.closeddate = datetime.utcnow()
        self.status = status

class ProjectInvolvement(MappedClass):
    class __mongometa__:
        session = main_orm_session
        name='project_involvement'

    _id=FieldProperty(S.ObjectId)
    status=FieldProperty(S.OneOf('active', 'closed', 'invitation', 'request'))
    collaborationtype=FieldProperty(S.OneOf('cooperation', 'participation'))
    organization_id=ForeignIdProperty('Organization')
    project_id=ForeignIdProperty('Project')
    startdate = FieldProperty(S.DateTime, if_missing=None)
    closeddate = FieldProperty(S.DateTime, if_missing=None)

    organization = RelationProperty('Organization')
    project = RelationProperty('Project')
    
    @classmethod
    def insert(cls, status, collaborationtype, organization_id, project_id):
        p = cls.query.find(dict(
            organization_id=organization_id, 
            project_id=project_id))
        for el in p:
            if p.status != 'closed':
github apache / allura / ForgeOrganization / forgeorganization / organization / model / organization.py View on Github external
class __mongometa__:
        name='organization'
        session = main_orm_session
        unique_indexes = [ 'shortname' ]

    _id=FieldProperty(S.ObjectId)
    shortname=FieldProperty(str)
    fullname=FieldProperty(str)
    organization_type=FieldProperty(S.OneOf(
        'For-profit business',
        'Foundation or other non-profit organization',
        'Research and/or education institution'))
    description=FieldProperty(str)
    headquarters=FieldProperty(str)
    dimension=FieldProperty(
        S.OneOf('Small', 'Medium', 'Large', 'Unknown'),
        if_missing = 'Unknown')
    website=FieldProperty(str)
    workfields=FieldProperty([S.ObjectId])
    created=FieldProperty(S.DateTime, if_missing=datetime.utcnow())
    
    memberships=RelationProperty('Membership')
    project_involvements=RelationProperty('ProjectInvolvement')

    def url(self):
        return ('/o/' + self.shortname.replace('_', '-') + '/').encode('ascii','ignore')

    def project(self):
        return M.Project.query.get(
            shortname='o/'+self.shortname.replace('_', '-'))

    @classmethod
github apache / allura / Allura / allura / model / monq_model.py View on Github external
indexes = [
            [
                # used in MonQTask.get() method
                # also 'state' queries exist in several other methods
                ('state', ming.ASCENDING),
                ('priority', ming.DESCENDING),
                ('time_queue', ming.ASCENDING)
            ],
            [
                # used by repo tarball status check, etc
                'state', 'task_name', 'time_queue'
            ],
        ]

    _id = FieldProperty(S.ObjectId)
    state = FieldProperty(S.OneOf(*states))
    priority = FieldProperty(int)
    result_type = FieldProperty(S.OneOf(*result_types))
    time_queue = FieldProperty(datetime, if_missing=datetime.utcnow)
    time_start = FieldProperty(datetime, if_missing=None)
    time_stop = FieldProperty(datetime, if_missing=None)

    task_name = FieldProperty(str)
    process = FieldProperty(str)
    context = FieldProperty(dict(
        project_id=S.ObjectId,
        app_config_id=S.ObjectId,
        user_id=S.ObjectId,
        notifications_disabled=bool))
    args = FieldProperty([])
    kwargs = FieldProperty({None: None})
    result = FieldProperty(None, if_missing=None)
github apache / allura / Allura / allura / model / auth.py View on Github external
# Don't use these directly, use get/set_pref() instead
    preferences = FieldProperty(dict(
        results_per_page=int,
        email_address=str,
        email_format=str,
        disable_user_messages=bool,
        mention_notifications=bool,
        multifactor=bool,
    ))
    # Additional top-level fields can/should be accessed with get/set_pref also
    # Not sure why we didn't put them within the 'preferences' dictionary :(
    display_name = FieldPropertyDisplayName(str)
    # Personal data
    sex = FieldProperty(
        S.OneOf('Male', 'Female', 'Other', 'Unknown',
                if_missing='Unknown'))
    birthdate = FieldProperty(S.DateTime, if_missing=None)

    # Availability information
    availability = FieldProperty([dict(
        week_day=str,
        start_time=dict(h=int, m=int),
        end_time=dict(h=int, m=int))])
    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
github apache / allura / ForgeTracker / forgetracker / tracker_main.py View on Github external
permissions_desc = {
        'configure': 'Edit milestones.',
        'read': 'View tickets.',
        'update': 'Edit tickets.',
        'create': 'Create tickets.',
        'save_searches': 'Not used.',
        'admin': 'Set permissions. Configure options, saved searches, custom fields, '
        'and default list view columns. Move tickets to or from this '
        'tracker. Import tickets.',
        'delete': 'Delete and undelete tickets. View deleted tickets.',
    }
    config_options = Application.config_options + [
        ConfigOption('EnableVoting', bool, True),
        ConfigOption('TicketMonitoringEmail', str, ''),
        ConfigOption('TicketMonitoringType',
                     schema.OneOf('NewTicketsOnly', 'AllTicketChanges',
                                  'NewPublicTicketsOnly', 'AllPublicTicketChanges'), None),
        ConfigOption('AllowEmailPosting', bool, True)
    ]
    exportable = True
    searchable = True
    tool_label = 'Tickets'
    tool_description = """
        Organize your project's bugs, enhancements, tasks, etc. with a ticket system.
        You can track and search by status, assignee, milestone, labels, and custom fields.
    """
    default_mount_label = 'Tickets'
    default_mount_point = 'tickets'
    ordinal = 6
    icons = {
        24: 'images/tickets_24.png',
        32: 'images/tickets_32.png',