Commits

Puria Nafisi Azizi  committed 4a67920

First import

  • Participants

Comments (0)

Files changed (21)

+.pyc
+.swp
+^build
+^dist
+.egg-info
+.idea
+.DS_Store
+~$
+recursive-include tgpolls/public *
+recursive-include tgpolls/templates *.html
+global-exclude *.pyc
+
+About tgpolls
+-------------------------
+
+tgpolls is a Pluggable application for TurboGears2 that allows you to create polls and let registered and anonymous users to vote a question created by manager users.
+The polls are both single choice or multiple choice! And have a termination time!
+
+Installing
+-------------------------------
+
+tgpolls can be installed both from pypi or from bitbucket::
+
+    easy_install tgpolls
+
+should just work for most of the users
+
+Plugging tgpolls
+----------------------------
+
+In your application *config/app_cfg.py* import **plug**::
+
+    from tgext.pluggable import plug
+
+Then at the *end of the file* call plug with tgpolls::
+
+    plug(base_config, 'tgpolls')
+
+You will be able to access the registration process at
+*http://localhost:8080/tgpolls*.
+
+Available Hooks
+----------------------
+
+tgpolls makes available a some hooks which will be
+called during some actions to alter the default
+behavior of the appplications:
+
+Exposed Partials
+----------------------
+
+tgpolls exposes a bunch of partials which can be used
+to render pieces of the blogging system anywhere in your
+application:
+
+Exposed Templates
+--------------------
+
+The templates used by registration and that can be replaced with
+*tgext.pluggable.replace_template* are:
+
+# -*- coding: utf-8 -*-
+import sys, os
+
+try:
+    from setuptools import setup, find_packages
+except ImportError:
+    from ez_setup import use_setuptools
+    use_setuptools()
+    from setuptools import setup, find_packages
+
+install_requires=[
+    "TurboGears2 >= 2.1.4",
+    "tgext.pluggable"
+]
+
+here = os.path.abspath(os.path.dirname(__file__))
+try:
+    README = open(os.path.join(here, 'README.rst')).read()
+except IOError:
+    README = ''
+
+setup(
+    name='tgapp-tgpolls',
+    version='0.1',
+    description='',
+    long_description=README,
+    author='Puria Nafisi Azizi',
+    author_email='puria.nafisi@axant.it',
+    #url='',
+    keywords='turbogears2.application',
+    setup_requires=["PasteScript >= 1.7"],
+    paster_plugins=[],
+    packages=find_packages(exclude=['ez_setup']),
+    install_requires=install_requires,
+    include_package_data=True,
+    package_data={'tgapp.tgpolls': ['i18n/*/LC_MESSAGES/*.mo',
+                                 'templates/*/*',
+                                 'public/*/*']},
+    entry_points="""
+    """,
+    dependency_links=[
+        "http://www.turbogears.org/2.1/downloads/current/"
+        ],
+    zip_safe=False
+)

File tgpolls/__init__.py

+# -*- coding: utf-8 -*-
+"""The tgapp-tgpolls package"""
+
+def plugme(app_config, options):
+    return dict(appid='tgpolls', global_helpers=False)

File tgpolls/bootstrap.py

+# -*- coding: utf-8 -*-
+"""Setup the tgpolls application"""
+
+from tgpolls import model
+from tgext.pluggable import app_model
+
+def bootstrap(command, conf, vars):
+    pass
+

File tgpolls/controllers/__init__.py

+# -*- coding: utf-8 -*-
+"""Controllers for the tgapp-tgpolls pluggable application."""
+
+from root import RootController

File tgpolls/controllers/root.py

+# -*- coding: utf-8 -*-
+"""Main Controller"""
+
+from tg import TGController
+from tg import expose, flash, require, url, lurl, request, redirect, validate
+from tg.i18n import ugettext as _, lazy_ugettext as l_
+from tgext.datahelpers.validators import SQLAEntityConverter, validated_handler
+from tgext.pluggable import plug_redirect
+
+
+from tgpolls import model
+from tgpolls.model import DBSession
+from tgpolls.lib.forms import new_poll_form
+
+class RootController(TGController):
+    @expose('tgpolls.templates.index')
+    def index(self):
+        return dict()
+
+    @expose('tgpolls.templates.poll.new')
+    def new(self, **kw):
+        return dict(form=new_poll_form)
+
+    @expose()
+    @validate(new_poll_form,
+              error_handler=validated_handler(new))
+    def save(self, **kw):
+
+        new_poll = model.Poll(body=kw['body'], expiry=kw['expire'])
+        model.DBSession.add(new_poll)
+        model.DBSession.flush()
+
+        for answer in kw['answers'].split('|'):
+            new_answer = model.PollAnswer(text=answer, poll_id=new_poll.uid)
+            model.DBSession.add(new_answer)
+
+        model.DBSession.flush()
+
+        flash(_('Poll successfully added'))
+        return plug_redirect('tgpolls', '/new')
+

File tgpolls/helpers.py

+# -*- coding: utf-8 -*-
+
+"""WebHelpers used in tgapp-tgpolls."""
+
+from webhelpers import date, feedgenerator, html, number, misc, text
+
+def bold(text):
+    return html.literal('<strong>%s</strong>' % text)
+
+def radio_answer(name, value, text):
+    return html.literal('<input name="radio_answer_%s" type="radio" value="%s">%s</input>' % (name, value, text))

File tgpolls/lib/__init__.py

+# -*- coding: utf-8 -*-
+

File tgpolls/lib/forms.py

+from tw.api import WidgetsList
+from tw.forms import TableForm, TextField, HiddenField, TextArea, SingleSelectField
+from tw.forms import validators
+from tw.forms.calendars import CalendarDateTimePicker
+from tgext.datahelpers.validators import SQLAEntityConverter
+from tg import config
+from tg.i18n import lazy_ugettext as l_
+from calendarevents import model
+
+import tw2.core
+import tw2.forms
+
+class NewPollForm(tw2.forms.FormPage):
+    title = l_("Poll")
+
+    class child(tw2.forms.TableForm):
+        action = '/tgpolls/save'
+        body = tw2.forms.TextField(validator=tw2.core.Required)
+        expire = tw2.forms.CalendarDateTimePicker(label_text=l_('Expiry date'), date_format='%d/%m/%Y %H:%M',
+                                                  validator=tw2.core.DateTimeValidator(required=True, format='%d/%m/%Y %H:%M')
+                                                  )
+        answers = tw2.forms.TextArea(label_text=l_('Answers separated by | (eg: First answer|Second answer)'), validator=tw2.core.Required)
+
+new_poll_form = NewPollForm()

File tgpolls/model/__init__.py

+# -*- coding: utf-8 -*-
+from sqlalchemy.ext.declarative import declarative_base
+from tgext.pluggable import PluggableSession
+
+DBSession = PluggableSession()
+DeclarativeBase = declarative_base()
+
+def init_model(app_session):
+    DBSession.configure(app_session)
+
+from models import Poll, PollAnswer
+

File tgpolls/model/models.py

+from sqlalchemy import Table, ForeignKey, Column
+from sqlalchemy.types import Unicode, Integer, DateTime
+from sqlalchemy.orm import backref, relation
+
+from tgpolls.model import DeclarativeBase
+from tgext.pluggable import app_model, primary_key
+
+class Poll(DeclarativeBase):
+    __tablename__ = 'tgpolls_polls'
+
+    uid = Column(Integer, autoincrement=True, primary_key=True)
+    body = Column(Unicode(2048))
+    expiry = Column(DateTime)
+
+class PollAnswer(DeclarativeBase):
+    __tablename__ = 'tgpolls_poll_answers'
+
+    uid = Column(Integer, autoincrement=True, primary_key=True)
+    text = Column(Unicode(255))
+
+    poll_id = Column(Integer, ForeignKey(primary_key(Poll)), nullable=True, index=True)
+    poll = relation(Poll, backref=backref('answers'), lazy='joined')
+

File tgpolls/partials.py

+from tg import expose
+
+@expose('tgpolls.templates.little_partial')
+def something(name):
+    return dict(name=name)

File tgpolls/public/__init__.py

+# -*- coding: utf-8 -*-
+"""Enable statics for the tgapp-tgpolls package"""

File tgpolls/public/css/style.css

+#hello_box {
+    font-style: italic;
+    color: red;
+}

File tgpolls/templates/__init__.py

+# -*- coding: utf-8 -*-
+"""Templates package for the application."""

File tgpolls/templates/index.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude">
+
+  <xi:include href="master.html" />
+
+<head>
+  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" py:if="False"/>
+  <title>Welcome to TurboGears pluggable Application</title>
+  <link rel="stylesheet" type="text/css" media="screen" href="${tg.url('/_pluggable/tgpolls/css/style.css')}" />
+</head>
+
+<body>
+    <div py:if="request.identity">Hi ${request.identity['user']}</div>
+    <div id="hello_box">
+        <img src="${tg.url('/_pluggable/tgpolls/images/star.png')}"/>
+    </div>
+    <div>${h.call_partial('tgpolls.partials:something', name='Partial')}</div>
+</body>
+</html>

File tgpolls/templates/little_partial.html

+<div xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude">
+    <div>This is from partial: ${h.tgpolls.bold(name)}</div>
+</div>

File tgpolls/templates/poll/__init__.py

+__author__ = 'amol'

File tgpolls/templates/poll/new.html

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude">
+
+<xi:include href="master.html" />
+
+<head>
+    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" py:if="False"/>
+    <title>Create new poll</title>
+    <link rel="stylesheet" type="text/css" media="screen" href="${tg.url('/_pluggable/tgpolls/css/style.css')}" />
+</head>
+
+<body>
+    <h2 class="tgpolls_head">Create a new poll!</h2>
+    <div class="tgpolls_form">
+        ${form.display()}
+    </div>
+</body>
+</html>