Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
 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
Beispiel #8
0
 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'))
Beispiel #9
0
 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'))
Beispiel #10
0
 def get_db(self):
     '''
     Useful method, returns a database connection
     '''
     request = testing.DummyRequest()
     return get_db(request)