django.utils.functional.curry

Here are the examples of the python api django.utils.functional.curry taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

200 Examples 7

Example 1

Project: talk.org
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(FileField, self).contribute_to_class(cls, name)
        setattr(cls, 'get_%s_filename' % self.name, curry(cls._get_FIELD_filename, field=self))
        setattr(cls, 'get_%s_url' % self.name, curry(cls._get_FIELD_url, field=self))
        setattr(cls, 'get_%s_size' % self.name, curry(cls._get_FIELD_size, field=self))
        setattr(cls, 'save_%s_file' % self.name, lambda instance, filename, raw_contents, save=True: instance._save_FIELD_file(self, filename, raw_contents, save))
        dispatcher.connect(self.delete_file, signal=signals.post_delete, sender=cls)

Example 2

Project: talk.org
Source File: base.py
View license
    def _prepare(cls):
        # Creates some methods once self._meta has been populated.
        opts = cls._meta
        opts._prepare(cls)

        if opts.order_with_respect_to:
            cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
            cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
            setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls))
            setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls))

        # Give the class a docstring -- its definition.
        if cls.__doc__ is None:
            cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields]))

        if hasattr(cls, 'get_absolute_url'):
            cls.get_absolute_url = curry(get_absolute_url, opts, cls.get_absolute_url)

        dispatcher.send(signal=signals.class_prepared, sender=cls)

Example 3

Project: talk.org
Source File: related.py
View license
    def prepare_field_objs_and_params(self, manipulator, name_prefix):
        params = {'validator_list': self.validator_list[:], 'member_name': name_prefix + self.attname}
        if self.rel.raw_id_admin:
            field_objs = self.get_manipulator_field_objs()
            params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
        else:
            if self.radio_admin:
                field_objs = [oldforms.RadioSelectField]
                params['ul_class'] = get_ul_class(self.radio_admin)
            else:
                if self.null:
                    field_objs = [oldforms.NullSelectField]
                else:
                    field_objs = [oldforms.SelectField]
            params['choices'] = self.get_choices_default()
        return field_objs, params

Example 4

Project: talk.org
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(ImageField, self).contribute_to_class(cls, name)
        # Add get_BLAH_width and get_BLAH_height methods, but only if the
        # image field doesn't have width and height cache fields.
        if not self.width_field:
            setattr(cls, 'get_%s_width' % self.name, curry(cls._get_FIELD_width, field=self))
        if not self.height_field:
            setattr(cls, 'get_%s_height' % self.name, curry(cls._get_FIELD_height, field=self))

Example 5

Project: talk.org
Source File: manipulators.py
View license
    def _prepare(cls, model):
        cls.model = model
        cls.manager = model._default_manager
        cls.opts = model._meta
        for field_name_list in cls.opts.unique_together:
            setattr(cls, 'isUnique%s' % '_'.join(field_name_list), curry(manipulator_validator_unique_together, field_name_list, cls.opts))
        for f in cls.opts.fields:
            if f.unique_for_date:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_date), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_date), cls.opts, 'date'))
            if f.unique_for_month:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_month), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_month), cls.opts, 'month'))
            if f.unique_for_year:
                setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_year), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_year), cls.opts, 'year'))

Example 6

Project: talk.org
Source File: __init__.py
View license
    def simple_tag(self,func):
        params, xx, xxx, defaults = getargspec(func)

        class SimpleNode(Node):
            def __init__(self, vars_to_resolve):
                self.vars_to_resolve = map(Variable, vars_to_resolve)

            def render(self, context):
                resolved_vars = [var.resolve(context) for var in self.vars_to_resolve]
                return func(*resolved_vars)

        compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode)
        compile_func.__doc__ = func.__doc__
        self.tag(getattr(func, "_decorated_function", func).__name__, compile_func)
        return func

Example 7

Project: django-photologue-old
Source File: models.py
View license
    def add_accessor_methods(self, *args, **kwargs):
        for size in PhotoSizeCache().sizes.keys():
            setattr(self, 'get_%s_size' % size,
                    curry(self._get_SIZE_size, size=size))
            setattr(self, 'get_%s_photosize' % size,
                    curry(self._get_SIZE_photosize, size=size))
            setattr(self, 'get_%s_url' % size,
                    curry(self._get_SIZE_url, size=size))
            setattr(self, 'get_%s_filename' % size,
                    curry(self._get_SIZE_filename, size=size))

Example 8

Project: django-audit-log
Source File: middleware.py
View license
    def process_request(self, request):
        if settings.DISABLE_AUDIT_LOG:
            return
        if not request.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
            if hasattr(request, 'user') and request.user.is_authenticated():
                user = request.user
            else:
                user = None
            session = request.session.session_key
            update_pre_save_info = curry(self._update_pre_save_info, user, session)
            update_post_save_info = curry(self._update_post_save_info, user, session)
            signals.pre_save.connect(update_pre_save_info,  dispatch_uid = (self.__class__, request,), weak = False)
            signals.post_save.connect(update_post_save_info,  dispatch_uid = (self.__class__, request,), weak = False)

Example 9

Project: GAE-Bulk-Mailer
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        self.set_attributes_from_name(name)
        self.model = cls
        cls._meta.add_field(self)
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name,
                    curry(cls._get_FIELD_display, field=self))

Example 10

Project: GAE-Bulk-Mailer
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self,
                      is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self,
                      is_next=False))

Example 11

Project: django-photologue
Source File: models.py
View license
    def add_accessor_methods(self, *args, **kwargs):
        for size in PhotoSizeCache().sizes.keys():
            setattr(self, 'get_%s_size' % size,
                    curry(self._get_SIZE_size, size=size))
            setattr(self, 'get_%s_photosize' % size,
                    curry(self._get_SIZE_photosize, size=size))
            setattr(self, 'get_%s_url' % size,
                    curry(self._get_SIZE_url, size=size))
            setattr(self, 'get_%s_filename' % size,
                    curry(self._get_SIZE_filename, size=size))

Example 12

Project: django-photologue
Source File: models.py
View license
    def __getattr__(self, name):
        global size_method_map
        if not size_method_map:
            init_size_method_map()
        di = size_method_map.get(name, None)
        if di is not None:
            result = curry(getattr(self, di['base_name']), di['size'])
            setattr(self, name, result)
            return result
        else:
            raise AttributeError

Example 13

Project: django-seo2
Source File: base.py
View license
def register_signals():
    for metadata_class in list(registry.values()):
        model_instance = metadata_class._meta.get_model('modelinstance')
        if model_instance is not None:
            update_callback = curry(_update_callback,
                                    model_class=model_instance)
            delete_callback = curry(_delete_callback,
                                    model_class=model_instance)

            # Connect the models listed in settings to the update callback.
            for model in metadata_class._meta.seo_models:
                # TODO Currently it's not needed to create metadata for new
                # instance
                models.signals.post_save.connect(update_callback, sender=model,
                                                 weak=False)
                models.signals.pre_delete.connect(delete_callback,
                                                  sender=model, weak=False)

Example 14

Project: snowy
Source File: tests.py
View license
    def setUp(self):
        # Although client.put now exists in Django 1.1, it is unusable for us:
        # http://code.djangoproject.com/ticket/11371
        # So, we override it with our own working version:
        self.client.put = curry(self.client.post, REQUEST_METHOD='PUT')
        # TODO: Use standard consumer?
        self.consumer = Consumer(name='Test Consumer', description='Test',
                                 status='accepted')
        self.consumer.key="123"
        self.consumer.secret="123"
        self.consumer.save()
        self.admin_requester = OAuthRequester(self, 'admin', 'admin',
                                              self.consumer)
        self.test1_requester = OAuthRequester(self, 'test1', 'test1',
                                              self.consumer)

Example 15

Project: django-dbsettings
Source File: tests.py
View license
    def test_declaration(self):
        "Group declarations can only contain values and a docstring"
        # This definition is fine
        attrs = {
            '__doc__': "This is a docstring",
            'test': dbsettings.IntegerValue(),
        }
        # So this should succeed
        type('GoodGroup', (dbsettings.Group,), attrs)

        # By adding an invalid attribute
        attrs['problem'] = 'not a Value'
        # This should fail
        self.assertRaises(TypeError, curry(type, 'BadGroup', (dbsettings.Group,), attrs))

        # Make sure affect models get the new permissions
        self.assertTrue('can_edit_populated_settings' in dict(Populated._meta.permissions))
        self.assertTrue('can_edit_unpopulated_settings' in dict(Unpopulated._meta.permissions))

Example 16

Project: splunk-webframework
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        self.set_attributes_from_name(name)
        self.model = cls
        cls._meta.add_field(self)
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name,
                    curry(cls._get_FIELD_display, field=self))

Example 17

Project: splunk-webframework
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self,
                      is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self,
                      is_next=False))

Example 18

Project: django-image-filer
Source File: __init__.py
View license
    def add_accessor_methods(self, *args, **kwargs):
        for template in ImageManipulationTemplateCache().templates.keys():
            setattr(self, 'get_%s_template' % template,
                    curry(self._get_TEMPLATE_template, template=template))
            setattr(self, 'get_%s_size' % template,
                    curry(self._get_TEMPLATE_size, template=template))
            setattr(self, 'get_%s_url' % template,
                    curry(self._get_TEMPLATE_url, template=template))
            setattr(self, 'get_%s_filename' % template,
                    curry(self._get_TEMPLATE_filename, template=template))

Example 19

Project: tendenci
Source File: models.py
View license
    def add_accessor_methods(self):
        """
        Dynamically create Meta methods.
        self.get_<type>() method
        """
        for field in ('keywords','title','description', 'canonical_url'):
            setattr(self,'get_%s' % field, curry(self.__get_meta, field))

Example 20

Project: tendenci
Source File: models.py
View license
    def add_accessor_methods(self, *args, **kwargs):
        for size in PhotoSizeCache().sizes.keys():
            setattr(self, 'get_%s_size' % size,
                    curry(self._get_SIZE_size, size=size))
            setattr(self, 'get_%s_photosize' % size,
                    curry(self._get_SIZE_photosize, size=size))
            setattr(self, 'get_%s_url' % size,
                    curry(self._get_SIZE_url, size=size))
            setattr(self, 'get_%s_filename' % size,
                    curry(self._get_SIZE_filename, size=size))

Example 21

Project: hubplus
Source File: mutations.py
View license
    def add_m2m_table(self, app_label, proj_sig):
        app_sig = proj_sig[app_label]
        model_sig = app_sig[self.model_name]

        model = MockModel(proj_sig, app_label, self.model_name, model_sig)
        field = create_field(proj_sig, self.field_name, self.field_type, self.field_attrs)
        field.m2m_db_table = curry(field._get_m2m_db_table, model._meta)

        related_app_label, related_model_name = self.field_attrs['related_model'].split('.')
        related_sig = proj_sig[related_app_label][related_model_name]
        related_model = MockModel(proj_sig, related_app_label, related_model_name, related_sig)
        related = MockRelated(related_model, model, field)

        field.m2m_column_name = curry(field._get_m2m_column_name, related)
        field.m2m_reverse_name = curry(field._get_m2m_reverse_name, related)

        sql_statements = evolver.add_m2m_table(model, field)

        return sql_statements

Example 22

Project: confista
Source File: utils.py
View license
def deadline_expired(code_name):
    def wrapped(func, *args, **kwargs):
        try:
            expiration = Deadline.objects.get(code_name = code_name)
        except ObjectDoesNotExist:
            return func
        if not datetime.now() > expiration.expiry:
            return func
        return curry(redirect, expiration = expiration)
    return wrapped

Example 23

Project: treeio
Source File: user.py
View license
    def process_request(self, request):
        "Process request"

        view = None
        try:
            view, args, kwargs = resolve(request.path)
        except Exception:
            pass

        if view == ajax_popup:
            process_created_object = curry(
                self.process_created_object, request)
            signals.post_save.connect(
                process_created_object, dispatch_uid=request.user, weak=False)

Example 24

Project: PiplMesh
Source File: tests.py
View license
    def _render(self, request):
        context = template.RequestContext(request)

        data = {}
        on_template_render = functional.curry(client.store_rendered_templates, data)
        signals.template_rendered.connect(on_template_render, dispatch_uid='template-render')

        try:
            rendered = panel.HoroscopePanel().render(request, context)
        finally:
            signals.template_rendered.disconnect(dispatch_uid='template-render')

        return data, rendered

Example 25

Project: django-stories
Source File: admin.py
View license
    def get_changelist_formset(self, request, **kwargs):
        """
        Returns the quickedit formset for the row
        """
        defaults = {
            'formfield_callback': curry(
                self.formfield_for_dbfield,
                request=request),
        }
        defaults.update(kwargs)
        QEForm = modelform_factory(self.model)
        return modelformset_factory(
            self.model,
            QEForm,
            extra=0,
            fields=self.quick_editable,
            **defaults)

Example 26

Project: django-nonrel
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        self.set_attributes_from_name(name)
        self.model = cls
        cls._meta.add_field(self)
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name, curry(cls._get_FIELD_display, field=self))

Example 27

Project: django-nonrel
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=False))

Example 28

Project: hue
Source File: forms.py
View license
def design_form_by_type(node_type, user, workflow):
  klass_form = _node_type_TO_FORM_CLS[node_type]

  if node_type == 'subworkflow':
    klass_form = curry(klass_form, user=user, workflow=workflow)

  return klass_form

Example 29

Project: decode-Django
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        self.set_attributes_from_name(name)
        self.model = cls
        cls._meta.add_field(self)
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name,
                    curry(cls._get_FIELD_display, field=self))

Example 30

Project: decode-Django
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self,
                      is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self,
                      is_next=False))

Example 31

Project: django-compositepks
Source File: related.py
View license
    def contribute_to_related_class(self, cls, related):
        # m2m relations to self do not have a ManyRelatedObjectsDescriptor,
        # as it would be redundant - unless the field is non-symmetrical.
        if related.model != related.parent_model or not self.rel.symmetrical:
            # Add the descriptor for the m2m relation
            setattr(cls, related.get_accessor_name(), ManyRelatedObjectsDescriptor(related))

        # Set up the accessors for the column names on the m2m table
        self.m2m_column_name = curry(self._get_m2m_column_name, related)
        self.m2m_reverse_name = curry(self._get_m2m_reverse_name, related)

Example 32

Project: django-compositepks
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=False))

Example 33

Project: django-compositepks
Source File: __init__.py
View license
    def simple_tag(self,func):
        params, xx, xxx, defaults = getargspec(func)

        class SimpleNode(Node):
            def __init__(self, vars_to_resolve):
                self.vars_to_resolve = map(Variable, vars_to_resolve)

            def render(self, context):
                resolved_vars = [var.resolve(context) for var in self.vars_to_resolve]
                return func(*resolved_vars)

        compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode)
        compile_func.__doc__ = func.__doc__
        self.tag(getattr(func, "_decorated_function", func).__name__, compile_func)
        return func

Example 34

Project: django-sophie
Source File: views.py
View license
def list_entries( request, blog_slug=None, page_num=1 ):
    ''' renders requested page, a list of date-ordred entries '''
    blog = Blog.get_blog(blog_slug)
    pages = LaidbackPaginator(blog.get_entries(), blog.page_length)

    # curry it up to save typing!
    route = curry(route_template, blog_slug=blog.slug)

    context = RequestContext(request, { 
        'blog': blog,
        'page': pages.page(page_num),
        'multiblog': multiblog_enabled,
    })

    context['base_template'] = select_template( route('base') )
    return render_to_response( route('entry_list'), {}, context )

Example 35

Project: django-sophie
Source File: views.py
View license
def show_category(request, blog_slug=None, category_slug=None, page_num=1):
    ''' lists entries under category specified by category_slug '''
    blog = Blog.get_blog(blog_slug)
    category = get_object_or_404(Category, blog=blog, slug=category_slug)
    entries = Entry.live.filter( category=category )
    pages = LaidbackPaginator(entries, blog.page_length)
    route = curry(route_template,extraname=category.slug,blog_slug=blog.slug)
    context = RequestContext(request, {
        'blog': blog,
        'category': category,
        'page': pages.page(page_num),
        'multiblog': multiblog_enabled,
    }) 

    context['base_template'] = select_template( route('base') )
    return render_to_response( route('category_details'), {}, context )

Example 36

Project: django-sophie
Source File: views.py
View license
def show_entry(request, entry_slug, blog_slug=None):
    blog = Blog.get_blog(blog_slug)
    entry = get_object_or_404(Entry, slug=entry_slug)
    route = curry(route_template, extraname=entry.slug, blog_slug=blog.slug)
    context = RequestContext(request, {
        'blog': blog,
        'entry': entry,
        'multiblog': multiblog_enabled,
    })

    context['base_template'] = select_template( route('base') )
    return render_to_response( route('entry_details'), {}, context )

Example 37

Project: django-hstore
Source File: virtual.py
View license
    def contribute_to_class(self, cls, name):
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name,
                    curry(cls._get_FIELD_display, field=self))
        self.attname = name
        self.name = name
        self.model = cls
        # setting column as none will tell django to not consider this a concrete field
        self.column = None
        # Connect myself as the descriptor for this field
        setattr(cls, name, self)
        # add field to class
        if DJANGO_VERSION[:2] >= (1, 8):
            # virtual=True available since django 1.8
            cls._meta.add_field(self, virtual=True)
        else:
            cls._meta.add_field(self)
            # add also into virtual fields in order to support admin
            cls._meta.virtual_fields.append(self)

Example 38

Project: lettuce
Source File: models.py
View license
@step(STEP_PREFIX + r'(?:an? )?([A-Z][a-z0-9_ ]*) should be present ' +
      r'in the database')
def models_exist_generic(step, model):
    """
    And objectives should be present in the database:
    | description      |
    | Make a mess      |
    """

    model = get_model(model)

    try:
        func = _MODEL_EXISTS[model]
    except KeyError:
        func = curry(models_exist, model)

    func(step)

Example 39

Project: lettuce
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        self.set_attributes_from_name(name)
        self.model = cls
        cls._meta.add_field(self)
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name, curry(cls._get_FIELD_display, field=self))

Example 40

Project: lettuce
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=False))

Example 41

Project: lettuce
Source File: __init__.py
View license
    def simple_tag(self,func):
        params, xx, xxx, defaults = getargspec(func)

        class SimpleNode(Node):
            def __init__(self, vars_to_resolve):
                self.vars_to_resolve = map(Variable, vars_to_resolve)

            def render(self, context):
                resolved_vars = [var.resolve(context) for var in self.vars_to_resolve]
                return func(*resolved_vars)

        compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode)
        compile_func.__doc__ = func.__doc__
        self.tag(getattr(func, "_decorated_function", func).__name__, compile_func)
        return func

Example 42

Project: golismero
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        self.set_attributes_from_name(name)
        self.model = cls
        cls._meta.add_field(self)
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name,
                    curry(cls._get_FIELD_display, field=self))

Example 43

Project: golismero
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self,
                      is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self,
                      is_next=False))

Example 44

Project: django-field-history
Source File: tracker.py
View license
    def contribute_to_class(self, cls, name):
        setattr(cls, '_get_field_history', _get_field_history)
        for field in self.fields:
            setattr(cls, 'get_%s_history' % field,
                    curry(cls._get_field_history, field=field))
        self.name = name
        self.attname = '_%s' % name
        models.signals.class_prepared.connect(self.finalize_class, sender=cls)

Example 45

Project: feedsanitizer
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        self.set_attributes_from_name(name)
        self.model = cls
        cls._meta.add_field(self)
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name, curry(cls._get_FIELD_display, field=self))

Example 46

Project: feedsanitizer
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=False))

Example 47

Project: hortonworks-sandbox
Source File: views.py
View license
@require_http_methods(["POST"])
def chmod(request):
    recurring = ["sticky", "user_read", "user_write", "user_execute", "group_read", "group_write", "group_execute", "other_read", "other_write", "other_execute"]
    params = ["path"]
    def bulk_chmod(*args, **kwargs):
        op = curry(request.fs.chmod, recursive=request.POST.get('recursive', False))
        for arg in args:
            op(arg['path'], arg['mode'])
    # mode here is abused: on input, it's a string, but when retrieved,
    # it's an int.
    return generic_op(ChmodFormSet, request, bulk_chmod, ['path', 'mode'], "path",
                      data_extractor=formset_data_extractor(recurring, params),
                      arg_extractor=formset_arg_extractor,
                      initial_value_extractor=formset_initial_value_extractor)

Example 48

Project: hortonworks-sandbox
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        self.set_attributes_from_name(name)
        self.model = cls
        cls._meta.add_field(self)
        if self.choices:
            setattr(cls, 'get_%s_display' % self.name, curry(cls._get_FIELD_display, field=self))

Example 49

Project: hortonworks-sandbox
Source File: __init__.py
View license
    def contribute_to_class(self, cls, name):
        super(DateField,self).contribute_to_class(cls, name)
        if not self.null:
            setattr(cls, 'get_next_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=True))
            setattr(cls, 'get_previous_by_%s' % self.name,
                curry(cls._get_next_or_previous_by_FIELD, field=self, is_next=False))

Example 50

Project: hortonworks-sandbox
Source File: __init__.py
View license
    def simple_tag(self,func):
        params, xx, xxx, defaults = getargspec(func)

        class SimpleNode(Node):
            def __init__(self, vars_to_resolve):
                self.vars_to_resolve = map(Variable, vars_to_resolve)

            def render(self, context):
                resolved_vars = [var.resolve(context) for var in self.vars_to_resolve]
                return func(*resolved_vars)

        compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, SimpleNode)
        compile_func.__doc__ = func.__doc__
        self.tag(getattr(func, "_decorated_function", func).__name__, compile_func)
        return func