Example #1
0
 def GET(self, name=None):
     user = model.get_user(name=name)
     if user:
         pages = model.get_pages(item_user=user.name)
         comments_on = model.get_comments(session.user.name, item_user=user.name)
         comments_by = model.get_comments(session.user.name, user_name=user.name)
         return render.user(user.name, pages, comments_on, comments_by)
Example #2
0
 def GET(self):
     if session.user.name == "Anonymous":
         raise web.seeother("/dashboard/login")
     pages = model.get_pages(item_user=session.user.name, limit=10)
     comments_on = model.get_comments(session.user.name, item_user=session.user.name, limit=5)
     comments_by = model.get_comments(session.user.name, user_name=session.user.name, limit=5)
     private_messages = model.get_messages(session.user.name, limit=5)
     return render.dashboard(session.user.name, pages, comments_on, comments_by, private_messages)
Example #3
0
 def GET(self, n):
     """ get issue json  """
     n = int(n)
     web.header('Content-Type', 'application/json')
     dout = {};
     dout["success"] = True
     dout["message"] = list(model.get_comments(n))
     print json.dumps(dout,sort_keys=True,indent=2,default=json_serial)
     return json.dumps(dout,sort_keys=True,indent=2,default=json_serial)
Example #4
0
 def POST(self, blogid):
     form = self.form()
     if not form.validates():
         post = model.get_post(int(blogid))
         comments = model.get_comments(int(blogid))
         return render.view(post, comments, form)
     else:
         model.new_comment(blogid, form.d.author, form.d.comment)
         web.seeother("/view/" + blogid)
Example #5
0
def homepage():
    """Geeft de homepagina weer."""

    # Als de gebruiker via POST kwam.
    if request.method == "POST":

        # Naar approute comment gaan als er op comment geklikt is.
        if request.form.get("comment"):
            session["image_id"] = request.form.get("comment")
            return redirect(url_for("comment"))

        # Foto's weergeven.
        else:
            pictures = model.display()
            get_comment = model.get_comments()
            return render_template("homepage.html", images=pictures, comments=get_comment)

    # Als de gebruiker via GET de route bereikt heeft.
    else:
        pictures = model.display()
        get_comment = model.get_comments()
        return render_template("homepage.html", images=pictures, comments=get_comment)
Example #6
0
 def GET(self, id):
     """ View single post """
     # TODO: make the post test render as htmnl
     post = model.get_post(int(id))
     user = model.getUserById(post.user_id)
     comments = model.get_comments(int(id))
     renderedComments = ""
     if comments:
         renderedComments = renderInsert.comments(comments, model)
     votes = model.get_votes(id)
     lUser = auth.getUser()
     if lUser:
         hasUserVoted = model.hasUserVoted(auth.getUser().user_id, post.id)
     else:
         hasUserVoted = False
     return render.view(post, user, renderedComments, self.form, hasUserVoted, votes)
Example #7
0
 def GET(self, id=None):
     if id:
         comment = model.get_comment(id)
         return render.comment_list([comment], form)
     else:
         inp = web.input(item_host=None, item_path=None, item_name=None)
         related_pages = []
         related_items = []
         if inp.item_host and inp.item_path and inp.item_name:
             related_pages = model.db.select('cot_comment',
                 what="DISTINCT item_path AS page",
                 where="(item_host=$item_host)",
                 order="item_path",
                 limit=20,
                 vars={'item_host': inp.item_host}
             )
             related_items = model.db.select('cot_comment',
                 what="DISTINCT item_name AS item",
                 where="(item_host=$item_host) AND (item_path=$item_path)",
                 order="item_name",
                 limit=20,
                 vars={'item_host': inp.item_host, 'item_path': inp.item_path}
             )
         elif inp.item_host and inp.item_path:
             related_pages = model.db.select('cot_comment',
                 what="DISTINCT item_path AS page",
                 where="(item_host=$item_host)",
                 order="item_path",
                 limit=20,
                 vars={'item_host': inp.item_host}
             )
             related_items = model.db.select('cot_comment',
                 what="DISTINCT item_name AS item",
                 where="(item_host=$item_host) AND (item_path=$item_path)",
                 order="item_name",
                 limit=20,
                 vars={'item_host': inp.item_host, 'item_path': inp.item_path}
             )
         comments = model.get_comments(session.user.name, item_host=inp.item_host, item_path=inp.item_path, item_name=inp.item_name)
         return render.comment_list(comments, inp, related_pages, related_items)
Example #8
0
 def POST(self,id):
     web.header('Content-Type', 'application/json')
     dout = {}
     din = json.loads(web.data().decode("utf-8-sig"));
     
     print "din: " + json.dumps(din,sort_keys=True,indent=2)
     if not din["parent"]:
         din["parent"] = 0;# root mao
     try:
         if not "title" in din:
             # print "add title."
             din["title"] = "";
         n = model.new_issue(din["title"],din["detail"],din["parent"],din["user"],din["isArticle"])
         dout["success"] = True
         if din["parent"]:
             dout["message"] = list(model.get_comments(din["parent"]))
     except KeyError:
         dout["success"] = False
         dout["errors"] = "Title is required."
     finally:
         # print json.dumps(dout,sort_keys=True,indent=2,default=json_serial)
         return json.dumps(dout,sort_keys=True,indent=2,default=json_serial)
Example #9
0
def ajax():
    # Utility entry point for various functions that are triggered by the javascript.
    action = request.args['action']
    log_access('ajax', 'query' + request.query_string)

    # AutoSaveForm is used to recover any edits on the calls when users browser closes for an unintended reason.
    if action == 'setautosaveform':
        model.set_autosave_form(request.args['key'], json.dumps(request.form))

    elif action == 'getautosaveform':
        return model.get_autosave_form(request.args['key'])

    elif action == 'deleteautosaveform':
        model.delete_autosave_form(request.args['key'])

    # Templates are quick text blobs used for editing the calls.
    elif action == 'gettemplatelist':
        return json.dumps(model.get_template_list())

    elif action == 'addtemplate':
        id = model.add_template(request.form)
        return json.dumps(model.get_template(id))

    elif action == 'settemplate':
        model.set_template(request.form)
        return json.dumps(model.get_template(request.form['id']))

    elif action == 'deletetemplate':
        model.delete_template(request.form['id'])

    elif action == 'startemplate':
        return json.dumps(model.star_template(request.form['id']))

    elif action == 'getresidentsstarredtemplates':
        return json.dumps(model.get_residents_starred_templates())

    # Commenting related functions
    elif action == 'addcomment':
        model.add_comment(request.args['key'], request.form['comment'])
        return json.dumps(model.get_comments(request.args['key']))

    elif action == 'deletecomment':
        id = request.args['comment_id']
        comment = model.get_comment(id)
        if session['user_auth_level'] >= 10000 or comment['username'] == session['user_username']: # administrator
            model.delete_comment(id)

    elif action == 'savecomment':
        id = request.args['comment_id']
        comment = model.get_comment(id)
        if session['user_auth_level'] >= 10000 or comment['username'] == session['user_username']: # administrator
            model.edit_comment(id, request.form['comment'])

    elif action == 'getcomments':
        call_id = request.args['key']
        comments = model.get_comments(call_id)
        for comment in comments:
            comment['blob'] = text_process(comment['blob'])
        return json.dumps(comments)

    # Deletes a call record.
    elif action == 'deletecalllog':
        key = request.args['key']
        if session['user_auth_level'] >= 10000 \
                or (model.is_call_log_owner(session['user_id'], key) and model.get_call_log(key)['created'] >= datetime.today() - timedelta(days=config.DISABLE_EDIT_AGE)): #  administrator
            model.delete_call_log(key)

    # Returns calls of a specific patient by the patients hospital number.
    elif action == 'searchforpatientnumber':
        key = request.args['key']
        key = key.strip()
        return json.dumps(model.get_calls_by_patient_number(key))

    # Tag related
    elif action == 'deletetag':
        model.delete_tag(request.args['tag'])

    elif action == 'saveTagChange':
        model.save_tag_change_for_call(int(request.args['id']), request.args['tag'], int(request.args['added']))

    # Liking a call, currently there is no limit on how many times you can like a record.
    elif action == 'like':
        key = int(request.args['id'])
        model.like_call_log(key)
        call = model.get_call_log(key)
        return str(call['liked'])

    # Flags a record
    elif action == 'flag':
        key = int(request.args['id'])
        flag = int(request.args['flag'])
        flag_state = model.get_flag(request.args['id'])
        if flag_state == flag:
            model.delete_flag(request.args['id'])
        else:
            model.set_flag(key, flag)

        return str(model.get_flag(request.args['id']))

    return '1'
Example #10
0
		assert(post and post.author_id == 1 and post.title == 'title' and post.content == 'content' and post.excerpt== None and post.slug == None and post.post_type=='blog' and post.comment_status=='open' and post.post_status=='published')
	
	model.delete_post(post_id)
	model.delete_post(another_post_id)
	posts = model.get_posts()
	assert(not posts)
	
	post_id = model.new_post(1, 'title', 'content', None, None, 'blog', 'open', 'published', None, None)
	assert(post_id)

	for i in range(0, 10):
		author = 'author %d' %i
		content = 'comment %d' %i
		model.new_comment(post_id, author, '192.168.1.1', 'firefox 4.0', content)

	comments = model.get_comments()
	assert(comments and len(comments) == 10 and model.get_comment_num(post_id) == 10)

	ci = 9 
	for c in comments:
		assert(c.post_id == post_id and c.author == 'author %d' %ci and c.author_ip == '192.168.1.1' and c.comment_agent == 'firefox 4.0' and c.content == 'comment %d' %ci and c.url == None and c.email == None and c.reply_notify_mail == False)
		ci -= 1

	############start test category, now there is only default category.
	cid1 = model.new_category('category 1', 0, 'description 1')

	categories = model.get_all_categories()

	assert(len(categories) == 2 and cid1 > 0)

	for c in categories:
Example #11
0
 def GET(self, blogid):
     post = model.get_post(int(blogid))
     comments = model.get_comments(int(blogid))
     form = self.form()
     return render.view(post, comments, form)