Exemplo n.º 1
0
def edit(id):
    branch = model_datastore.read(id)
    branch_parent_id = branch['branch_parent_id']
    #```````````````````````````````````````````````````````````
    # POST METHOD
    #```````````````````````````````````````````````````````````
    if request.method == 'POST':
        #Identify the parent
        branch_parent_id = request.form['branch_parent_id']
        #Fetch category name being updated
        name = request.form['name']
        sortorder = request.form['sortorder']

        if name:
            o = objects.clsBranch()
            o.set(name, branch_parent_id, sortorder)
            o.id = branch.id
            o.update()

        return redirect(url_for('.list', branch_id=branch_parent_id))

    #```````````````````````````````````````````````````````````
    # GET METHOD
    #```````````````````````````````````````````````````````````
    #Send output
    di = {
        "branch": branch,
        "branch_parent_id": branch_parent_id,
        "sortorder": branch['sortorder']
    }
    return utils.render_html("treemgr-edit.html", di)
Exemplo n.º 2
0
def add(branch_parent_id):
    #```````````````````````````````````````````````````````````
    # POST METHOD
    #```````````````````````````````````````````````````````````
    if request.method == 'POST':
        #Identify the parent
        branch_parent_id = request.form['branch_parent_id']
        #Fetch category names being added
        name1 = request.form['name1']
        name2 = request.form['name2']
        name3 = request.form['name3']
        name4 = request.form['name4']
        name5 = request.form['name5']
        sortorder1 = request.form['sortorder1']
        sortorder2 = request.form['sortorder2']
        sortorder3 = request.form['sortorder3']
        sortorder4 = request.form['sortorder4']
        sortorder5 = request.form['sortorder5']

        if name1:
            o1 = objects.clsBranch()
            o1.set(name1, branch_parent_id, sortorder1)
            o1.create()
        if name2:
            o2 = objects.clsBranch()
            o2.set(name2, branch_parent_id, sortorder2)
            o2.create()
        if name3:
            o3 = objects.clsBranch()
            o3.set(name3, branch_parent_id, sortorder3)
            o3.create()
        if name4:
            o4 = objects.clsBranch()
            o4.set(name4, branch_parent_id, sortorder4)
            o4.create()
        if name5:
            o5 = objects.clsBranch()
            o5.set(name5, branch_parent_id, sortorder5)
            o5.create()

        return redirect(url_for('.list', branch_id=branch_parent_id))

    #```````````````````````````````````````````````````````````
    # GET METHOD
    #```````````````````````````````````````````````````````````
    branch = {}

    #Compute next sort order for the form
    o = objects.clsBranch()
    o.branch_parent_id = branch_parent_id
    next_sortorder = o.get_next_sortorder()
    #Send output
    di = {
        "branch": branch,
        "branch_parent_id": branch_parent_id,
        "next_sortorder": next_sortorder
    }
    return utils.render_html("treemgr-add.html", di)
Exemplo n.º 3
0
def view(id):
    #```````````````````````````````````````````````````````````
    # GET METHOD
    #```````````````````````````````````````````````````````````
    branch = model_datastore.read(id)

    #Send output
    di = {
        "branch": branch,
    }
    return utils.render_html("treemgr-view.html", di)
Exemplo n.º 4
0
def list_leaves(branch_id):
    #```````````````````````````````````````````````````````````
    # GET METHOD
    #```````````````````````````````````````````````````````````
    #print("Inside content mgr view...")
    leaves = model_datastore.list_leaves(branch_id)
    branch = model_datastore.read_branch(branch_id)
    #Read and print each leaf with all its parameters
    di = {}
    lstleaves = []

    for content in leaves:
        obj = objects.clsLeaf()
        obj.id = content.id
        obj.branch_id = content['branch_id']
        obj.content_type_id = content['content_type_id']
        obj.source_doc_id = content['source_doc_id']
        if content['content_eng']:
            obj.content_eng = utils.remove_html_tags(content['content_eng'])
        if content['content_san']:
            obj.content_san = utils.remove_html_tags(content['content_san'])
        if content['content_kan']:
            obj.content_kan = utils.remove_html_tags(content['content_kan'])
        obj.content_type_name = config.DICT_CONTENT_TYPE[
            content['content_type_id']]
        obj.source_doc_name = config.DICT_SOURCEDOCS[content['source_doc_id']]
        #Add to list
        lstleaves.append(obj)
        del obj

    #Send output
    di = {
        "lstleaves": lstleaves,
        "catname": branch['name'],
        "branch_id": branch_id,
        "branch_parent_id": branch['branch_parent_id']
    }
    return utils.render_html("contentmgr-list.html", di)
Exemplo n.º 5
0
def list(branch_id):
    #```````````````````````````````````````````````````````````
    # GET METHOD
    #```````````````````````````````````````````````````````````
    isRoot = None
    if branch_id != '0':
        #Displaying children of selected category
        #First fetch all children for this branch
        branches = model_datastore.list(branch_id)
        #Determine page title name
        x = model_datastore.read(branch_id)
        if x:
            catname = x['name']
        else:
            catname = "Categories"
        #Find and Fetch next branch details
        #o = objects.clsBranch()
        #branch = o.read(branch_id)
        #next_branch = o.get_next_record()
        #next_branch_id = next_branch.id

    else:
        isRoot = True
        #Displaying root categories
        catname = "Root categories"
        branches = model_datastore.list('0')
        #next_branch_id = None

    #Send output
    di = {
        "isRoot": isRoot,
        "branches": branches,
        "catname": catname,
        "branch_parent_id": branch_id,
        #"next_branch_id": next_branch_id
    }
    return utils.render_html("treemgr-list.html", di)
Exemplo n.º 6
0
# get any data sent with the GET or POST request
# this may be required by multiple components
sent_data = cgi.FieldStorage()

# -------- START OF FUNCTIONAL COMPONENTS ----------->>>

# ---------- HANDLE REGISTRATION FORM SUBMISSIONS ----------

# check if login form was submitted
if 'btn_register' in sent_data:
    # it was, so call the login function
    result = components.register(db, sent_data)
    msg = result['msg']
else:
    # message displayed in register form will be empty
    msg = ""

#render html document containing form
print(utils.render_html(config['HTML'] + 'register.html', data=[msg]))

# ---------- HANDLE REGISTRATION FORM SUBMISSIONS ERRORS -----------

# check if registered already
if 'btn_register' in sent_data:
    # student is already registered?
    result = components.register(db, sent_data['registered'].value=True)
    msg = "Student is already registered."

# --------- /END OF COMPONENTS --------
Exemplo n.º 7
0
def edit(leaf_id):
    leaf = model_datastore.read_leaf(leaf_id)
    branch_id = leaf['branch_id']

    #```````````````````````````````````````````````````````````
    # POST METHOD
    #```````````````````````````````````````````````````````````
    if request.method == 'POST':
        leaf_id = leaf.id
        obj = objects.clsLeaf()
        content_eng = request.form['content_eng']
        content_san = request.form['content_san']
        content_kan = request.form['content_kan']
        obj.leaf_id = leaf_id
        obj.branch_id = branch_id
        obj.content_type_id = request.form['content_type_id']
        obj.source_doc_id = request.form['source_doc_id']

        if content_eng == "<div><br></div>":
            obj.content_eng = ""
        else:
            obj.content_eng = content_eng

        if content_san == "<div><br></div>":
            obj.content_san = ""
        else:
            obj.content_san = content_san

        if content_kan == "<div><br></div>":
            obj.content_kan = ""
        else:
            obj.content_kan = content_kan

        #Saving updated object in datastore and ES
        print("Updating Leaf/content to database...")
        if obj.update():
            print("---> Leaf updated!")
        else:
            print("---> Updating Leaf failed!!")
        return redirect(url_for('.list_leaves', branch_id=branch_id))

    #```````````````````````````````````````````````````````````
    # GET METHOD
    #```````````````````````````````````````````````````````````
    #Create leaf object and populate with all data
    obj = objects.clsLeaf()
    obj.populate_from_record(leaf)

    branch_name = ""
    branch = model_datastore.read_branch(branch_id)
    branch_name = branch['name']
    try:
        branch_parent = model_datastore.read_branch(branch.branch_parent_id)
        master_branch_name = branch_parent['name']
    except:
        master_branch_name = "Root"

    #Send output
    di = {
        "leaf": obj,
        "branch": branch,
        "branch_name": branch_name,
        "master_branch_name": master_branch_name,
        "branch_id": branch_id,
        "branch_parent_id": branch['branch_parent_id']
    }
    return utils.render_html("contentmgr-edit.html", di)
Exemplo n.º 8
0
def add(branch_id):
    #```````````````````````````````````````````````````````````
    # POST METHOD
    #```````````````````````````````````````````````````````````
    if request.method == 'POST':
        #Fetch content being added
        content_eng = request.form['content_eng']
        content_san = request.form['content_san']
        content_kan = request.form['content_kan']
        content_type_id = request.form['content_type_id']
        source_doc_id = request.form['source_doc_id']

        obj = objects.clsLeaf()
        obj.branch_id = branch_id
        obj.content_type_id = content_type_id
        obj.source_doc_id = source_doc_id

        if content_eng == "<div><br></div>":
            obj.content_eng = ""
        else:
            obj.content_eng = content_eng

        if content_san == "<div><br></div>":
            obj.content_san = ""
        else:
            obj.content_san = content_san

        if content_kan == "<div><br></div>":
            obj.content_kan = ""
        else:
            obj.content_kan = content_kan

        #Save object in datastore and ES
        print("Saving Leaf/content to database...")
        if obj.create():
            print("---> Leaf saved!")
        else:
            print("---> Saving Leaf failed!!")
        return redirect(url_for('.list_leaves', branch_id=branch_id))

    #```````````````````````````````````````````````````````````
    # GET METHOD
    #```````````````````````````````````````````````````````````
    branch = {}
    branch_name = ""
    branch = model_datastore.read_branch(branch_id)
    branch_name = branch['name']
    try:
        branch_parent = model_datastore.read_branch(branch.branch_parent_id)
        master_branch_name = branch_parent['name']
    except:
        master_branch_name = "Root"

    #Send output
    di = {
        "branch": branch,
        "branch_name": branch_name,
        "master_branch_name": master_branch_name,
        "branch_parent_id": branch['branch_parent_id'],
        "branch_id": branch_id,
    }
    return utils.render_html("contentmgr-add.html", di)
Exemplo n.º 9
0
def searchtest():
    di = {}
    return render_html("search2.html", di)