コード例 #1
0
ファイル: resources.py プロジェクト: artyomtrityak/kievjs
    def __init__(cls, name, bases, dct):
        MethodViewType.__init__(cls, name, bases, dct)

        def build_attrs_list(key):
            if cls.index_fields[key] is list:
                attribute = ArrayAttribute(key)
            else:
                attribute = Attribute(key)

            return attribute

        if cls.model is not None:
            cls.make_signals()
            attrs = map(build_attrs_list, cls.index_fields)
            table_name = "{}_rt".format(cls.index_name)
            cls.index_table = Index(table_name, indexer.metadata, *attrs)
            cls.select = select(["*"], from_obj=[cls.index_table])
            index_objects.append(cls)
コード例 #2
0
    def __init__(cls, name, bases, dct):
        MethodViewType.__init__(cls, name, bases, dct)

        def build_attrs_list(key):
            if cls.index_fields[key] is list:
                attribute = ArrayAttribute(key)
            else:
                attribute = Attribute(key)

            return attribute

        if cls.model is not None:
            cls.make_signals()
            attrs = map(build_attrs_list, cls.index_fields)
            table_name = "{}_rt".format(cls.index_name)
            cls.index_table = Index(table_name, indexer.metadata, *attrs)
            cls.select = select(["*"], from_obj=[cls.index_table])
            index_objects.append(cls)
コード例 #3
0
ファイル: base.py プロジェクト: Crowdlink/lever
    def __init__(mcs, name, bases, dct):
        MethodViewType.__init__(mcs, name, bases, dct)
        types = ['_pre_method', '_post_method', '_pre_action', '_post_action']
        # here to accumulate methods by priority, then this is sorted out
        # to a list
        type_funcs = {}
        # set to an empty dictionary. dict is keyed on method, or action
        for key in types:
            setattr(mcs, key, {})
            type_funcs[key] = {}

        # accumulate all attributes on this class or bases
        attrs = list(six.itervalues(dct))
        for base in bases:
            attrs.extend(list(six.itervalues(base.__dict__)))

        # loop through all the possible attrs and accumulate their attached
        # methods
        for attr in attrs:
            for key in types:
                # see if it has a special attribute designating it for use
                val = getattr(attr, key, None)
                if val:
                    # turn single attribute into iterable
                    if not isinstance(val, (list, tuple)):
                        val = (val, )

                    # build a dictionary keyed by priority
                    for method in val:
                        (type_funcs[key].setdefault(method, {}).
                                      setdefault(attr._priority, []).
                                      append(attr))

        # now run through our dictionary of lists of functions that is
        # keyed by priority and combine them into one list. equal
        # priorities are a taken first encountered order
        for typ, methods in six.iteritems(type_funcs):
            for method, pris in six.iteritems(methods):
                for pri, funcs in sorted(six.iteritems(pris)):
                    getattr(mcs, typ).setdefault(method, []).extend(funcs)
コード例 #4
0
ファイル: __init__.py プロジェクト: tomdyson/Canella-CMS
 def __new__(cls, name, bases, d):
     rv = MethodViewType.__new__(cls, name, bases, d)
     if not rv.schema:
         return rv
     default_endpoints = cls.gen_default_api_endpoints(rv)
     if hasattr(rv, 'url_map'):
         default_endpoints.update(rv.url_map)
     for url, options in default_endpoints.items():
         api.add_resource(rv,
                          url,
                          methods=options.get(
                              'methods', ['POST', 'PUT', 'DELETE', 'GET']),
                          endpoint=options.get('endpoint'))
     site_endpoint = getattr(rv.schema, 'site_endpoint', [])
     if site_endpoint:
         rv.schema._declared_fields['site_url'] = URLFor(
             site_endpoint[0], **site_endpoint[1])
     return rv