def serialize(self, field, cstruct, **kw): html = "" if cstruct in (null, None, []): cstruct = self.null_value request = pyramid.threadlocal.get_current_request() from gecoscc.db import get_db mongodb = get_db(request) for i, cstruct_item in enumerate(cstruct): field_iter = copy(field) if i > 0: field_iter.name = "%s-%s" % (field.name, i) if cstruct_item: ou = mongodb.nodes.find_one({'_id': ObjectId(cstruct_item)}) if not ou: continue path = ou['path'].split(',') path.append(cstruct_item) else: path = [cstruct_item] html += self.get_select(mongodb, path, field_iter, **kw) html += "<p></p>" if not html: html += self.get_select(mongodb, ['root'], field_iter, **kw) return html
def __call__(self, node, value): request = pyramid.threadlocal.get_current_request() from gecoscc.db import get_db mongodb = get_db(request) if not mongodb.printer_models.find_one({'manufacturer': value}): node.raise_invalid(self.err_msg)
def __call__(self, node, value): ignore_unique = getattr(node, 'ignore_unique', False) if ignore_unique: return request = pyramid.threadlocal.get_current_request() from gecoscc.db import get_db mongodb = get_db(request) if mongodb.adminusers.find({node.name: value}).count() > 0: err_msg = _(self.err_msg, mapping={'val': value}) node.raise_invalid(err_msg)
def get_dummy_request(self): ''' Useful method, returns a typical request, with the same request properties than pyramid add (see gecoscc/__init__) ''' request = testing.DummyRequest() request.db = get_db(request) request.userdb = get_userdb(request) user = request.db.adminusers.find_one({'is_superuser': True}) if not user: user = request.userdb.create_user('test', 'test', '*****@*****.**', {'is_superuser': True}) request.user = request.db.adminusers.find_one({'is_superuser': True}) return request
def __call__(self, node, value): super(UpdateSequenceValidator, self).__call__(node,value) if self.filename: m = re.match(self.pattern, self.filename) request = pyramid.threadlocal.get_current_request() from gecoscc.db import get_db mongodb = get_db(request) nextseq = getNextUpdateSeq(mongodb) # Numeric update naming if m is not None and m.group(1) != nextseq: err_msg = _(self.err_msg, mapping={'val': nextseq}) node.raise_invalid(err_msg) else: if mongodb.updates.find({'name':self.filename}).count() > 0: node.raise_invalid(_('This name already exists'))
def __call__(self, node, value): super(UpdateSequenceValidator, self).__call__(node,value) if self.filename: m = re.match(SERIALIZED_UPDATE_PATTERN, self.filename) request = pyramid.threadlocal.get_current_request() from gecoscc.db import get_db mongodb = get_db(request) nextseq = getNextUpdateSeq(mongodb) # Numeric update naming if m is not None and m.group(1) != nextseq: err_msg = _(self.err_msg, mapping={'val': nextseq}) node.raise_invalid(err_msg) else: if mongodb.updates.find({'name':self.filename}).count() > 0: node.raise_invalid(_('This name already exists')) sequence = re.match(BASE_UPDATE_PATTERN, self.filename).group(1) if mongodb.updates.find({'_id': sequence}).count() > 0: node.raise_invalid(_('This sequence already exists'))
def get_db(self): ''' Useful method, returns a database connection ''' request = testing.DummyRequest() return get_db(request)