def path(self, department_id): from uber.models.department import Department department_id = Department.to_id(department_id) for arg in ('department_id', 'department', 'location'): try: return self._path.format(slug=self.slug, **{arg: department_id}) except KeyError: pass raise KeyError('department_id')
def _adapter(*args, **kwargs): argvalues = inspect.getargvalues(inspect.currentframe()) has_kwarg = False department_id = None for arg in possible_args: if arg in kwargs: has_kwarg = True department_id = kwargs[arg] del kwargs[arg] if has_kwarg: from uber.models.department import Department department_id = Department.to_id(department_id) return func(*args, department_id=department_id, **kwargs) elif arg_index < len(args): from uber.models.department import Department args = list(args) args[arg_index] = Department.to_id(args[arg_index]) return func(*args, **kwargs) return func(*args, **kwargs)
def _guess_dept(session, id_name): from uber.models import Department from sqlalchemy import or_ id, name = id_name dept = session.query(Department).filter(or_( Department.id == id, Department.normalized_name == Department.normalize_name(name))).first() if dept: return (id, dept) return None