Skip to content

Commit

Permalink
Merge pull request #28 from pstch/develop
Browse files Browse the repository at this point in the history
Switch from try_calling to call_if (semantics changed)
  • Loading branch information
Hugo Geoffroy committed May 6, 2014
2 parents 10972f6 + 826309d commit 841a847
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ pycallgraph.gdf
pycallgraph.png

docs/_*
/.project
/.pydevproject
8 changes: 7 additions & 1 deletion django_crucrudile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
"""

__title__ = 'django-crucrudile'
__version__ = '0.4.6'
__description__ = 'Model-defined CRUD views & patterns for Django',

__version__ = '0.4.7'

__author__ = 'Hugo Geoffroy'
__author_email__ = 'hugo@pstch.net'

__license__ = 'GNU General Public License V3.0'
__copyright__ = 'Copyright 2013-2014 Hugo Geoffroy'
__url__ = 'https://github.com/pstch/django-crucrudile'
6 changes: 3 additions & 3 deletions django_crucrudile/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.core.urlresolvers import reverse
from django.conf.urls import url

from django_crucrudile.utils import try_calling, monkeypatch_mixin
from django_crucrudile.utils import call_if, monkeypatch_mixin
from django_crucrudile.views.mixins import ModelActionMixin


Expand Down Expand Up @@ -83,7 +83,7 @@ def get_args_by_view(cls, view):
args = super(ModelMixin, cls).get_args_by_view(view)
if view is view_class and extra_args is not None:
args.update({
arg_key: try_calling(arg_value, cls) or arg_value
arg_key: call_if(arg_value, cls)
for (arg_key, arg_value) in extra_args.items()
})
return args
Expand Down Expand Up @@ -134,7 +134,7 @@ def _get_url_name(cls):

if extra_funcs:
for func_name, func in extra_funcs.items():
func_name = try_calling(func_name, view_class) or func_name
func_name = call_if(func_name, view_class)
setattr(ModelMixin,
func_name,
func)
Expand Down
14 changes: 6 additions & 8 deletions django_crucrudile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
``django-crucrudile`` modules. They are pretty simple, which is why
they're just tossed in here, and not in their own modules.`
This module is imported by ``views.mixins`` (for :func:`try_calling`
and :func:`monkeypatch_mixin`)and ``models.mixins`` (for
:func:`convert_camel_case`). Should it become any longer, it may be
wise to split it.
----------------
"""
import re


def try_calling(arg, *args, **kwargs):
def call_if(arg, *args, **kwargs):
"""Evaluate and return arg (with given args and kwargs) if it's a
callable, otherwise return None
callable, otherwise return arg.
"""
return arg(*args, **kwargs) if callable(arg) else None
try:
return arg(*args, **kwargs)
except TypeError:
return arg


def convert_camel_case(camel_cased, separator):
Expand Down
32 changes: 19 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,36 @@

import django_crucrudile

CLASSIFIERS = [
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Operating System :: OS Independent',
'Topic :: Software Development',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
]

setup(
name='django-crucrudile',
name=django_crucrudile.__title__,
version=django_crucrudile.__version__,

description='Model-defined CRUD views & patterns for Django',
long_description="views, models, auto URL patterns, ...",

url='https://github.com/pstch/django-crucrudile',
url=django_crucrudile.__url__,

author=django_crucrudile.__author__,
author_email=django_crucrudile.__author_email__,

author='Hugo Geoffroy',
author_email='hugo@pstch.net',
license=django_crucrudile.__license__,

packages=find_packages(exclude=['tests']),

install_requires=[
'Django == 1.6'
],

classifiers=[
'Intended Audience :: Developers',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
'Framework :: Django',
],
platforms=['any'],
classifiers=CLASSIFIERS,

test_suite='runtests.runtests',
)

0 comments on commit 841a847

Please sign in to comment.