Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
('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)
def clear_user_data(self):
# for [[project_blog_posts]] macro
('app_config_id', 'state', 'timestamp'),
# for [[neighborhood_blog_posts]] macro
('neighborhood_id', 'state', 'timestamp'),
]
type_s = 'Blog Post'
title = FieldProperty(str, if_missing='Untitled')
text = FieldProperty(str, if_missing='')
text_cache = FieldProperty(MarkdownCache)
timestamp = FieldProperty(datetime, if_missing=datetime.utcnow)
slug = FieldProperty(str)
state = FieldProperty(
schema.OneOf('draft', 'published'), if_missing='draft')
neighborhood_id = ForeignIdProperty('Neighborhood', if_missing=None)
link_regex = re.compile(r'^[^#]+$') # no target in the link, meaning no comments
@property
def activity_name(self):
return 'a blog post'
@property
def activity_extras(self):
d = ActivityObject.activity_extras.fget(self)
d.update(summary=self.title)
return d
def author(self):
'''The author of the first snapshot of this BlogPost'''
return M.User.query.get(_id=self.get_version(1).author.id) or M.User.anonymous()
'AppConfig', if_missing=lambda: c.app.config._id)
app_config = RelationProperty('AppConfig')
moved_to_url = FieldProperty(str, required=True, allow_none=False)
class SpamCheckResult(MappedClass):
class __mongometa__:
session = main_orm_session
name = 'spam_check_result'
indexes = [
('project_id', 'result'),
('user_id', 'result'),
]
_id = FieldProperty(S.ObjectId)
ref_id = ForeignIdProperty('ArtifactReference')
ref = RelationProperty('ArtifactReference', via='ref_id')
project_id = ForeignIdProperty('Project')
project = RelationProperty('Project', via='project_id')
user_id = ForeignIdProperty('User')
user = RelationProperty('User', via='user_id')
timestamp = FieldProperty(datetime, if_missing=datetime.utcnow)
result = FieldProperty(bool)
return super(Forum, self).get_mail_footer(notification, toaddr)
class ForumThread(M.Thread):
class __mongometa__:
name = 'forum_thread'
indexes = [
'flags',
'discussion_id',
'import_id', # may be used by external legacy systems
]
type_s = 'Thread'
discussion_id = ForeignIdProperty(Forum)
first_post_id = ForeignIdProperty('ForumPost')
flags = FieldProperty([str])
discussion = RelationProperty(Forum)
posts = RelationProperty('ForumPost', via='thread_id')
first_post = RelationProperty('ForumPost', via='first_post_id')
@property
def type_name(self):
return 'topic'
@property
def status(self):
if len(self.posts) == 1:
return self.posts[0].status
else:
return 'ok'
def update(self, args):
self.cookbook_name = args['cookbook_name']
self.metadata = args['metadata']
self.definitions = args['definitions']
self.attributes = args['attributes']
self.files = args['files']
self.providers = args['providers']
self.templates = args['templates']
self.recipes = args['recipes']
self.resources = args['resources']
self.root_files = args['root_files']
self.libraries=args['libraries']
orm_session.mapper(CookbookVersion, cookbook_version, properties=dict(
account_id=ForeignIdProperty('Account'),
account=RelationProperty('Account')))
def shorthand_id(self):
return self.short
class AwardGrant(Artifact):
"An :class:`Award ` can be bestowed upon a project by a neighborhood"
class __mongometa__:
session = main_orm_session
name = 'grant'
indexes = ['short']
type_s = 'Generic Award Grant'
_id = FieldProperty(S.ObjectId)
award_id = ForeignIdProperty(Award, if_missing=None)
award = RelationProperty(Award, via='award_id')
granted_by_neighborhood_id = ForeignIdProperty(
'Neighborhood', if_missing=None)
granted_by_neighborhood = RelationProperty(
'Neighborhood', via='granted_by_neighborhood_id')
granted_to_project_id = ForeignIdProperty('Project', if_missing=None)
granted_to_project = RelationProperty(
'Project', via='granted_to_project_id')
award_url = FieldProperty(str, if_missing='')
comment = FieldProperty(str, if_missing='')
timestamp = FieldProperty(datetime, if_missing=datetime.utcnow)
def index(self):
result = Artifact.index(self)
result.update(
_id_s=self._id,
def upload(self, ifp):
fs = self.query.mapper.collection.m.fs
fs.delete(self._id)
with fs.new_file(
_id=self._id, account_id=self.account_id, needs_upload=False) as ofp:
while True:
chunk = ifp.read(self.CHUNKSIZE)
if chunk: ofp.write(chunk)
else: break
if ofp.md5 != self.md5:
import pdb; pdb.set_trace()
chef_file.m.fs.delete(self._id)
raise Invalid('Invalid checksum', None, None)
orm_session.mapper(Sandbox, sandbox, properties=dict(
account_id=ForeignIdProperty('Account'),
account=RelationProperty('Account')))
orm_session.mapper(ChefFile, chef_file,properties=dict(
account_id=ForeignIdProperty('Account'),
account=RelationProperty('Account')))
return self.short
class AwardGrant(Artifact):
"An :class:`Award ` can be bestowed upon a project by a neighborhood"
class __mongometa__:
session = main_orm_session
name = 'grant'
indexes = ['short']
type_s = 'Generic Award Grant'
_id = FieldProperty(S.ObjectId)
award_id = ForeignIdProperty(Award, if_missing=None)
award = RelationProperty(Award, via='award_id')
granted_by_neighborhood_id = ForeignIdProperty(
'Neighborhood', if_missing=None)
granted_by_neighborhood = RelationProperty(
'Neighborhood', via='granted_by_neighborhood_id')
granted_to_project_id = ForeignIdProperty('Project', if_missing=None)
granted_to_project = RelationProperty(
'Project', via='granted_to_project_id')
award_url = FieldProperty(str, if_missing='')
comment = FieldProperty(str, if_missing='')
timestamp = FieldProperty(datetime, if_missing=datetime.utcnow)
def index(self):
result = Artifact.index(self)
result.update(
_id_s=self._id,
short_s=self.short,
timestamp_dt=self.timestamp,
:var options: an object on which various options are stored. options.mount_point is the url component for this app instance
:var acl: a dict that maps permissions (strings) to lists of roles that have the permission
"""
class __mongometa__:
session = project_orm_session
name='config'
indexes = [
'project_id',
'options.import_id',
('options.mount_point', 'project_id')]
# AppConfig schema
_id=FieldProperty(S.ObjectId)
project_id=ForeignIdProperty(Project)
discussion_id=ForeignIdProperty('Discussion')
tool_name=FieldProperty(str)
version=FieldProperty(str)
options=FieldProperty(None)
project = RelationProperty(Project, via='project_id')
discussion = RelationProperty('Discussion', via='discussion_id')
tool_data = FieldProperty({str:{str:None}}) # entry point: prefs dict
acl = FieldProperty(ACL())
def get_tool_data(self, tool, key, default=None):
return self.tool_data.get(tool, {}).get(key, default)
def set_tool_data(self, tool, **kw):
d = self.tool_data.setdefault(tool, {})
d.update(kw)
class __mongometa__:
session = main_orm_session
name = 'notification'
indexes = ['project_id']
_id = FieldProperty(str, if_missing=h.gen_message_id)
# Classify notifications
neighborhood_id = ForeignIdProperty(
'Neighborhood', if_missing=lambda: c.project.neighborhood._id)
project_id = ForeignIdProperty('Project', if_missing=lambda: c.project._id)
app_config_id = ForeignIdProperty(
'AppConfig', if_missing=lambda: c.app.config._id)
tool_name = FieldProperty(str, if_missing=lambda: c.app.config.tool_name)
ref_id = ForeignIdProperty('ArtifactReference')
topic = FieldProperty(str)
# Notification Content
in_reply_to = FieldProperty(str)
references = FieldProperty([str])
from_address = FieldProperty(str)
reply_to_address = FieldProperty(str)
subject = FieldProperty(str)
text = FieldProperty(str)
link = FieldProperty(str)
author_id = AlluraUserProperty()
feed_meta = FieldProperty(S.Deprecated)
artifact_reference = FieldProperty(S.Deprecated)
pubdate = FieldProperty(datetime, if_missing=datetime.utcnow)
ref = RelationProperty('ArtifactReference')