Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 2b45a13754da3298372a2695b59c553f25e8bef0 @paltman paltman committed
27 LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2011, Eldarion, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name of Eldarion, Inc. nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 MANIFEST.in
@@ -0,0 +1,2 @@
+include README.rst
+recursive-include kaleo/templates *.html
5 README.rst
@@ -0,0 +1,5 @@
+==========
+cobranding
+==========
+
+
1 cobranding/__init__.py
@@ -0,0 +1 @@
+__version__ = "0.1.dev1"
24 cobranding/brands.py
@@ -0,0 +1,24 @@
+class Registry(object):
+
+ def __init__(self):
+ self._brands = {}
+
+ def register(self, domain, app_model, expression):
+ # @@@ Validation: what if it is already registered?
+ # @@@ Validation: what if app_model is invalid for INSTALLED_APPS
+ # @@@ Validation: what if expression is not a valid Q expression
+ if domain not in self._brands:
+ self._brands[domain] = {}
+ if not isinstance(app_model, basestring):
+ app_model = "%s.%s" % (app_model._meta.app_label, app_model._meta.object_name)
+ self._brands[domain][app_model] = expression
+
+ def expression_for(self, domain, app_model):
+ return self._brands.get(domain, {}).get(app_model)
+
+
+registry = Registry()
+
+
+def register(domain, app_model, expression):
+ registry.register(domain, app_model, expression)
0 cobranding/models.py
No changes.
0 cobranding/templatetags/__init__.py
No changes.
47 cobranding/templatetags/cobranding_tags.py
@@ -0,0 +1,47 @@
+from django import template
+
+from cobranding.brands import registry
+
+
+register = template.Library()
+
+
+class CobrandFilterNode(template.Node):
+
+ @classmethod
+ def handle_token(cls, parser, token):
+ bits = token.split_contents()
+ if len(bits) != 4:
+ raise template.TemplateSyntaxError("Invalid number of arguments.")
+ if bits[2] != "using":
+ raise template.TemplateSyntaxError("Invalid arguments.")
+ return cls(
+ queryset = bits[1],
+ hostname = bits[3]
+ )
+
+ def __init__(self, queryset, hostname):
+ self.queryset = template.Variable(queryset)
+ self.hostname = template.Variable(hostname)
+
+ def render(self, context):
+ var_name = self.queryset.var
+ queryset = self.queryset.resolve(context)
+ hostname = self.hostname.resolve(context)
+ app_model = "%s.%s" % (queryset.model._meta.app_label, queryset.model._meta.object_name)
+ expression = registry.expression_for(hostname, app_model)
+ if expression:
+ context[var_name] = queryset.filter(expression)
+ return ""
+
+
+@register.tag
+def cobrand_filter(parser, token):
+ """
+ Usage::
+ {% cobrand_filter queryset using request.get_host %}
+
+ Filters the queryset by the given hostname using rules defined in
+ cobranding.brands.registry
+ """
+ return CobrandFilterNode.handle_token(parser, token)
137 setup.py
@@ -0,0 +1,137 @@
+import codecs
+import os
+import sys
+
+from distutils.util import convert_path
+from fnmatch import fnmatchcase
+from setuptools import setup, find_packages
+
+
+def read(fname):
+ return codecs.open(os.path.join(os.path.dirname(__file__), fname)).read()
+
+
+# Provided as an attribute, so you can append to these instead
+# of replicating them:
+standard_exclude = ["*.py", "*.pyc", "*$py.class", "*~", ".*", "*.bak"]
+standard_exclude_directories = [
+ ".*", "CVS", "_darcs", "./build", "./dist", "EGG-INFO", "*.egg-info"
+]
+
+
+# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
+# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
+# Note: you may want to copy this into your setup.py file verbatim, as
+# you can't import this from another package, when you don't know if
+# that package is installed yet.
+def find_package_data(
+ where=".",
+ package="",
+ exclude=standard_exclude,
+ exclude_directories=standard_exclude_directories,
+ only_in_packages=True,
+ show_ignored=False):
+ """
+ Return a dictionary suitable for use in ``package_data``
+ in a distutils ``setup.py`` file.
+
+ The dictionary looks like::
+
+ {"package": [files]}
+
+ Where ``files`` is a list of all the files in that package that
+ don"t match anything in ``exclude``.
+
+ If ``only_in_packages`` is true, then top-level directories that
+ are not packages won"t be included (but directories under packages
+ will).
+
+ Directories matching any pattern in ``exclude_directories`` will
+ be ignored; by default directories with leading ``.``, ``CVS``,
+ and ``_darcs`` will be ignored.
+
+ If ``show_ignored`` is true, then all the files that aren"t
+ included in package data are shown on stderr (for debugging
+ purposes).
+
+ Note patterns use wildcards, or can be exact paths (including
+ leading ``./``), and all searching is case-insensitive.
+ """
+ out = {}
+ stack = [(convert_path(where), "", package, only_in_packages)]
+ while stack:
+ where, prefix, package, only_in_packages = stack.pop(0)
+ for name in os.listdir(where):
+ fn = os.path.join(where, name)
+ if os.path.isdir(fn):
+ bad_name = False
+ for pattern in exclude_directories:
+ if (fnmatchcase(name, pattern)
+ or fn.lower() == pattern.lower()):
+ bad_name = True
+ if show_ignored:
+ print >> sys.stderr, (
+ "Directory %s ignored by pattern %s"
+ % (fn, pattern))
+ break
+ if bad_name:
+ continue
+ if (os.path.isfile(os.path.join(fn, "__init__.py"))
+ and not prefix):
+ if not package:
+ new_package = name
+ else:
+ new_package = package + "." + name
+ stack.append((fn, "", new_package, False))
+ else:
+ stack.append((fn, prefix + name + "/", package, only_in_packages))
+ elif package or not only_in_packages:
+ # is a file
+ bad_name = False
+ for pattern in exclude:
+ if (fnmatchcase(name, pattern)
+ or fn.lower() == pattern.lower()):
+ bad_name = True
+ if show_ignored:
+ print >> sys.stderr, (
+ "File %s ignored by pattern %s"
+ % (fn, pattern))
+ break
+ if bad_name:
+ continue
+ out.setdefault(package, []).append(prefix+name)
+ return out
+
+
+PACKAGE = "cobranding"
+NAME = "cobranding"
+DESCRIPTION = "a app for cobrand filtering"
+AUTHOR = "Eldarion"
+AUTHOR_EMAIL = "paltman@eldarion.com"
+URL = "http://github.com/eldarion/kaleo"
+VERSION = __import__(PACKAGE).__version__
+
+
+setup(
+ name=NAME,
+ version=VERSION,
+ description=DESCRIPTION,
+ long_description=read("README.rst"),
+ author=AUTHOR,
+ author_email=AUTHOR_EMAIL,
+ license="BSD",
+ url=URL,
+ packages=find_packages(exclude=["tests.*", "tests"]),
+ package_data=find_package_data(PACKAGE, only_in_packages=False),
+ classifiers=[
+ "Development Status :: 3 - Alpha",
+ "Environment :: Web Environment",
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: BSD License",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python",
+ "Framework :: Django",
+ ],
+ zip_safe=False
+)
+

0 comments on commit 2b45a13

Please sign in to comment.
Something went wrong with that request. Please try again.