Example #1
0
def home_page_handler(request):
    global aux
    request.set_secure_cookie("id", str(aux))  # until we have a login page
    charity = backend_objects.getRandomCharity()
    #charity = backend_objects.Charity("Snail Helpline", "We help snails!!", logoURL = "snail.jpg")
    context = {"charity": charity}
    request.write(templater.render("templates/index.html", context))
    def test_render_list(self):
        template = """
        <ul>
        {{#hits}}
        <li>{{title}}</li>
        {{#hits}}
        </ul>
      """

        data = {}
        data["hits"] = [
            {"title": "aa"},
            {"title": "bb"},
        ]

        data["hits"] = [{'path': '/Users/michael/Downloads/data/notebook/03713370-5c66-4c57-86fd-48ea449aa644',
              'uuid': '03713370-5c66-4c57-86fd-48ea449aa644', 'title': 'asdsad'},
             {'path': '/Users/michael/Downloads/data/notebook/78da9032-9f00-4877-81f9-abe3d9945ef6',
              'uuid': '78da9032-9f00-4877-81f9-abe3d9945ef6', 'title': 'template\r\n'},
             {'path': '/Users/michael/Downloads/data/notebook/99603471-09f1-41e6-8c16-dae75322d276',
              'uuid': '99603471-09f1-41e6-8c16-dae75322d276', 'title': 'asdsa\n'},
             {'path': '/Users/michael/Downloads/data/notebook/e249ad9b-03a3-4cd4-b1d6-9bb18a73fed7',
              'uuid': 'e249ad9b-03a3-4cd4-b1d6-9bb18a73fed7', 'title': '// js templating xcc\r\n'}]
        render_result = templater.render(template, data)

        self.assertEqual("", render_result)
Example #3
0
def applications(req, params):
    def addapp(params):
        name = templater.cleaner.clean(params['name'])
        if name in req.server.applications_name:
            req.error = 'Application %s already begun' % (name)
            return error(req, params)
        appid = cookie_session.new_session_id()
        req.server.applications[appid] = {'name':name, 'appid':appid}
        req.server.applications_name[name] = appid
        if req.user['usr_id'] not in req.server.applications_usrid:
            req.server.applications_usrid[req.user['usr_id']] = list()
        req.server.applications_usrid[req.user['usr_id']].append(appid)
    if req.user:
        if 'name' in params: addapp(params)

        if req.user['usr_id'] not in req.server.applications_usrid:
            applications = list()
        else:
            applications = [req.server.applications[appid]
                   for appid in req.server.applications_usrid[req.user['usr_id']]]
        user_id = req.user['usr_id']
        session_id = req.session['session_id']
        page = templater.render('templates/applications.html', locals())
        return 'text/html', page, None
    else:
        return login(req, params)
    def test_render_two_itemlists_multiline(self):
        data = {}
        data["colors"] = [
            {"name": "red"},
            {"name": "green"},
        ]

        data["countries"] = [
            {"name": "Cornwall"},
            {"name": "Wales"},
        ]

        template = """
{{#colors}}
<li>{{name}}</li>
{{#colors}}
{{#countries}}
<li>{{name}}</li>
{{#countries}}
        """

        render_result = templater.render(template, data)
        expected = """

<li>red</li>

<li>green</li>


<li>Cornwall</li>

<li>Wales</li>

        """
        self.assertEqual(expected, render_result)
Example #5
0
def charity_profile_handler(request, charity_profile_id):
    charity = backend_objects.Charity.get(charity_profile_id)
    #charity = backend_objects.Charity("Snail Helpline", "We help snails!!", "https://en.wikipedia.org/wiki/Snail", logoURL = "snail.jpg")
    #request.write("Here is the profile for charity " + charity_profile_id + ".")
    #request.write(get_template("charity.html").format(charity_profile_id = charity_profile_id, charity_name = "charity_name", charity_logo = "charity_logo"))
    context = {"charity": charity, "charity_profile_id": charity_profile_id}
    request.write(templater.render("templates/charity.html", context))
Example #6
0
def coversheet(req, params):
    if req.user:
        user_id = req.user['usr_id']
        session_id = req.session['session_id']
        page = templater.render('templates/coversheet.html', locals())
        return 'text/html', page, None
    else:
        return login(req, params)
 def test_render_itemlist(self):
     data = {}
     data["colors"] = [
         {"name": "red"},
         {"name": "green"},
     ]
     render_result = templater.render("{{#colors}}<li>{{name}}</li>{{#colors}}", data)
     self.assertEqual("<li>red</li><li>green</li>", render_result)
 def test_render_itemlist_nomatch(self):
     data = {}
     data["colors"] = [
         {"name": "red"},
         {"name": "green"},
     ]
     render_result = templater.render("no match", data)
     self.assertEqual("no match", render_result)
Example #9
0
def post_create_charity_profile_handler(request):
    context = {}
    charity_name = request.get_field('new_name')
    charity_logo_name = request.get_field("logo_name")
    charity_new_bio = request.get_field("new_bio")
    #request.write("You have added a Charity with this name " + charity_name + ". Your logo name is: " + charity_logo_name + ". And your bio is: " + charity_new_bio)
    new_charity = backend_objects.Charity(charity_name,
                                          story=charity_new_bio,
                                          logoURL=charity_logo_name)
    new_charity.save()
    context['charity'] = new_charity
    request.write(
        templater.render("templates/post_create_charity_profile.html",
                         context))
Example #10
0
    def test_render_two_itemlists(self):
        data = {}
        data["colors"] = [
            {"name": "red"},
            {"name": "green"},
        ]

        data["countries"] = [
            {"name": "Cornwall"},
            {"name": "Wales"},
        ]
        render_result = templater.render(
            "Colors:{{#colors}}{{name}},{{#colors}};Countries:{{#countries}}{{name}},{{#countries}}", data)
        self.assertEqual("Colors:red,green,;Countries:Cornwall,Wales,", render_result)
Example #11
0
def create_user_profile_handler(request):
    context = {}
    request.write(templater.render("templates/user_sign_up.html", context))
Example #12
0
def feed_handler(request):
    context = {
        "Post": backend_objects.Post,
        "Charity": backend_objects.Charity
    }
    request.write(templater.render("templates/feed.html", context))
Example #13
0
from net.sf.chellow.monad import Monad
import db
import templater

Monad.getUtils()["impt"](globals(), "templater", "db")
Contract = db.Contract
inv, template = globals()["inv"], globals()["templater"]

sess = None
try:
    sess = db.session()
    contract_id = inv.getLong("mop_contract_id")

    contract = Contract.get_mop_by_id(contract_id)
    templater.render(inv, template, {"contract": contract})
finally:
    if sess is not None:
        sess.close()
Example #14
0
from net.sf.chellow.monad import Monad
import db
import templater
Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')
Contract, Batch = db.Contract, db.Batch
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    if inv.getRequest().getMethod() == 'GET':
        contract_id = inv.getLong('mop_contract_id')
        contract = Contract.get_mop_by_id(sess, contract_id)
        batches = sess.query(Batch).filter(
            Batch.contract_id == contract.id).order_by(
            Batch.reference.desc()).all()
        templater.render(
            inv, template, {'contract': contract, 'batches': batches})
finally:
    if sess is not None:
        sess.close()
Example #15
0
 def test_render_missing(self):
     render_result = templater.render("hallo {{color}}", {"name": "susi"})
     self.assertEqual("hallo ", render_result)
Example #16
0
import db
import templater
import utils
Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')
inv, template = globals()['inv'], globals()['template']


def make_fields():
    initial_date = datetime.utcnow().replace(tzinfo=pytz.utc)
    initial_date = datetime(initial_date.year, initial_date.month, 1)
    return {'initial_date': initial_date}

sess = None
try:
    sess = db.session()
    if inv.getRequest().getMethod() == 'GET':
        templater.render(inv, template, make_fields())
    else:
        db.set_read_write(sess)
        name = inv.getString('name')
        is_core = inv.getBoolean('is_core')
        start_date = utils.form_date(inv, 'start')
        contract = db.Contract.insert_non_core(
            sess, is_core, name, '{}', '{}', start_date, None, '{}')
        sess.commit()
        inv.sendSeeOther(
            '/reports/267/output/?non_core_contract_id=' + str(contract.id))
finally:
    if sess is not None:
        sess.close()
Example #17
0
from net.sf.chellow.monad import Monad
import db
import templater
Monad.getUtils()['impt'](globals(), 'templater', 'db')
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    pc_id = inv.getLong('pc_id')
    pc = db.Pc.get_by_id(sess, pc_id)
    templater.render(inv, template, {'pc': pc})
finally:
    if sess is not None:
        sess.close()
Example #18
0
def user_profile_handler(request, user_profile_id, user_profile_name):
    #request.write("Here is " + user_profile_id + " aka " + user_profile_name)
    user = backend_objects.User.get(0)
    context = {"user": user}
    request.write(templater.render("templates/user.html", context))
Example #19
0
def about_handler(request):
    context = {}
    request.write(templater.render("templates/about.html", context))
Example #20
0
from net.sf.chellow.monad import Monad
import db
import templater
Monad.getUtils()['impt'](globals(), 'templater', 'db')
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    cop_id = inv.getLong('cop_id')
    cop = db.Cop.get_by_id(sess, cop_id)
    templater.render(inv, template, {'cop': cop})
finally:
    if sess is not None:
        sess.close()
Example #21
0
from net.sf.chellow.monad import Monad
import db
import templater
Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    rate_script_id = inv.getLong('hhdc_rate_script_id')
    rate_script = db.RateScript.get_hhdc_by_id(sess, rate_script_id)
    templater.render(inv, template, {'rate_script': rate_script})
finally:
    if sess is not None:
        sess.close()
Example #22
0
import templater

class User:
    def __init__(self, name):
        self.name = name

user = User("Tim Dawborn")
print(templater.render('docs/templater.md', user=user,
                       movie_list=["Aladdin", "Finding Nemo"],
                       var_name="Example variable",
                       page_title="Movie list",
                       site_title="List thing site",
                       expression=True))
Example #23
0
UserException = utils.UserException
render = templater.render
inv, template = globals()['inv'], globals()['template']


def make_fields(sess, snag, message=None):
    messages = [] if message is None else [str(message)]
    return {'snag': snag, 'messages': messages}

sess = None
try:
    sess = db.session()
    if inv.getRequest().getMethod() == 'GET':
        snag_id = inv.getLong('site_snag_id')
        snag = db.Snag.get_by_id(sess, snag_id)
        templater.render(inv, template, make_fields(sess, snag))
    else:
        db.set_read_write(sess)
        snag_id = inv.getLong('site_snag_id')
        ignore = inv.getBoolean('ignore')

        snag = db.Snag.get_by_id(sess, snag_id)
        snag.is_ignored = ignore
        sess.commit()
        inv.sendSeeOther("/reports/119/output/?site_snag_id=" + str(snag.id))
except UserException, e:
    sess.rollback()
    templater.render(inv, template, make_fields(sess, snag, e), 400)
finally:
    sess.close()
Example #24
0
from net.sf.chellow.monad import Monad
import db
import templater
Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')
Contract, MarketRole = db.Contract, db.MarketRole
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    hhdc_contracts = sess.query(Contract).join(MarketRole).filter(
        MarketRole.code == 'C').order_by(Contract.name).all()
    templater.render(inv, template, {'hhdc_contracts': hhdc_contracts})
finally:
    if sess is not None:
        sess.close()
Example #25
0
from net.sf.chellow.monad import Monad
import db
import utils
import templater
Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    utils.clog("hello")
    templater.render(inv, template, {'clogs': utils.clogs})
finally:
    if sess is not None:
        sess.close()
Example #26
0
from net.sf.chellow.monad import Monad
import db
import templater
Monad.getUtils()['impt'](globals(), 'templater', 'db')
ReadType = db.ReadType
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    read_types = sess.query(ReadType).order_by(ReadType.code).all()
    templater.render(inv, template, {'read_types': read_types})
finally:
    if sess is not None:
        sess.close()
Example #27
0
def charity_list_handler(request):
    context = {}
    request.write(templater.render("templates/charity_list.html", context))
Example #28
0
from net.sf.chellow.monad import Monad
import templater
Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')
inv, template = globals()['inv'], globals()['template']

templater.render(inv, template, {})
Example #29
0
from net.sf.chellow.monad import Monad
import db
import templater

Monad.getUtils()["impt"](globals(), "templater", "db")
GspGroup = db.GspGroup
inv, template = globals()["inv"], globals()["template"]

sess = None
try:
    sess = db.session()
    groups = sess.query(GspGroup).order_by(GspGroup.code).all()
    templater.render(inv, template, {"groups": groups})
finally:
    if sess is not None:
        sess.close()
Example #30
0
from net.sf.chellow.monad import Monad
import db
import templater
import datetime
from dateutil.relativedelta import relativedelta
Monad.getUtils()['impt'](globals(), 'templater', 'db')
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    now = datetime.datetime.utcnow()
    if now.month < 3:
        now += relativedelta(year=1)
    templater.render(inv, template, {'year': now.year})
finally:
    if sess is not None:
        sess.close()
Example #31
0
 def test_render_existing(self):
     render_result = templater.render("hallo {{name}}", {"name": "susi"})
     self.assertEqual("hallo susi", render_result)
Example #32
0
 def test_render_two(self):
     render_result = templater.render("hallo {{name}} {{color}}", {"color": "red", "name": "susi"})
     self.assertEqual("hallo susi red", render_result)
Example #33
0
from net.sf.chellow.monad import Monad
import db
import templater
Monad.getUtils()['impt'](globals(), 'templater', 'db')
Contract, MarketRole = db.Contract, db.MarketRole
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    contracts = [
        Contract.get_non_core_by_name(sess, name)
        for name in sorted(('ccl', 'aahedc', 'bsuos', 'tlms', 'rcrc'))]
    scenarios = sess.query(Contract).join(MarketRole).filter(
        MarketRole.code == 'X',
        Contract.name.like('scenario_%')).order_by(Contract.name).all()
    templater.render(
        inv, template, {'contracts': contracts, 'scenarios': scenarios})
finally:
    if sess is not None:
        sess.close()
Example #34
0
from net.sf.chellow.monad import Monad
import db
import templater
Monad.getUtils()['impt'](globals(), 'templater', 'db')
MeterType, Party = db.MeterType, db.Party
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    meter_types = sess.query(MeterType).order_by(MeterType.code)
    templater.render(inv, template, {'meter_types': meter_types})
finally:
    if sess is not None:
        sess.close()
Example #35
0
from net.sf.chellow.monad import Monad
import db
import templater
import utils
from sqlalchemy.exc import SQLAlchemyError

Monad.getUtils()['impt'](globals(), 'templater', 'db', 'utils')
form_str = utils.form_str
inv, template = globals()['inv'], globals()['template']

sess = None
messages = None
try:
    sess = db.session()
    result = None
    if inv.hasParameter('query') and (inv.getRequest().getMethod() == 'POST'):
        query = form_str(inv, 'query')
        query = query.strip()
        if len(query) > 0:
            try:
                result = sess.execute(query)
            except SQLAlchemyError, e:
                messages.append(str(e))

    templater.render(inv, template, {'result': result, 'messages': messages})
finally:
    if sess is not None:
        sess.close()
Example #36
0
    parser_names = ', '.join(
        '.' + row[0][12:] for row in sess.query(Contract.name).filter(
            Contract.name.like("bill-parser-%")))
    return {
        'messages': messages,
        'importer_ids': sorted(
            bill_import.get_bill_importer_ids(batch.id), reverse=True),
        'batch': batch, 'parser_names': parser_names}

sess = None
try:
    sess = db.session()
    if inv.getRequest().getMethod() == 'GET':
        batch_id = inv.getLong('supplier_batch_id')
        batch = db.Batch.get_by_id(sess, batch_id)
        templater.render(inv, template, make_fields(sess, batch))
    else:
        batch_id = inv.getLong('supplier_batch_id')
        batch = db.Batch.get_by_id(sess, batch_id)
        file_item = inv.getFileItem("import_file")
        f = StringIO.StringIO()
        if sys.platform.startswith('java'):
            from java.io import InputStreamReader

            stream = InputStreamReader(file_item.getInputStream(), 'utf-8')
            bt = stream.read()
            while bt != -1:
                f.write(unichr(bt))
                bt = stream.read()
            file_size = file_item.getSize()
        else:
Example #37
0
def create_charity_profile_handler(request):
    context = {}
    request.write(
        templater.render("templates/create_charity_profile.html", context))
    """Wanting to do something here but not sure what yet."""
Example #38
0
from net.sf.chellow.monad import Monad
import db
import templater
import utils
Monad.getUtils()['impt'](globals(), 'templater', 'db', 'utils')
GspGroup = db.GspGroup
form_int = utils.form_int
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    group_id = form_int(inv, 'gsp_group_id')
    group = GspGroup.get_by_id(sess, group_id)
    templater.render(inv, template, {'group': group})
finally:
    if sess is not None:
        sess.close()
Example #39
0
import pytz
import utils
import db
import templater
Monad.getUtils()['impt'](globals(), 'db', 'utils', 'templater')
render = templater.render
HH = utils.HH
Contract, RateScript = db.Contract, db.RateScript
inv, template = globals()['inv'], globals()['template']

sess = None
try:
    sess = db.session()
    contract_id = inv.getLong('mop_contract_id')
    contract = Contract.get_mop_by_id(sess, contract_id)
    rate_scripts = sess.query(RateScript).filter(
        RateScript.contract == contract).order_by(
        RateScript.start_date.desc()).all()
    now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
    last_month_start = datetime.datetime(
        now.year, now.month, 1, tzinfo=pytz.utc) - relativedelta(months=1)
    last_month_finish = last_month_start + relativedelta(months=1) - HH
    templater.render(
        inv, template, {
            'contract': contract, 'rate_scripts': rate_scripts,
            'last_month_start': last_month_start,
            'last_month_finish': last_month_finish})
finally:
    if sess is not None:
        sess.close()