Commits

Kai Diefenbach committed 95a3950

Initial import

Comments (0)

Files changed (7)

+syntax: glob
+*.pyc
+*.pyo
+*.DS_Store 
+*.installed.cfg
+*build/
+*dist/
+*.egg-info/
+Copyright (c) 2011, Kai Diefenbach - iqplusplus
+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 the author nor the names of other 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 HOLDER 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.
+include README.txt
+include LICENSE.txt
+recursive-include lfc_portlets/templates *
+recursive-include lfc_portlets/locale *
+What is it?
+===========
+
+The standard portlets for LFC
+
+Changes
+=======
+
+1.0 (....-..-..)
+------------------------
+
+* Initial public release

lfc_portlets/__init__.py

Empty file added.

lfc_portlets/models.py

+# python imports
+import random
+
+# django imports
+from django import forms
+from django.db import models
+from django.template import RequestContext
+from django.template.loader import render_to_string
+from django.utils import translation
+from django.utils.translation import ugettext_lazy as _
+
+
+# tagging imports
+import tagging.utils
+from tagging.forms import TagField
+
+# portlets imports
+from portlets.models import Portlet
+
+# lfc imports
+from lfc.models import BaseContent
+from lfc.fields.autocomplete import AutoCompleteTagInput
+
+
+class NavigationPortlet(Portlet):
+    """A portlet to display the navigation tree.
+
+    Note: this reuses mainly the navigation inclusion tag.
+
+    Parameters:
+
+        - start_level:
+            The tree is displayed from this level 1. The tree starts with 1
+
+        - expand_level:
+            The tree is expanded up this level. Default is 0, which means the
+            tree is not expanded at all but the current node.
+    """
+    start_level = models.PositiveSmallIntegerField(default=1)
+    expand_level = models.PositiveSmallIntegerField(default=0)
+
+    def render(self, context):
+        """Renders the portlet as HTML.
+        """
+        request = context.get("request")
+        return render_to_string("lfc/portlets/navigation_portlet.html", RequestContext(request, {
+            "start_level": self.start_level,
+            "expand_level": self.expand_level,
+            "title": self.title,
+        }))
+
+    def form(self, **kwargs):
+        """
+        """
+        return NavigationPortletForm(instance=self, **kwargs)
+
+
+class NavigationPortletForm(forms.ModelForm):
+    """Add/edit form for the navigation portlet.
+    """
+    class Meta:
+        model = NavigationPortlet
+
+
+class ContentPortlet(Portlet):
+    """A portlet to display arbitrary content objects. The objects can be
+    selected by tags.
+
+    **Attributes:**
+
+    limit:
+        The amount of objects which are displayed at maximum.
+
+    tags:
+        The tags an object must have to be displayed.
+    """
+    limit = models.PositiveSmallIntegerField(default=5)
+    tags = models.CharField(blank=True, max_length=100)
+
+    def __unicode__(self):
+        return "%s" % self.id
+
+    def render(self, context):
+        """Renders the portlet as HTML.
+        """
+        objs = BaseContent.objects.filter(
+            language__in=("0", translation.get_language()))
+
+        if self.tags:
+            objs = tagging.managers.ModelTaggedItemManager().with_all(self.tags, objs)[:self.limit]
+        else:
+            objs = objs[:self.limit]
+
+        return render_to_string("lfc/portlets/pages_portlet.html", {
+            "title": self.title,
+            "objs": objs,
+        })
+
+    def form(self, **kwargs):
+        """Returns the add/edit form of the portlet.
+        """
+        return ContentPortletForm(instance=self, **kwargs)
+
+
+class ContentPortletForm(forms.ModelForm):
+    """Add/edit form of the content portlet.
+    """
+    tags = TagField(widget=AutoCompleteTagInput(), required=False)
+
+    class Meta:
+        model = ContentPortlet
+
+
+class RandomPortlet(Portlet):
+    """A portlet to display random objects. The objects can be selected by
+    tags.
+
+    **Attributes:**
+
+    limit:
+        The amount of objects which are displayed at maximum.
+
+    tags:
+        The tags an object must have to be displayed.
+    """
+    limit = models.PositiveSmallIntegerField(default=1)
+    tags = models.CharField(blank=True, max_length=100)
+
+    def render(self, context):
+        """Renders the portlet as HTML.
+        """
+        items = BaseContent.objects.filter(
+            language__in=("0", translation.get_language()))
+
+        if self.tags:
+            items = tagging.managers.ModelTaggedItemManager().with_all(self.tags, items)[:self.limit]
+
+        items = list(items)
+        random.shuffle(items)
+
+        return render_to_string("lfc/portlets/random_portlet.html", {
+            "title": self.title,
+            "items": items[:self.limit],
+        })
+
+    def form(self, **kwargs):
+        """Returns the form of the portlet.
+        """
+        return RandomPortletForm(instance=self, **kwargs)
+
+
+class RandomPortletForm(forms.ModelForm):
+    """Add/Edit form for the random portlet.
+    """
+    tags = TagField(widget=AutoCompleteTagInput(), required=False)
+
+    class Meta:
+        model = RandomPortlet
+
+
+class TextPortlet(Portlet):
+    """A portlet to display arbitrary HTML text.
+
+    **Attributes:**
+
+    text:
+        The HTML text which is displayed. Can contain any HTML text.
+    """
+
+    text = models.TextField(_(u"Text"), blank=True)
+
+    def __unicode__(self):
+        return "%s" % self.id
+
+    def render(self, context):
+        """Renders the portlet as HTML.
+        """
+        return render_to_string("lfc/portlets/text_portlet.html", {
+            "title": self.title,
+            "text": self.text
+        })
+
+    def form(self, **kwargs):
+        """
+        """
+        return TextPortletForm(instance=self, **kwargs)
+
+
+class TextPortletForm(forms.ModelForm):
+    """Add/Edit form for the text portlet.
+    """
+    class Meta:
+        model = TextPortlet
+from setuptools import setup, find_packages
+import os
+
+version = '1.0'
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(here, 'README.txt')).read()
+
+setup(name='lfc-portlets',
+      version=version,
+      description='The standard portlets for LFC',
+      long_description=README,
+      classifiers=[
+          'Development Status :: 4 - Beta',
+          'Environment :: Web Environment',
+          'Framework :: Django',
+          'License :: OSI Approved :: BSD License',
+          'Operating System :: OS Independent',
+          'Programming Language :: Python',
+      ],
+      keywords='django lfc portlets',
+      author='Kai Diefenbach',
+      author_email='kai.diefenbach@iqpp.de',
+      url='http://www.iqpp.de',
+      license='BSD',
+      packages=find_packages(exclude=['ez_setup']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+        'setuptools',
+      ],
+      )