def testOrderSimple(self): d = OrderedDict() d['ciao'] = 1 d['abcbd'] = 2 d[56] = 3 for n,kv in enumerate(d.iteritems(), start = 1): self.assertEqual(n,kv[1])
def __init__(self, route, model=None, editavailable=None, list_display_links=None, object_display=None, related_field=None, url_bits_mapping=None, routes=None, always_load_fields=None, **kwargs): self.model = model ResolverMixin.__init__(self, route) RendererMixin.__init__(self, **kwargs) if routes: base_routes = OrderedDict(((r.name, r) for r in self.base_routes)) base_routes.update(((r.name, r) for r in routes)) self.base_routes = list(itervalues(base_routes)) else: self.base_routes = list(self.base_routes) if not self.pagination: self.pagination = html.Pagination() self.object_views = [] self.model_url_bits = () self.editavailable = editavailable if editavailable is not None else\ self.editavailable self.list_display_links = list_display_links or self.list_display_links self.related_field = related_field or self.related_field self.always_load_fields = always_load_fields or self.always_load_fields if self.parent_view and not self.related_field: raise UrlException('Parent view "{0}" specified in\ application {1} without a "related_field".'.format(self.parent_view, self)) self.object_display = object_display or self.object_display self.url_bits_mapping = self.url_bits_mapping or url_bits_mapping self.clear()
def get_form_meta_data(bases, attrs, with_base_fields=True): fields = [] inlines = [] for name, obj in list(attrs.items()): if isinstance(obj, Field): # field name priority is the name in the instance obj.name = obj.name or name fields.append((obj.name, attrs.pop(name))) elif isinstance(obj, FieldList): obj = attrs.pop(name) fields.extend(obj.fields(name + '__')) elif isinstance(obj, FormSet): obj.name = name inlines.append((name, attrs.pop(name))) fields = sorted(fields, key=lambda x: x[1].creation_counter) inlines = sorted(inlines, key=lambda x: x[1].creation_counter) # If this class is subclassing another Form, add that Form's fields. # Note that we loop over the bases in *reverse*. This is necessary in # order to preserve the correct order of fields. if with_base_fields: for base in bases[::-1]: if hasattr(base, 'base_fields'): fields = list(base.base_fields.items()) + fields else: for base in bases[::-1]: if hasattr(base, 'declared_fields'): fields = list(base.declared_fields.items()) + fields return OrderedDict(fields), OrderedDict(inlines)
def testOrderSimple(self): d = OrderedDict() d['ciao'] = 1 d['abcbd'] = 2 d[56] = 3 for n, kv in enumerate(d.iteritems(), start=1): self.assertEqual(n, kv[1])
def __init__(self, route, model=None, editavailable=None, list_display_links=None, object_display=None, related_field=None, url_bits_mapping=None, routes=None, always_load_fields=None, **kwargs): self.model = model ResolverMixin.__init__(self, route) RendererMixin.__init__(self, **kwargs) if routes: base_routes = OrderedDict(((r.name,r) for r in self.base_routes)) base_routes.update(((r.name,r) for r in routes)) self.base_routes = list(itervalues(base_routes)) else: self.base_routes = list(self.base_routes) if not self.pagination: self.pagination = html.Pagination() self.object_views = [] self.model_url_bits = () self.editavailable = editavailable if editavailable is not None else\ self.editavailable self.list_display_links = list_display_links or self.list_display_links self.related_field = related_field or self.related_field self.always_load_fields = always_load_fields or self.always_load_fields if self.parent_view and not self.related_field: raise UrlException('Parent view "{0}" specified in\ application {1} without a "related_field".'.format(self.parent_view,self)) self.object_display = object_display or self.object_display self.url_bits_mapping = self.url_bits_mapping or url_bits_mapping self.clear()
def _all_ordered_choices(self, bfield, selected): options = OrderedDict(((opt.attr('value'), opt) for opt in\ self._all_choices(bfield, selected))) for value in selected: opt = options.pop(value, None) if opt is not None: yield opt for opt in itervalues(options): yield opt
def testOrderList(self): from stdnet.utils.populate import populate x = populate('string', 300, min=5, max=15) y = populate('string', 300, min=5, max=15) data = zip(x, y) od = OrderedDict(data) self.assertEqual(len(od), 300) for t, v in zip(od.iteritems(), data): self.assertEqual(t, v)
def testOrderList(self): from stdnet.utils.populate import populate x = populate('string',300, min = 5, max = 15) y = populate('string',300, min = 5, max = 15) data = zip(x,y) od = OrderedDict(data) self.assertEqual(len(od),300) for t,v in zip(od.iteritems(),data): self.assertEqual(t,v)
def _set_parent(self, parent): # Get the element if available if self.tag == 'body': if parent: raise ValueError('Body cannot have parent') return self # When switching parents, remove itself from current parent children if self._parent and self._parent is not parent: self._parent.remove(self) clone = self._clone self._parent = parent = parent or self.body() self._clone = parent._clone # If the parent is a clone, unwind mixins if not clone and self._clone and self._children: children = self._children self._children = OrderedDict() for tag, c in iteritems(children): if isinstance(c, mixin): c(self) else: self._children[tag] = c c = parent._children.get(self.code) if isinstance(c, list) and self not in c: c.append(self) else: parent._children[self.code] = [self]
def __init__(self, settings=None, route='/', parent=None, routes=None, APPLICATION_URLS=None, **handlers): super(Site, self).__init__(route, routes=routes) self.APPLICATION_URLS = APPLICATION_URLS self._model_registry = {} self._page_layout_registry = OrderedDict() self.plugin_choices = [('', '-----------------')] self.request_processors = [] if parent is None: self.submit_data_middleware = SubmitDataMiddleware() settings = settings or get_settings() if not handlers.get('permissions'): handlers['permissions'] = PermissionHandler(settings) else: self.submit_data_middleware = parent.submit_data_middleware self.parent = parent if settings: self.internals['settings'] = settings self.internals.update(handlers) self.register_page_layout('default')
def _make_clone(self, parent=None, recursive=True): '''Clone the current :class:`css` element and execute all :class:`mixin` in the process.''' if self._clone: if parent is not None: self._set_parent(parent) return self elem = self.make(self._tag, clone=True) elem.parent_relationship = self.parent_relationship elem.comment = self.comment elem._attributes.extend(self._attributes) parent = parent if parent is not None else self.parent if parent is not None: parent = parent._make_clone(recursive=False) elem._set_parent(parent) if recursive: # first execute all mixins children = elem._children for tag, child in iteritems(self.children): if isinstance(child, mixin): child(elem) elif tag in children: children[tag].extend(child) else: children[tag] = list(child) # now aggregate elem._children = OrderedDict() for tag, child_list in iteritems(children): for child in child_list: child._make_clone(parent=elem) return elem
def make(cls, tag, clone=False): o = super(css, cls).__new__(cls) if tag == 'body' and clone: data = cls.local() data.real_body = data.body data.body = o o._tag = tag o._children = OrderedDict() o._attributes = [] o._parent = None o._clone = clone return o
def __init__(self, cn=None, data=None, attrs=None, css=None): classes = self.classes self.classes = set() self.data = deepcopy(self.data) if self.data else {} self.attrs = deepcopy(self.attrs) if self.attrs else {} self._css = deepcopy(self._css) if self.attrs else {} self.addClass(classes) self.addData(data) self.addClass(cn) self.addAttrs(attrs) self.css(css) self.children = OrderedDict() self.internal = {}
class jhtmls(HeaderBody): '''Contains a list of objects {identifier, html and type} :parameter html: html to add to web page. :parameter identifier: jquery selector :parameter type: one of ``"replacewith"``, ``"replace"``, ``"addto"``. ''' def __init__(self, environ, html=None, identifier=None, alldocument=True, type='replace', removable=False): self.html=OrderedDict() if html != None: self.add(identifier, html, type, alldocument, removable) def header(self, request): return 'htmls' def __update(self, obj): html=self.html key =obj.get('identifier') objr=html.get(key,None) if objr is None: html[key]=obj else: objr['html'] += obj['html'] def add(self, identifier, html='', type='replace', alldocument=True, removable=False): obj={'identifier': identifier, 'html': html, 'type': type, 'alldocument': alldocument, 'removable': removable} self.__update(obj) def update(self, html): if isinstance(html, jhtmls): html=html.html for v in html.values(): self.__update(v) def body(self, request): return list(self.html.values())
def tojson(self): return OrderedDict(((v.name, v.tojson()) for v in self))
def testInstance(self): d = OrderedDict() self.assertTrue(isinstance(d, dict))
def __init__(self, environ, html=None, identifier=None, alldocument=True, type='replace', removable=False): self.html=OrderedDict() if html != None: self.add(identifier, html, type, alldocument, removable)