This package provides utilities that are commonly needed in ARC Django projects. It supports Python 3.3+ and Django 1.8+.
To work on this package, run make init
. This will create a virtualenv for you, install the
package in editable mode, and run the tests. Take a look at the Makefile to see the actual commands
that are run.
Run make test
.
The following assumes your package has a setup.py that uses setuptools' setup()
and that you are
using pip. You will need to specify --find-links http://pypi.research.pdx.edu/dist/
when running
pip install
(it's easiest to add --find-links ...
to the top of the project's
requirements.txt).
To use this package in a Django project, do the following:
- Add
'django-arcutils'
toinstall_requires
in setup.py - To use the LDAP features, add
'django-arcutils[ldap]'
toinstall_requires
- To use template tags, add
'arcutils'
toINSTALLED_APPS
NOTE: Many features have not been documented yet :( To get an idea of all the available features,
take a look at the modules and packages in the top level arcutils
directory.
Some ARCUtils functionality can be accessed via the arcutils
console script (or via
python -m arcutils
). Currently, there is one subcommand for running LDAP queries:
arcutils ldap '(uid=pants)'
CAS is used when a project needs to log users in with their PSU accounts. The basic setup is straightforward:
- Add
"arcutils.cas.backends.CASModelBackend"
to the project'sAUTHENTICATION_BACKENDS
(in most cases, this will be the only value inAUTHENTICATION_BACKENDS
) - Include CAS URLs in the project's root URLconf:
url(r'^account/', include(arcutils.cas.urls))
By default, the first time a user logs in, a User
record (with an unusable password) will be
created in the project's database.
-
ChoiceEnum
class FooType(ChoiceEnum): A = 1 B = 2 class SomeModel(models.Model): foo = models.ChoiceField(choices=FooType.as_choices())
-
will_be_deleted_with(obj)
returns 2-tuples of(model class of objects in set, set of objects that will be deleted along with obj)
. This can be used in delete views to list the objects that will be deleted in a cascading manner. -
arcutils.db.dictfetchall
: pass a cursor and get the rows back as a dict
-
arcutils.forms.BaseFormSet
andarcutils.forms.BaseModelFormSet
have aniter_with_empty_form_first()
method that is is basically([formset.empty_form] + formset.forms)
. This makes it convenient to iterate over the empty form in templates without having a special case for it. -
arcutils.forms.BaseFormSet
andarcutils.forms.BaseModelFormSet
override theclean
method so that if a form is being deleted, its validation errors are blanked out.
To use the LDAP features, you will need at least a minimal set of LDAP settings:
LDAP = {
'default': {
'host': 'ldap://ldap-bulk.oit.pdx.edu',
'search_base': 'ou=people,dc=pdx,dc=edu',
}
}
-
arcutils.ldap.ldapsearch(query, using='default', **kwargs)
performs an LDAP search using the LDAP connection specified by the using parameter. By default, each LDAP result is parsed into a "profile", which is just a dict with user info pulled from the LDAP attributes:results = ldapsearch('(uid=mdj2)') print(results[0]) # -> {'first_name': 'Matt', 'last_name': 'Johnson', ...}
TODO: Write this section.
Implements a simple daily task runner as an alternative to cron or Celery.