Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Ensure that a list field only accepts lists with valid elements."""
access_level_choices = (
("a", u"Administration"),
("b", u"Manager"),
("c", u"Staff"),
)
class User(Document):
pass
class Comment(EmbeddedDocument):
content = StringField()
class BlogPost(Document):
content = StringField()
comments = ListField(EmbeddedDocumentField(Comment))
tags = ListField(StringField())
authors = ListField(ReferenceField(User))
authors_as_lazy = ListField(LazyReferenceField(User))
generic = ListField(GenericReferenceField())
generic_as_lazy = ListField(GenericLazyReferenceField())
access_list = ListField(choices=access_level_choices, display_sep=", ")
User.drop_collection()
BlogPost.drop_collection()
post = BlogPost(content="Went for a walk today...")
post.validate()
post.tags = "fun"
self.assertRaises(ValidationError, post.validate)
post.tags = [1, 2]
def test_default_value_is_not_used_when_changing_value_to_empty_list_for_dyn_doc(
self
):
"""List field with default can be set to the empty list (dynamic)"""
# Issue #1733
class Doc(DynamicDocument):
x = ListField(IntField(), default=lambda: [42])
doc = Doc(x=[1]).save()
doc.x = []
doc.y = 2 # Was triggering the bug
doc.save()
reloaded = Doc.objects.get(id=doc.id)
self.assertEqual(reloaded.x, [])
job.delete()
except (mongoengine.errors.DoesNotExist, mongoengine.errors.FieldDoesNotExist):
pass
super().delete(*args, **kwargs)
class Term(EmbeddedDocument):
predicate = StringField()
literals = ListField(StringField())
class Comparison(EmbeddedDocument):
obj1 = ListField(StringField())
comp = StringField()
obj2 = ListField(StringField())
class CodedStep(ExtrovirtsDocument):
name = StringField()
display_name = StringField()
coded_name = StringField()
parameters = ListField(StringField())
score = IntField()
add = EmbeddedDocumentListField(Term)
requirement_terms = EmbeddedDocumentListField(Term)
requirement_comparisons = EmbeddedDocumentListField(Comparison)
remove = EmbeddedDocumentListField(Term)
deterministic = BooleanField()
significant_parameters = ListField(IntField())
bindings = DictField()
source_hash = BinaryField()
from __future__ import unicode_literals
from mongoengine import BooleanField, StringField, ListField, ReferenceField, \
CASCADE
from core.database import YetiDocument
from core.user import User
class Group(YetiDocument):
enabled = BooleanField(required=True, default=True)
groupname = StringField(required=True, unique=True)
members = ListField(ReferenceField(User, reverse_delete_rule=CASCADE))
admins = ListField(ReferenceField(User, reverse_delete_rule=CASCADE))
SEARCH_ALIASES = {}
meta = dict(
collection = 'Groups',
allow_inheritance = False,
indexes = [],
)
id = StringField(db_field='_id', primary_key=True)
title = StringField(db_field='t')
rules = ListField(EmbeddedDocumentField(ACLRule), db_field='r')
join_rules = ListField(EmbeddedDocumentField(ACLRule), db_field='j', default=list)
request_rules = ListField(EmbeddedDocumentField(ACLRule), db_field='q', default=list)
join_members = ListField(ReferenceField(EVECharacter), db_field='jm', default=list)
request_members = ListField(ReferenceField(EVECharacter), db_field='rm', default=list)
requests = ListField(ReferenceField(EVECharacter), db_field='rl', default=list)
request_members_names = ListField(StringField(), default=list)
join_members_names = ListField(StringField(), default=list)
creator = ReferenceField('User', db_field='c')
modified = DateTimeField(db_field='m', default=datetime.utcnow)
_permissions = ListField(ReferenceField(Permission), db_field='p')
# Permissions
VIEW_PERM = 'core.group.view.{group_id}'
EDIT_ACL_PERM = 'core.group.edit.acl.{group_id}'
EDIT_PERMS_PERM = 'core.group.edit.perms.{group_id}'
EDIT_MEMBERS_PERM = 'core.group.edit.members.{group_id}'
EDIT_REQUESTS_PERM = 'core.group.edit.requests.{group_id}'
EDIT_TITLE_PERM = 'core.group.edit.title.{group_id}'
EDIT_ID_PERM = 'core.group.edit.id.{group_id}'
DELETE_PERM = 'core.group.delete.{group_id}'
CREATE_PERM = 'core.group.create'
# -*- encoding: utf-8 -*-
import gzip
import mongoengine
from discograph.library.mongo.MongoModel import MongoModel
class Master(MongoModel, mongoengine.Document):
### MONGOENGINE FIELDS ###
artists = mongoengine.EmbeddedDocumentListField('ArtistCredit')
data_quality = mongoengine.StringField()
discogs_id = mongoengine.IntField(unique=True, null=True, sparse=True)
genres = mongoengine.ListField(mongoengine.StringField())
main_release_id = mongoengine.IntField()
release_date = mongoengine.DateTimeField()
styles = mongoengine.ListField(mongoengine.StringField())
title = mongoengine.StringField()
### MONGOENGINE META ###
meta = {
'indexes': [
'discogs_id',
'title',
'$title',
],
'ordering': ['+discogs_id'],
}
display_name = StringField(required=True)
# This is the owner of the case
owner = StringField(required=True)
# These are the names of all the collaborators that are allowed to view the
# case, including the owner
collaborators = ListField(StringField())
assignee = ReferenceField('User')
individuals = ListField(EmbeddedDocumentField(Individual))
created_at = DateTimeField(default=datetime.now)
updated_at = DateTimeField(default=datetime.now)
suspects = ListField(ReferenceField('Variant'))
causative = ReferenceField('Variant')
synopsis = StringField(default='')
status = StringField(default='inactive', choices=STATUS_ORDER)
is_research = BooleanField()
events = ListField(EmbeddedDocumentField(Event))
comments = ListField(EmbeddedDocumentField(Event))
# This decides which gene lists that should be shown when the case is opened
default_gene_lists = ListField(StringField())
clinical_gene_lists = ListField(EmbeddedDocumentField(GeneList))
research_gene_lists = ListField(EmbeddedDocumentField(GeneList))
genome_build = StringField()
genome_version = FloatField()
analysis_date = StringField()
gender_check = StringField(choices=['unconfirmed', 'confirm', 'deviation'],
default='unconfirmed')
phenotype_terms = ListField(EmbeddedDocumentField(PhenotypeTerm))
# madeline info is a full xml file
### CLASS VARIABLES ###
date_regex = re.compile('^(\d{4})-(\d{2})-(\d{2})$')
date_no_dashes_regex = re.compile('^(\d{4})(\d{2})(\d{2})$')
year_regex = re.compile('^\d\d\d\d$')
### MONGOENGINE FIELDS ###
discogs_id = mongoengine.IntField(primary_key=True)
artists = mongoengine.EmbeddedDocumentListField('ArtistCredit')
companies = mongoengine.EmbeddedDocumentListField('CompanyCredit')
country = mongoengine.StringField()
#data_quality = mongoengine.StringField()
extra_artists = mongoengine.EmbeddedDocumentListField('ArtistCredit')
formats = mongoengine.EmbeddedDocumentListField('Format')
genres = mongoengine.ListField(mongoengine.StringField())
identifiers = mongoengine.EmbeddedDocumentListField('Identifier')
labels = mongoengine.EmbeddedDocumentListField('LabelCredit')
master_id = mongoengine.IntField()
release_date = mongoengine.DateTimeField()
#status = mongoengine.StringField()
styles = mongoengine.ListField(mongoengine.StringField())
title = mongoengine.StringField()
tracklist = mongoengine.EmbeddedDocumentListField('Track')
### MONGOENGINE META ###
meta = {
'indexes': [
'#title',
'$title',
'discogs_id',
# the pkglist, because mongoengine does not allow to modify existing items in the list
# and add new items to the list at the same time.
self.save()
self.pkglist += collections_to_add
self.save()
class PackageGroup(UnitMixin, ContentUnit):
# TODO add docstring to this class
package_group_id = mongoengine.StringField(required=True)
repo_id = mongoengine.StringField(required=True)
description = mongoengine.StringField()
default_package_names = mongoengine.ListField()
optional_package_names = mongoengine.ListField()
mandatory_package_names = mongoengine.ListField()
name = mongoengine.StringField()
default = mongoengine.BooleanField(default=False)
display_order = mongoengine.IntField()
user_visible = mongoengine.BooleanField(default=False)
translated_name = mongoengine.DictField()
translated_description = mongoengine.DictField()
langonly = mongoengine.StringField()
conditional_package_names = mongoengine.ListField()
# For backward compatibility
_ns = mongoengine.StringField(default='units_package_group')
_content_type_id = mongoengine.StringField(required=True, default='package_group')
unit_key_fields = ('package_group_id', 'repo_id')
unit_display_name = 'Package Group'
unit_description = 'Yum Package group information'
class Questions(Document):
questionId = StringField(unique=True)
questionType = IntField(default = 0)
questionDescription = StringField()# special formatted inside the description itself
pictures = ListField(StringField())
options = StringField()
answer = StringField()
hint = StringField()
explanation = StringField()
time = IntField()
xp = IntField()
tagsAllSubjects = ListField(StringField()) #categorynameIndex , ....
tagsAllIndex = ListField(StringField())
tags=ListField(StringField())
meta = {
'indexes': [
'tags',
'tagsAllSubjects',
'tagsAllIndex'
]
}
@staticmethod
def addQuestion(questionId, questionType ,questionDescription , pictures, options, answer, hint , explanation , time, xp , tags):
questionId = str(questionId)
question = Questions.objects(questionId=questionId)