Commits

cur...@tinbrain.net  committed 493d6fc

Renamed tools to fix namespaces

  • Participants
  • Parent commits 6caf9c9

Comments (0)

Files changed (13)

File gnocchi_tools/__init__.py

+
+from gnocchi_tools import template

File gnocchi_tools/admin.py

+from django.contrib.contenttypes import generic
+from gnocchi_tools import models
+from django.http import HttpResponse
+import csv
+
+class InlineAttributeAdmin( generic.GenericTabularInline ):
+    model = models.Attribute
+    ct_field = 'content_type'
+    ct_fk_field = 'object_id'
+
+##
+## Model "export to CSV" tool
+##
+from django.core.serializers.python import Serializer
+
+class CsvSerializer(Serializer):
+    def start_serialization(self):
+        self.csv = csv.DictWriter(self.stream, fieldnames=self.selected_fields)
+        if self.options.get('headers', True):
+            self.csv.writerow(dict((x,x) for x in self.selected_fields))
+        self._current = None
+
+    def end_object(self, obj):
+        self._current[obj._meta.pk.name] = obj.pk
+        self.csv.writerow(self._current)
+        self._current = None
+
+    def getvalue(self):
+        return self.stream
+
+def export_as_csv(admin, request, queryset):
+    fields = getattr(admin, 'csv_fields', None)
+    filename = getattr(admin, 'csv_filename', '%s_export.csv' % admin.model._meta.module_name)
+    response = HttpResponse(mimetype='text/csv')
+    response['Content-Disposition'] = 'attachment; filename=%s' % filename
+    if fields is None:
+        fields = [field.name for field in admin.model._meta.local_fields]
+    xout = CsvSerializer()
+    return xout.serialize(queryset, fields=fields, stream=response)
+
+export_as_csv.short_description = 'Export as CSV'

File gnocchi_tools/attr.py

+
+class AttrHelper(object):
+    '''Help mixin to make accessing Attributes easier'''
+    def _load_cache(self, force=False):
+        '''Load all the dict values for this object'''
+        if not hasattr(self, '_attributes') or force:
+            self._attributes = dict(
+                self.attributes.values_list('name', 'value')
+            )
+
+    def __getitem__( self, key ):
+        self._load_cache()
+        return self._attributes[key]
+
+    def __setitem__( self, key, value ):
+        try:
+            attr = self.attributes.get(name=key)
+        except Attribute.DoesNotExist:
+            attr = Attribute( name=key, content_object=self )
+        attr.value = value
+        attr.save()
+        # We reload the cache, instead of a direct update, in case of overrides
+        self._load_cache(True)
+
+

File gnocchi_tools/models.py

+
+from django.db import models
+from django.contrib.contenttypes import generic
+from django.utils.translation import ugettext_lazy as _
+
+class Attribute( models.Model ):
+    '''Generic Attribute'''
+    name = models.SlugField(verbose_name=_('Name'))
+    value = models.CharField(max_length=1024, verbose_name=_('Value'))
+    content_type = models.ForeignKey('contenttypes.ContentType')
+    object_id = models.PositiveIntegerField()
+    content_object = generic.GenericForeignKey('content_type', 'object_id')
+    class Meta:
+        ordering = ('name',)
+        verbose_name = _('Attribute')
+        verbose_name_plural = _('Attributes')
+    def __unicode__(self):
+        return u'%s=%s' % (self.name, self.value,)
+

File gnocchi_tools/template.py

+
+def parse_args(parser, token, as_name=False):
+    '''Parse token args, returning a list of args, and dict of keyword args
+
+    If as_name is passed, the last two args of the tag may be "as {name}"
+    If so, as_name will be set to the name.
+    '''
+    parts = token.split_contents()
+    parts.pop(0)
+    #
+    if as_name:
+        if len(parts) > 2 and parts[-2] == 'as':
+            as_name = parts[-1]
+            parts = parts[:-2]
+    # Parse the args
+    args = []
+    kwargs = {}
+    for arg in parts:
+        if '=' in arg:
+            key, val = arg.split('=', 1)
+            kwargs[key.strip().encode('utf8')] = parser.compile_filter(val)
+        else:
+            args.append(parser.compile_filter(arg))
+    return args, kwargs, as_name

File gnocchi_tools/utils.py

+
+from django.utils.importlib import import_module
+def autodiscover_factory(module, include_project=False):
+    def autodiscover():
+        """
+        Auto-discover INSTALLED_APPS modules and fail silently when
+        not present.
+        """
+        import imp
+        from django.conf import settings
+
+        def import_app(app):
+            # For each app, we need to look for an module with the module inside
+            # that app's package. We can't use os.path here -- recall that
+            # modules may be imported different ways (think zip files) -- so we
+            # need to get the app's __path__ and look for admin.py on that path.
+
+            # Step 1: find out the app's __path__ Import errors here will (and
+            # should) bubble up, but a missing __path__ (which is legal, but
+            # weird) fails silently -- apps that do weird things with __path__
+            # might need to manually ensure that the files are being imported.
+
+            try:
+                app_path = import_module(app).__path__
+            except AttributeError:
+                return
+
+            # Step 2: use imp.find_module to find the app's pages_templates.py.
+            # For some reason imp.find_module raises ImportError if the app
+            # can't be found but doesn't actually try to import the module. So
+            # skip this app if its pages_templates.py doesn't exist
+            try:
+                imp.find_module(module, app_path)
+            except ImportError:
+                return
+
+            # Step 3: import the app's pages file. If this has errors we want
+            # them to bubble up.
+            import_module("%s.%s" % (app, module))
+
+        for app in settings.INSTALLED_APPS:
+            import_app(app)
+
+        if include_project:
+            # Look for a project-specific modules.
+            import_app(settings.PROJECT_NAME)
+
+    return autodiscover
     url = 'http://bitbucket.org/funkybob/gnocchi-tools/',
     keywords = ['django', 'gnocchi',],
     packages = find_packages(),
-    package_dir = {
-        'gnocchi_tools': 'tools',
-    },
     zip_safe = False,
     classifiers = [
         'Environment :: Web Environment',

File tools/__init__.py

-
-from gnocchi_tools import template

File tools/admin.py

-from django.contrib.contenttypes import generic
-from gnocchi_tools import models
-from django.http import HttpResponse
-import csv
-
-class InlineAttributeAdmin( generic.GenericTabularInline ):
-    model = models.Attribute
-    ct_field = 'content_type'
-    ct_fk_field = 'object_id'
-
-##
-## Model "export to CSV" tool
-##
-from django.core.serializers.python import Serializer
-
-class CsvSerializer(Serializer):
-    def start_serialization(self):
-        self.csv = csv.DictWriter(self.stream, fieldnames=self.selected_fields)
-        if self.options.get('headers', True):
-            self.csv.writerow(dict((x,x) for x in self.selected_fields))
-        self._current = None
-
-    def end_object(self, obj):
-        self._current[obj._meta.pk.name] = obj.pk
-        self.csv.writerow(self._current)
-        self._current = None
-
-    def getvalue(self):
-        return self.stream
-
-def export_as_csv(admin, request, queryset):
-    fields = getattr(admin, 'csv_fields', None)
-    filename = getattr(admin, 'csv_filename', '%s_export.csv' % admin.model._meta.module_name)
-    response = HttpResponse(mimetype='text/csv')
-    response['Content-Disposition'] = 'attachment; filename=%s' % filename
-    if fields is None:
-        fields = [field.name for field in admin.model._meta.local_fields]
-    xout = CsvSerializer()
-    return xout.serialize(queryset, fields=fields, stream=response)
-
-export_as_csv.short_description = 'Export as CSV'

File tools/attr.py

-
-class AttrHelper(object):
-    '''Help mixin to make accessing Attributes easier'''
-    def _load_cache(self, force=False):
-        '''Load all the dict values for this object'''
-        if not hasattr(self, '_attributes') or force:
-            self._attributes = dict(
-                self.attributes.values_list('name', 'value')
-            )
-
-    def __getitem__( self, key ):
-        self._load_cache()
-        return self._attributes[key]
-
-    def __setitem__( self, key, value ):
-        try:
-            attr = self.attributes.get(name=key)
-        except Attribute.DoesNotExist:
-            attr = Attribute( name=key, content_object=self )
-        attr.value = value
-        attr.save()
-        # We reload the cache, instead of a direct update, in case of overrides
-        self._load_cache(True)
-
-

File tools/models.py

-
-from django.db import models
-from django.contrib.contenttypes import generic
-from django.utils.translation import ugettext_lazy as _
-
-class Attribute( models.Model ):
-    '''Generic Attribute'''
-    name = models.SlugField(verbose_name=_('Name'))
-    value = models.CharField(max_length=1024, verbose_name=_('Value'))
-    content_type = models.ForeignKey('contenttypes.ContentType')
-    object_id = models.PositiveIntegerField()
-    content_object = generic.GenericForeignKey('content_type', 'object_id')
-    class Meta:
-        ordering = ('name',)
-        verbose_name = _('Attribute')
-        verbose_name_plural = _('Attributes')
-    def __unicode__(self):
-        return u'%s=%s' % (self.name, self.value,)
-

File tools/template.py

-
-def parse_args(parser, token, as_name=False):
-    '''Parse token args, returning a list of args, and dict of keyword args
-
-    If as_name is passed, the last two args of the tag may be "as {name}"
-    If so, as_name will be set to the name.
-    '''
-    parts = token.split_contents()
-    parts.pop(0)
-    #
-    if as_name:
-        if len(parts) > 2 and parts[-2] == 'as':
-            as_name = parts[-1]
-            parts = parts[:-2]
-    # Parse the args
-    args = []
-    kwargs = {}
-    for arg in parts:
-        if '=' in arg:
-            key, val = arg.split('=', 1)
-            kwargs[key.strip().encode('utf8')] = parser.compile_filter(val)
-        else:
-            args.append(parser.compile_filter(arg))
-    return args, kwargs, as_name

File tools/utils.py

-
-from django.utils.importlib import import_module
-def autodiscover_factory(module, include_project=False):
-    def autodiscover():
-        """
-        Auto-discover INSTALLED_APPS modules and fail silently when
-        not present.
-        """
-        import imp
-        from django.conf import settings
-
-        def import_app(app):
-            # For each app, we need to look for an module with the module inside
-            # that app's package. We can't use os.path here -- recall that
-            # modules may be imported different ways (think zip files) -- so we
-            # need to get the app's __path__ and look for admin.py on that path.
-
-            # Step 1: find out the app's __path__ Import errors here will (and
-            # should) bubble up, but a missing __path__ (which is legal, but
-            # weird) fails silently -- apps that do weird things with __path__
-            # might need to manually ensure that the files are being imported.
-
-            try:
-                app_path = import_module(app).__path__
-            except AttributeError:
-                return
-
-            # Step 2: use imp.find_module to find the app's pages_templates.py.
-            # For some reason imp.find_module raises ImportError if the app
-            # can't be found but doesn't actually try to import the module. So
-            # skip this app if its pages_templates.py doesn't exist
-            try:
-                imp.find_module(module, app_path)
-            except ImportError:
-                return
-
-            # Step 3: import the app's pages file. If this has errors we want
-            # them to bubble up.
-            import_module("%s.%s" % (app, module))
-
-        for app in settings.INSTALLED_APPS:
-            import_app(app)
-
-        if include_project:
-            # Look for a project-specific modules.
-            import_app(settings.PROJECT_NAME)
-
-    return autodiscover