Skip to content

Commit

Permalink
put a name in shared link
Browse files Browse the repository at this point in the history
  • Loading branch information
emillon committed Dec 17, 2014
1 parent 1892121 commit d45d354
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def delete_doc(id):


class ShareForm(Form):
pass
name = TextField('Name', description='The person you are giving this link to')


def shared_link_serializer():
Expand All @@ -352,13 +352,20 @@ def shared_link_serializer():

@bp.route('/view/<id>/share', methods=['POST'])
def share_doc(id):
data = {'doc': id}
h = shared_link_serializer().dumps(data)
return jsonify(data=h)
form = ShareForm()
if form.validate_on_submit():
data = {'doc': id,
'name': form.name.data,
}
h = shared_link_serializer().dumps(data)
return jsonify(data=h)
return BadRequest()


@bp.route('/view/shared/<key>')
def view_shared_doc(key):
data = shared_link_serializer().loads(key)
docid = data['doc']
name = data['name']
flash("Hello, {}!".format(name))
return redirect(url_for('.view_doc', id=docid))
1 change: 1 addition & 0 deletions static/coffee/view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ view_init_common = (docid) ->
$.ajax
type: 'POST'
url: "/view/#{docid}/share"
data: $(this).serialize()
success: (data) ->
share_url = "#{window.location.origin}/view/shared/#{data['data']}"
input = $('<input>').attr('type', 'text').val(share_url)
Expand Down
1 change: 1 addition & 0 deletions templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<form method="post" enctype="multipart/form-data" id="share_form">
{{ form.hidden_tag() }}
{{ form_field(form.name) }}
<button type="submit" class="btn btn-primary">Generate</button>
</form>
{% endmacro %}
Expand Down

0 comments on commit d45d354

Please sign in to comment.