Example #1
0
#!/usr/bin/env python
import os
from Cheetah.Template import Template
from model.Record import EntitySet

CommentDatabase = EntitySet("groups", key="groupid")


def store_new_comment(the_comment):
    return CommentDatabase.new_record(the_comment)


def read_database():
    return CommentDatabase.read_database()


def store_comment(comment):
    return CommentDatabase.store_record(comment)


def get_comment(comment):
    return CommentDatabase.get_record(comment)


def delete_comment(comment):
    return CommentDatabase.delete_record(comment)


# #
# # Map web request to data layer
# #
Example #2
0
#!/usr/bin/python

from Cheetah.Template import Template
from model.Record import EntitySet
import sys
import os

ItemsDatabase = EntitySet("items",key="itemid")

def store_new_item(the_item): return ItemsDatabase.new_record(the_item)
def read_database(): return ItemsDatabase.read_database()
def store_item(item): return ItemsDatabase.store_record(item)
def get_item(item): return ItemsDatabase.get_record(item)
def delete_item(item): return ItemsDatabase.delete_record(item)

#
# Map web request to data layer
#

def make_item(stem="form", **argd):
    new_item = {
        "item" : argd.get(stem + ".item",""),
        "__filename" : argd.get(stem + ".upload.1.__filename",""),
        "tags" : argd.get(stem + ".tags",""),
    }
    new_item = store_new_item(new_item)
    return new_item

#
# Map web request to data layer
#
Example #3
0
#!/usr/bin/env python

from Cheetah.Template import Template
from model.Record import EntitySet

PeopleDatabase = EntitySet("people")


def store_new_person(the_person):
    return PeopleDatabase.new_record(the_person)


def read_database():
    return PeopleDatabase.read_database()


def store_person(person):
    return PeopleDatabase.store_record(person)


def get_person(person):
    return PeopleDatabase.get_record(person)


def delete_person(person):
    return PeopleDatabase.delete_record(person)


#
# Map web request to data layer
#
#!/usr/bin/env python
import os
from Cheetah.Template import Template
from model.Record import EntitySet

CommentDatabase = EntitySet("comments", key="commentid")


def store_new_comment(the_comment):
    return CommentDatabase.new_record(the_comment)


def read_database():
    return CommentDatabase.read_database()


def store_comment(comment):
    return CommentDatabase.store_record(comment)


def get_comment(comment):
    return CommentDatabase.get_record(comment)


def delete_comment(comment):
    return CommentDatabase.delete_record(comment)


# #
# # Map web request to data layer
# #
Example #5
0
#!/usr/bin/env python

import os.path

import sys

sys.path.append("/srv/www/sites/bicker.kamaelia.org/cgi/app/Facilitate")
import CookieJar

from model.Record import EntitySet

EntitySet.data = "/srv/www/sites/bicker.kamaelia.org/cgi/app/data"

Registrations = EntitySet("registrations", key="regid")
Videos = EntitySet("videos", key="imageid")

loggedout = False


def loggedIn(env):
    if loggedout:
        return False

    cookies = env.get("cookies", None)
    if not cookies:
        return False

    sessioncookie_raw = cookies.get("sessioncookie", None)
    if not sessioncookie_raw:
        return False
Example #6
0
#!/usr/bin/env python

from Cheetah.Template import Template
from model.Record import EntitySet
import cjson
import sys
import os

RelationSet = EntitySet

MissionStepsRelation = RelationSet("lists", key="relationid")
ItemsDatabase = EntitySet("missions", key="missionid")
PeopleDatabase = EntitySet("missions", key="missionid")

#
# This lot need dealing with more sensibly
#


def store_new_item(the_item):
    return MissionStepsRelation.new_record(the_item)


def read_database():
    return MissionStepsRelation.read_database()


def store_item(item):
    return MissionStepsRelation.store_record(item)

Example #7
0
#!/usr/bin/env python

import os.path


import sys ; sys.path.append("/srv/www/sites/bicker.kamaelia.org/cgi/app/Facilitate")
import CookieJar

from model.Record import EntitySet

EntitySet.data = "/srv/www/sites/bicker.kamaelia.org/cgi/app/data"

Registrations = EntitySet("registrations", key="regid")
Videos        = EntitySet("videos", key="imageid")

loggedout = False

def loggedIn(env):
    if loggedout:
        return False

    cookies = env.get("cookies", None)
    if not cookies:
        return False

    sessioncookie_raw = cookies.get("sessioncookie", None)
    if not sessioncookie_raw:
        return False

    sessioncookie = sessioncookie_raw.value
Example #8
0
#!/usr/bin/python

from Cheetah.Template import Template
from model.Record import EntitySet

# NOTE: You would rename "Missions" here to match your entity set's name
MissionsDatabase = EntitySet("missions", key="missionid")


# NOTE: Likewise, rather than MissionsDatabase, this would be your entity's name
def store_new_mission(the_mission):
    return MissionsDatabase.new_record(the_mission)


def read_database():
    return MissionsDatabase.read_database()


def store_mission(mission):
    return MissionsDatabase.store_record(mission)


def get_mission(mission):
    return MissionsDatabase.get_record(mission)


def delete_mission(mission):
    return MissionsDatabase.delete_record(mission)

#
# Map web request to data layer
Example #9
0
    if structure[0] == "responsestored":
        return [], Interstitials.thankyou_template

    if structure[0] == "error":
        structure[1]["record"] = pprint.pformat(structure[1]["record"])
        page = Interstitials.error % structure[1]
        headers = []
        if structure[1].get("setcookies", False):
            cookies = structure[1]["setcookies"]
            for cookie in cookies:
                headers.append(
                    ("Set-Cookie", "%s=%s" % (cookie, cookies[cookie])))

        return headers, page

    return [], Interstitials.failback % {"body": pprint.pformat(structure)}


def page_render_html(json, **argd):
    extra_headers, page = MakeHTML(page_logic(json, **argd))
    status = "200 OK"
    headers = [('Content-type', "text/html")]
    return status, headers + extra_headers, page


SimpleResponses = EntitySet("simpleresponses", key="responseid")

if __name__ == "__main__":
    pass
Example #10
0
#!/usr/bin/env python

from Cheetah.Template import Template
from model.Record import EntitySet

PeopleDatabase = EntitySet("people", "personid")

#
# Map web request to data layer
#


def make_person(stem="form", **argd):
    new_person = {
        "person": argd.get(stem + ".person", ""),
        "house": argd.get(stem + ".house", ""),
        "street": argd.get(stem + ".street", ""),
        "town": argd.get(stem + ".town", ""),
        "county": argd.get(stem + ".county", ""),
        "postcode": argd.get(stem + ".postcode", ""),
        "phone": argd.get(stem + ".phone", ""),
    }
    new_person = PeopleDatabase.new_record(new_person)
    return new_person


#
# Map web request to data layer
#

Example #11
0
#!/usr/bin/env python

from Cheetah.Template import Template
from model.Record import EntitySet
import sys
import os

RelationSet = EntitySet

TreesMembers = RelationSet("treesmembers", key="treememberid")
TreesDatabase = EntitySet("trees", key="treeid")
PeopleDatabase = EntitySet("people", key="personid")

#
# This lot need dealing with more sensibly
#


def store_new_item(the_item):
    return TreesMembers.new_record(the_item)


def read_database():
    return TreesMembers.read_database()


def store_item(item):
    return TreesMembers.store_record(item)


def get_item(item):
Example #12
0
#!/usr/bin/env python
import os
from Cheetah.Template import Template
from model.Record import EntitySet

CommentDatabase = EntitySet("trees", key="treeid")


def store_new_comment(the_comment):
    return CommentDatabase.new_record(the_comment)


def read_database():
    return CommentDatabase.read_database()


def store_comment(comment):
    return CommentDatabase.store_record(comment)


def get_comment(comment):
    return CommentDatabase.get_record(comment)


def delete_comment(comment):
    return CommentDatabase.delete_record(comment)


# #
# # Map web request to data layer
# #
Example #13
0
def page_render_html(json, **argd):
    action = argd.get("formtype", "overview")
    R = RelationRender(argd["__environ__"])

    if action == "overview":
        relations = read_database()
        rendered_relations = R.rendered_record_list(
            relations)  # generalised Rendered Relation

        return R.render_page(content=rendered_relations)  #str(R.environ)) #

    if action == "edit_new":
        relations = read_database()
        rendered_relations = R.rendered_record_list(
            relations)  #generalised Rendered Realtion
        leftitemtypes = get_itemtypes(
        )  #return the list of top level data items
        relations = read_database()
        rendered_relations = R.rendered_record_list(relations)
        empty_data_entry = R.rendered_itemtypes(-1, leftitemtypes)
        configured_form = R.render_configured_form(empty_data_entry,
                                                   nextstep="edit_items")
        return R.render_page(content=rendered_relations,
                             dataentry=configured_form)

    if action == "edit_items":
        relations = read_database()
        #rendered_relations  = R.rendered_record_list(relations)  # need generalised RenderedRealtion here
        #os.sys.stderr.write(argd.get("form.leftid")+"\n")
        #os.sys.stderr.write(argd.get("form.rightid")+"\n")

        leftdbid = argd.get("form.leftid")
        rightdbid = argd.get("form.rightid")
        leftdb_key = get_itemtype_key(leftdbid)
        rightdb_key = get_itemtype_key(rightdbid)
        relationid = -1
        #os.sys.stderr.write(leftdb_key+" "+rightdb_key+ "\n")
        leftdb = EntitySet(leftdbid, key=leftdb_key)
        rightdb = EntitySet(rightdbid, key=rightdb_key)
        #relation = RenderedRelation(R,leftdb, rightdb )
        available_relations = RenderedRelation(R, leftdb, rightdb)
        empty_data_entry = RenderedRelationEntryForm(relationid, leftdbid,
                                                     rightdbid, leftdb_key,
                                                     rightdb_key, leftdb,
                                                     rightdb)
        #os.sys.stderr.write("empty data entry returned \n")
        #os.sys.stderr.write(repr(empty_data_entry))
        configured_form = R.render_configured_item_form(empty_data_entry,
                                                        nextstep="create_new",
                                                        submitlabel="Add Item")

        return R.render_page(content=available_relations,
                             dataentry=configured_form)

    if action == "view_relation":
        relations = read_database()
        rendered_relations = R.rendered_record_list(relations)
        relation = get_item(argd["relationid"])
        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        return R.render_page(content=rendered_relations,
                             dataentry=rendered_relation_pair)

    if action == "edit_relation":
        relations = read_database()
        rendered_relations = R.rendered_record_list(relations)
        relation = get_item(argd["relationid"])
        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        leftitemtypes = get_itemtypes()
        empty_data_entry = R.rendered_itemtypes(argd["relationid"],
                                                leftitemtypes)
        configured_form = R.render_configured_form(
            empty_data_entry,
            nextstep="update_items",
            submitlabel="Update Item",
        )
        return R.render_page(extra=rendered_relations,
                             content=rendered_relation_pair,
                             dataentry=configured_form)

    if action == "create_new":
        os.sys.stderr.write(argd.get("form.left_dbid") + "\n")
        os.sys.stderr.write(argd.get("form.right_dbid") + "\n")
        new_relation = make_item(stem="form",
                                 **argd)  # Also stores them in the database
        relations = read_database()
        rendered_relations = R.rendered_record_list(relations)
        relation_pair = get_item_record_pair(new_relation)
        rendered_relation_pair = RenderedRelationPair(R, new_relation,
                                                      relation_pair)
        #rendered_tuple = RenderedTuple(argd["__environ__"],"missionstepid", new_item["missionstepid"], ItemsDatabase, PeopleDatabase)
        rendered_relation_pair = "<B> Record Saved </B>. If you wish to update, please do" + str(
            rendered_relation_pair)
        #rendered_tuple = "<B> Record Saved </B>. If you wish to update, please do" + str(rendered_tuple)
        #relation = get_item(argd["relationid"])
        return R.render_page(content=rendered_relations,
                             dataentry=rendered_relation_pair)

    if action == "delete_relation":
        # Take the data sent to us, and use that to fill out an edit form
        #
        # Note: This is actually filling in an *edit* form at that point, not a *new* user form
        # If they submit the new form, the surely they should be viewed to be updating the form?
        # yes...
        #
        # Show the database & a few options
        relations = read_database()
        rendered_relations = R.rendered_record_list(
            relations)  # generalised Rendered Relation
        relation = get_item(argd["relationid"])
        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        prebanner = "<h3> Are you sure you wish to delete this item</h3>"
        delete_action = "<a href='/cgi-bin/app/relations?formtype=confirm_delete&relationid=%s'>%s</a>" % (
            relation["relationid"], "Delete this item")
        cancel_action = "<a href='/cgi-bin/app/relations?formtype=view_relation&relationid=%s'>%s</a>" % (
            relation["relationid"], "Cancel deletion")

        delete_message = "%s <ul> %s </ul><h3> %s | %s </h3>" % (
            prebanner, str(rendered_relation_pair), delete_action,
            cancel_action)
        return R.render_page(content=rendered_relations,
                             dataentry=delete_message)

    if action == "confirm_delete":
        relation = get_item(argd["relationid"])
        delete_item(argd["relationid"])
        relations = read_database()  # Show the database & a few options
        rendered_relations = R.rendered_record_list(
            relations)  # generalised Rendered Relation
        return R.render_page(content=rendered_relations,
                             dataentry="<h1> Record %s Deleted </h1>" %
                             argd["relationid"])

    if action == "update_items":
        relationid = argd.get("form.relationid")
        relation = get_item(relationid)
        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        relations = read_database()

        leftdbid = argd.get("form.leftid")
        rightdbid = argd.get("form.rightid")
        leftdb_key = get_itemtype_key(leftdbid)
        rightdb_key = get_itemtype_key(rightdbid)

        #os.sys.stderr.write(leftdb_key+" "+rightdb_key+ "\n")
        leftdb = EntitySet(leftdbid, key=leftdb_key)
        rightdb = EntitySet(rightdbid, key=rightdb_key)
        available_relations = RenderedRelation(R, leftdb, rightdb)
        empty_data_entry = RenderedRelationEntryForm(relationid, leftdbid,
                                                     rightdbid, leftdb_key,
                                                     rightdb_key, leftdb,
                                                     rightdb)
        configured_form = R.render_configured_item_form(
            empty_data_entry, nextstep="update", submitlabel="Update Item")
        return R.render_page(content=available_relations,
                             dataentry=configured_form)

    if action == "update":
        # Take the data sent to us, and use that to fill out an edit form
        #
        # Note: This is actually filling in an *edit* form at that point, not a *new* user form
        # If they submit the new form, the surely they should be viewed to be updating the form?
        # yes...
        #
        relation = get_item(argd.get("form.relationid"))
        theitem = update_item(stem="form", **argd)
        relations = read_database()
        rendered_relations = R.rendered_record_list(
            relations)  # generalised Rendered Relation

        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        rendered_tuple = "<B> Record Saved </B>. If you wish to update, please do" + str(
            rendered_relation_pair)

        return R.render_page(content=rendered_relations,
                             dataentry=rendered_tuple)

    return str(
        Template(
            file='templates/Page.tmpl',
            searchList=[
                argd["__environ__"],
                {
                    "extra":
                    "",
                    "content":
                    "Sorry, got no idea what you want! (%s)" % str(action),
                    "dataentry":
                    "",
                    "banner":
                    "Not found",  # XXXX should send back a 404 status
                }
            ]))
Example #14
0
        return [], Interstitials.uploadok

    if structure[0] == "error":
        structure[1]["record"] = pprint.pformat(structure[1]["record"])
        page = Interstitials.error % structure[1]
        headers = []
        if structure[1].get("setcookies", False):
            cookies = structure[1]["setcookies"]
            for cookie in cookies:
                headers.append(
                    ("Set-Cookie", "%s=%s" % (cookie, cookies[cookie])))

        return headers, page

    return [], Interstitials.failback % {"body": pprint.pformat(structure)}


def page_render_html(json, **argd):
    extra_headers, page = MakeHTML(page_logic(json, **argd))
    status = "200 OK"
    headers = [('Content-type', "text/html")]
    return status, headers + extra_headers, page


Images = EntitySet("images", key="imageid")
Registrations = EntitySet("registrations", key="regid")
Contacts = EntitySet("contacts", key="contactid")

if __name__ == "__main__":
    pass
Example #15
0
#!/usr/bin/env python

import os.path
import sys
sys.path.append("/srv/www/sites/bicker.kamaelia.org/cgi/app/Facilitate")
import CookieJar

from model.Record import EntitySet

EntitySet.data = "/srv/www/sites/bicker.kamaelia.org/cgi/app/data"
Registrations = EntitySet("registrations", key="regid")
Contacts = EntitySet("contacts", key="contactid")


def set_cookie(env, thecookie, value):
    env["context"]["newcookies"][thecookie] = value


loggedout = False


def loggedIn(env):
    if loggedout:
        return False

    cookies = env.get("cookies", None)
    if not cookies:
        return False

    sessioncookie_raw = cookies.get("sessioncookie", None)
    if not sessioncookie_raw:
Example #16
0
                headers.append(
                    ("Set-Cookie", "%s=%s" % (cookie, cookies[cookie])))

        return headers, page

    return [], Interstitials.failback % {"body": pprint.pformat(structure)}


def page_render_html(json, **argd):
    extra_headers, page = MakeHTML(page_logic(json, **argd))
    status = "200 OK"
    headers = [('Content-type', "text/html")]
    return status, headers + extra_headers, page


Registrations = EntitySet("registrations", key="regid")

if __name__ == "__main__":

    print "Enter password for [email protected]"
    password = raw_input(
        ">> ")  # To avoid putting even a test password in the repository... :)

    loginbundle = {
        'email': '*****@*****.**',
        'password': password,
        'submit': '+Login+',
    }
    result = page_logic(None, **loginbundle)
    print result
    result = page_render_html(None, **loginbundle)
Example #17
0
#!/usr/bin/env python

from Cheetah.Template import Template
from model.Record import EntitySet
import sys
import os

RelationSet = EntitySet

ItemsPeopleRelation = RelationSet("itemspeople_relation", key="itempersonid")
ItemsDatabase = EntitySet("items", key="itemid")
PeopleDatabase = EntitySet("people")

#
# This lot need dealing with more sensibly
#


def store_new_item(the_item):
    return ItemsPeopleRelation.new_record(the_item)


def read_database():
    return ItemsPeopleRelation.read_database()


def store_item(item):
    return ItemsPeopleRelation.store_record(item)


def get_item(item):
Example #18
0
#!/usr/bin/env python

import os.path

import sys ; sys.path.append("/srv/www/sites/bicker.kamaelia.org/cgi/app/Facilitate")
import CookieJar

from model.Record import EntitySet

EntitySet.data = "/srv/www/sites/bicker.kamaelia.org/cgi/app/data"

Images        = EntitySet("images", key="imageid")
Registrations = EntitySet("registrations", key="regid")
Contacts      = EntitySet("contacts", key="contactid")

loggedout = False

def loggedIn(env):
    if loggedout:
        return False

    cookies = env.get("cookies", None)
    if not cookies:
        return False

    sessioncookie_raw = cookies.get("sessioncookie", None)
    if not sessioncookie_raw:
        return False

    sessioncookie = sessioncookie_raw.value
Example #19
0
        return [], Interstitials.video_uploadok

    if structure[0] == "error":
        structure[1]["record"] = pprint.pformat(structure[1]["record"])
        page = Interstitials.error % structure[1]
        headers = []
        if structure[1].get("setcookies", False):
            cookies = structure[1]["setcookies"]
            for cookie in cookies:
                headers.append(
                    ("Set-Cookie", "%s=%s" % (cookie, cookies[cookie])))

        return headers, page

    return [], Interstitials.failback % {"body": pprint.pformat(structure)}


def page_render_html(json, **argd):
    extra_headers, page = MakeHTML(page_logic(json, **argd))
    status = "200 OK"
    headers = [('Content-type', "text/html")]
    return status, headers + extra_headers, page


Videos = EntitySet("videos", key="videoid")
Registrations = EntitySet("registrations", key="regid")
Contacts = EntitySet("contacts", key="contactid")

if __name__ == "__main__":
    pass
Example #20
0
            cookies = structure[1]["setcookies"]
            for cookie in cookies:
                headers.append( ("Set-Cookie", "%s=%s" % ( cookie, cookies[cookie]) ) )

        return headers, page

    return [], Interstitials.failback % { "body" : pprint.pformat(structure) }
    

def page_render_html(json, **argd):
    extra_headers, page = MakeHTML( page_logic(json, **argd) )
    status = "200 OK"
    headers = [('Content-type', "text/html")]
    return status, headers+extra_headers, page

Registrations = EntitySet("registrations", key="regid")

if __name__ == "__main__":
    if 0:
        print "WARNING, running this test will zap your local store"
        print "press return to continue, control-c to not continue"
        raw_input()
    Registrations.Zap("registrations","regid")
    testcases = [
             [ "new", 
                "should succeed",
               "Can create new record in new database",
               {
                  'action' : 'new',
                  'dob.day': '30',
                  'dob.month': 'June',
Example #21
0
#!/usr/bin/env python

from Cheetah.Template import Template
from model.Record import EntitySet
import os,time

UsersDatabase = EntitySet("users",key="userid")des

def store_new_user(the_user): return UsersDatabase.new_record(the_user)
def read_database(): return UsersDatabase.read_database()
def store_user(user): return UsersDatabase.store_record(user)
def get_user(user): return UsersDatabase.get_record(user)
def delete_user(user): return UsersDatabase.delete_record(user)


#
# Map web request to data layer
#

def make_user_unique(fields = [], stem="form", **argd):
    if  fields==[]:
        make_user(stem="form", **argd)
    else:        
        new_vals = {}
        for field in fields:
            new_vals[field] = argd.get("form."+field) 
        users = read_database()
        if not users:
            os.sys.stderr.write("new user empty db+++++++++++++++++++++++++\n")
            return make_user(stem="form", **argd)
        for user in users:            
Example #22
0
def page_render_html(json, **argd):
    action = argd.get("formtype", "overview")
    R = RelationRender(argd["__environ__"])

    if action == "overview":
        relations = read_database()
        rendered_relations = R.rendered_record_list(
            relations)  # generalised Rendered Relation

        return R.render_page(content=rendered_relations)  #str(R.environ)) #

    if action == "edit_new":
        relations = read_database()
        os.sys.stderr.write(
            repr(relations) + "***************empty db *****\n")
        if relations == []:
            leftitemtypes = get_itemtypes(dirlist=["items", "comments"])
        else:
            leftitemtypes = get_itemtypes()
        rendered_relations = R.rendered_record_list(
            relations)  #generalised Rendered Relation
        #leftitemtypes = get_itemtypes()    #return the list of top level data items
        relations = read_database()
        rendered_relations = R.rendered_record_list(relations)
        empty_data_entry = R.rendered_itemtypes(-1, relations, leftitemtypes)
        configured_form = R.render_configured_form(empty_data_entry,
                                                   nextstep="edit_items")
        return R.render_page(content=rendered_relations,
                             dataentry=configured_form)

    if action == "edit_items":
        relations = read_database()
        #rendered_relations  = R.rendered_record_list(relations)  # need generalised RenderedRelation here
        #os.sys.stderr.write(argd.get("form.leftid")+"\n")
        #os.sys.stderr.write(argd.get("form.rightid")+"\n")

        leftdbid = argd.get("form.leftid")
        rightdbid = argd.get("form.rightid")
        leftdb_key = get_itemtype_key(leftdbid)
        rightdb_key = get_itemtype_key(rightdbid)
        relationid = -1
        #os.sys.stderr.write(leftdb_key+" "+rightdb_key+ "\n")
        leftdb = EntitySet(leftdbid, key=leftdb_key)
        rightdb = EntitySet(rightdbid, key=rightdb_key)
        #relation = RenderedRelation(R,leftdb, rightdb )
        available_relations = RenderedRelation(R, leftdb, rightdb)
        empty_data_entry = RenderedRelationEntryForm(relationid, leftdbid,
                                                     rightdbid, leftdb_key,
                                                     rightdb_key, leftdb,
                                                     rightdb)
        #os.sys.stderr.write("empty data entry returned \n")
        #os.sys.stderr.write(repr(empty_data_entry))
        configured_form = R.render_configured_item_form(empty_data_entry,
                                                        nextstep="create_new",
                                                        submitlabel="Add Item")

        return R.render_page(content=available_relations,
                             dataentry=configured_form)

    if action == "view_relation":
        relations = read_database()
        rendered_relations = R.rendered_record_list(relations)
        relation = get_item(argd["relationid"])
        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        return R.render_page(content=rendered_relations,
                             dataentry=rendered_relation_pair)

    if action == "edit_relation":
        relations = read_database()
        rendered_relations = R.rendered_record_list(relations)
        relation = get_item(argd["relationid"])
        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        leftitemtypes = get_itemtypes()
        empty_data_entry = R.rendered_itemtypes(argd["relationid"], relations,
                                                leftitemtypes)
        configured_form = R.render_configured_form(
            empty_data_entry,
            nextstep="update_items",
            submitlabel="Update Item",
        )
        return R.render_page(
            extra=rendered_relations,
            content=rendered_relation_pair,
            dataentry=configured_form)  # rendered_relations , "pop")

    if action == "create_new":
        #os.sys.stderr.write(argd.get("form.left_dbid")+"\n")
        #os.sys.stderr.write(argd.get("form.right_dbid")+"\n")
        relations = read_database()
        rendered_relations = R.rendered_record_list(relations)
        if argd.get("form.left_dbid"
                    ) == "lists":  # now we handle building the tree
            for relation in relations:  # check lhs existence
                if argd.get("form.left_itemid") == relation[
                        "left_itemid"] and relation["left_dbid"] == "lists":
                    duplicate_content = "<B> Record Not Saved </B>. The relation you requested already exists"
                    return R.render_page(content=rendered_relations,
                                         dataentry=duplicate_content)
            parent_record = get_item_record("lists",
                                            argd.get("form.left_itemid"))
            if parent_record["left_dbid"] != "lists":  # We are at the root node
                argd["form.root_id"] = parent_record["relationid"]
            else:  # child node
                argd["form.root_id"] = parent_record["root_id"]
        else:
            argd["form.root_id"] = -1
# Don't need to track back to root node just look at parent
# This will be handy for displaying the lists later.
#           rootid = None
#           while parent_record["left_dbid"]!=None and parent_record["left_dbid"]=="lists": # find the root node
#                       rootid=parent_record["root_id"] # set rootid to current root node
#                       parent_record = get_item_record("lists", parent_record["left_itemid"])


#                        if parent_record == None:      # root node has been deleted
#                             argd["form.root_id"]=rootid
#                             break
#            if parent_record != None:           # this is the root
#                        argd["form.root_id"]=parent_record["relationid"]
#            else:                               # use child root
#                        argd["form.root_id"]=rootid
#        else:
#            argd["form.root_id"]=-1
        new_relation = make_item(stem="form",
                                 **argd)  # Also stores them in the database

        rendered_relations = R.rendered_record_list(relations)
        relation_pair = get_item_record_pair(new_relation)
        rendered_relation_pair = RenderedRelationPair(R, new_relation,
                                                      relation_pair)
        #rendered_tuple = RenderedTuple(argd["__environ__"],"missionstepid", new_item["missionstepid"], ItemsDatabase, PeopleDatabase)
        rendered_relation_pair = "<B> Record Saved </B>. If you wish to update, please do" + str(
            rendered_relation_pair)
        #rendered_tuple = "<B> Record Saved </B>. If you wish to update, please do" + str(rendered_tuple)
        #relation = get_item(argd["relationid"])
        return R.render_page(content=rendered_relations,
                             dataentry=rendered_relation_pair)

    if action == "delete_relation":
        # Take the data sent to us, and use that to fill out an edit form
        #
        # Note: This is actually filling in an *edit* form at that point, not a *new* user form
        # If they submit the new form, the surely they should be viewed to be updating the form?
        # yes...
        #
        # Show the database & a few options
        relations = read_database()
        rendered_relations = R.rendered_record_list(
            relations)  # generalised Rendered Relation
        relation = get_item(argd["relationid"])
        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        prebanner = "<h3> Are you sure you wish to delete this item</h3>"
        delete_action = "<a href='/cgi-bin/app/lists?formtype=confirm_delete&relationid=%s'>%s</a>" % (
            relation["relationid"], "Delete this item")
        cancel_action = "<a href='/cgi-bin/app/lists?formtype=view_relation&relationid=%s'>%s</a>" % (
            relation["relationid"], "Cancel deletion")

        delete_message = "%s <ul> %s </ul><h3> %s | %s </h3>" % (
            prebanner, str(rendered_relation_pair), delete_action,
            cancel_action)
        return R.render_page(content=rendered_relations,
                             dataentry=delete_message)

    if action == "confirm_delete":
        relation = get_item(argd["relationid"])
        delete_item(argd["relationid"])
        relations = read_database()  # Show the database & a few options
        rendered_relations = R.rendered_record_list(
            relations)  # generalised Rendered Relation
        return R.render_page(content=rendered_relations,
                             dataentry="<h1> Record %s Deleted </h1>" %
                             argd["relationid"])

    if action == "update_items":
        relationid = argd.get("form.relationid")
        relation = get_item(relationid)
        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, relation,
                                                      relation_pair)
        relations = read_database()

        leftdbid = argd.get("form.leftid")
        rightdbid = argd.get("form.rightid")
        leftdb_key = get_itemtype_key(leftdbid)
        rightdb_key = get_itemtype_key(rightdbid)

        #os.sys.stderr.write(leftdb_key+" "+rightdb_key+ "\n")
        leftdb = EntitySet(leftdbid, key=leftdb_key)
        rightdb = EntitySet(rightdbid, key=rightdb_key)
        available_relations = RenderedRelation(R, leftdb, rightdb)
        empty_ata_entry = RenderedRelationEntryForm(relationid, leftdbid,
                                                    rightdbid, leftdb_key,
                                                    rightdb_key, leftdb,
                                                    rightdb)
        configured_form = R.render_configured_item_form(
            empty_data_entry, nextstep="update", submitlabel="Update Item")
        return R.render_page(content=available_relations,
                             dataentry=configured_form)

    if action == "update":
        # Take the data sent to us, and use that to fill out an edit form
        #
        # Note: This is actually filling in an *edit* form at that point, not a *new* user form
        # If they submit the new form, the surely they should be viewed to be updating the form?
        # yes...
        #
        relation = get_item(argd.get("form.relationid"))
        #the_relation = update_relationt(stem="form", **argd)
        theitem = update_item(stem="form", **argd)
        relations = read_database()
        rendered_relations = R.rendered_record_list(
            relations)  # generalised Rendered Relation

        relation_pair = get_item_record_pair(relation)
        rendered_relation_pair = RenderedRelationPair(R, theitem,
                                                      relation_pair)
        rendered_tuple = "<B> Record Saved </B>. If you wish to update, please do" + str(
            rendered_relation_pair)

        return R.render_page(content=rendered_relations,
                             dataentry=rendered_tuple)

    return str(
        Template(
            file='templates/Page.tmpl',
            searchList=[
                argd["__environ__"],
                {
                    "extra":
                    "",
                    "content":
                    "Sorry, got no idea what you want! (%s)" % str(action),
                    "dataentry":
                    "",
                    "banner":
                    "Not found",  # XXXX should send back a 404 status
                }
            ]))
Example #23
0
#!/usr/bin/env python

from Cheetah.Template import Template
from model.Record import EntitySet
import sys
import os

RelationSet = EntitySet

GroupsMembers = RelationSet("groupsmembers",key="groupmemberid")
GroupsDatabase = EntitySet("groups",key="groupid")
PeopleDatabase = EntitySet("people",key="personid")

#
# This lot need dealing with more sensibly
#

def store_new_item(the_item): return GroupsMembers.new_record(the_item)
def read_database(): return GroupsMembers.read_database()
def store_item(item): return GroupsMembers.store_record(item)
def get_item(item): return GroupsMembers.get_record(item)
def delete_item(item): return GroupsMembers.delete_record(item)

#
# Map web request to data layer
#

def make_item(stem="form", **argd):
    new_item = {
        "groupid" : argd.get(stem + ".groupid",""),
        "groupname": argd.get(stem + ".groupname",""),