Skip to content

Commit

Permalink
global: addition of functions registry
Browse files Browse the repository at this point in the history
* FIX Removes dependency on JSONAlchemy from Invenio package.

Signed-off-by: Jiri Kuncar <[email protected]>
  • Loading branch information
jirikuncar committed Sep 13, 2015
1 parent 050accb commit 6868cbc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
3 changes: 1 addition & 2 deletions invenio_records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from invenio.utils.datastructures import SmartDict

from .models import RecordMetadata
from .registry import functions
from .signals import (after_record_insert, after_record_update,
before_record_insert, before_record_update)

Expand Down Expand Up @@ -72,7 +73,6 @@ def create(cls, data, schema=None):
try:
record = cls(unicodifier(data))

from invenio.modules.jsonalchemy.registry import functions
list(functions('recordext'))

toposort_send(before_record_insert, record)
Expand Down Expand Up @@ -103,7 +103,6 @@ def patch(self, patch):
def commit(self):
db.session.begin(subtransactions=True)
try:
from invenio.modules.jsonalchemy.registry import functions
list(functions('recordext'))

toposort_send(before_record_update, self)
Expand Down
50 changes: 50 additions & 0 deletions invenio_records/registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2013, 2014, 2015 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""Define registries for extending *Record* class."""

from flask_registry import PkgResourcesDirDiscoveryRegistry, \
ModuleAutoDiscoveryRegistry, RegistryProxy

from invenio.ext.registry import ModuleAutoDiscoverySubRegistry
from invenio.utils.datastructures import LazyDict


def jsonext(namespace):
return RegistryProxy(namespace, ModuleAutoDiscoveryRegistry, namespace)


def function_proxy(namespace):
return RegistryProxy(
namespace + '.functions',
ModuleAutoDiscoverySubRegistry,
'functions',
registry_namespace=jsonext(namespace)
)


def functions(namespace=None):
funcs = dict((module.__name__.split('.')[-1],
getattr(module, module.__name__.split('.')[-1]))
for module in function_proxy('jsonext'))
if namespace is not None:
funcs.update((module.__name__.split('.')[-1],
getattr(module, module.__name__.split('.')[-1]))
for module in function_proxy(namespace))
return funcs

0 comments on commit 6868cbc

Please sign in to comment.