From 731b9058b0d6f7c3395c4823ebc3b9952ef37ce1 Mon Sep 17 00:00:00 2001 From: Huy Hoang Date: Fri, 11 Oct 2013 16:35:20 +0700 Subject: [PATCH] view detail a note --- src/api.py | 5 +- src/mobile.py | 37 ++++++++ src/templates/mobile/note.html | 162 +++++++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 src/templates/mobile/note.html diff --git a/src/api.py b/src/api.py index 86944a9..37197fb 100755 --- a/src/api.py +++ b/src/api.py @@ -3917,8 +3917,9 @@ def restore_doc(session_id, doc_id, revision): doc_id = update_note(session_id, doc_id, doc.get('content'), doc.get('tags')) return doc_id -def get_note(session_id, note_id, version=None): - db_name = get_database_name() +def get_note(session_id, note_id, version=None, db_name=None): + if not db_name: + db_name = get_database_name() db = DATABASE[db_name] info = db.stream.find_one({'_id': long(note_id), diff --git a/src/mobile.py b/src/mobile.py index 866f080..e38d62a 100644 --- a/src/mobile.py +++ b/src/mobile.py @@ -275,7 +275,44 @@ def group(group_id='public', view='group', page=1): settings=settings, view=view) + + +@app.route("/note/", methods=["GET", "OPTIONS"]) +def note(note_id=None, action=None, version=None): + session = request.headers.get('X-Session') + if not session: + authorization = request.headers.get('Authorization') + app.logger.debug(request.headers.items()) + + if not authorization or not authorization.startswith('session '): + abort(401) + + session = authorization.split()[-1] + session = SecureCookie.unserialize(session, settings.SECRET_KEY) + + session_id = session.get('session_id') + network = session.get('network') +# utcoffset = session.get('utcoffset') + + db_name = '%s_%s' % (network.replace('.', '_'), + settings.PRIMARY_DOMAIN.replace('.', '_')) + + user_id = api.get_user_id(session_id, db_name=db_name) + if not user_id: + abort(401) + + owner = api.get_user_info(user_id, db_name=db_name) + note = api.get_note(session_id, note_id, + db_name=db_name) + + mode = 'view' + return render_template('mobile/note.html', + view='notes', + mode=mode, + note=note, + owner=owner) + @app.route('/notifications') def notifications(): session = request.headers.get('X-Session') diff --git a/src/templates/mobile/note.html b/src/templates/mobile/note.html new file mode 100644 index 0000000..69dea91 --- /dev/null +++ b/src/templates/mobile/note.html @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + +
  • + + +{% if mode == 'view' %} + {% set viewers = note.viewers | exclude(note.owner.id) %} + + + + + +{% endif %} + + + +
    +
    + {% if owner.id %} +
    + + + + + + +
    + + {% endif %} + + +
    + {% autoescape on %}{{ note.title }}{% endautoescape %} +
    + + Saved + + + + + + + {% if owner %} + {% if not viewers %} + + + + {% elif note.is_public() %} + + + + {% else %} + + + + {% endif %} + + {% endif %} + + +
    + +
    +
    + + {% if mode == 'view' %} + {% autoescape on %} + {{ note.content | sanitize | fix_unclosed_tags }} + {% endautoescape %} + + {% if note.attachments %} +
    + {% for file in note.attachments %} + + {{ file.name | truncate(50, True)}} +
    + {% endfor %} + {% endif %} + {% endif %} +
    + +
    +
  • +