Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Add some error handling to the pad view
Browse files Browse the repository at this point in the history
  • Loading branch information
leylaso committed Mar 21, 2012
1 parent c48185c commit e89ceed
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
40 changes: 24 additions & 16 deletions etherpadlite/templates/etherpad-lite/pad.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@
{% block title %}{{pad.name}}{% endblock %}

{% block wrapper %}
{% if error %}
<div id="main">
<div id="errors">
<h2>Errors:</h2>
<p>{{error}}</p>
</div>
</div>
{% else %}
<iframe src="{{link}}?userName={{uname}}" style="height: 95%; width: 100%; min-height: 500px; display: block"></iframe>

<iframe src="{{link}}?userName={{uname}}" style="height: 95%; width: 100%; min-height: 500px; display: block"></iframe>
<script type="text/javascript">
/**
* This little script is necessary for some browsers that don't respect the
* height css attribute on iframes.
*/
function resizeEtherpad() {
height = jQuery(window).height()*94/100;
jQuery('#wrapper iframe').height(height);
}

<script type="text/javascript">
/**
* This little script is necessary for some browsers that don't respect the
* height css attribute on iframes.
*/
function resizeEtherpad() {
height = jQuery(window).height()*94/100;
jQuery('#wrapper iframe').height(height);
}

jQuery(document).ready( function() {
resizeEtherpad()
jQuery(window).resize(resizeEtherpad);
});
</script>
jQuery(document).ready( function() {
resizeEtherpad()
jQuery(window).resize(resizeEtherpad);
});
</script>
{% endif %}

{% endblock %}
28 changes: 22 additions & 6 deletions etherpadlite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,30 @@ def pad(request, pk):
server = urlparse(pad.server.url)
author = PadAuthor.objects.get(user=request.user)

# Create the session on the etherpad-lite side
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=config.SESSION_LENGTH)
sessReq = pad.server.url + 'api/1/createSession?apikey=' + pad.server.apikey + '&groupID=' + pad.group.groupID + '&authorID=' + author.authorID + '&validUntil=' + time.mktime(expires.timetuple()).__str__()
sessResp = simplecurl.json(sessReq)

# Verify the etherpad response and act accordingly
if sessResp['data'] is None or sessResp['code'] is not 0:
response = render_to_response('etherpad-lite/pad.html',
{'pad': pad,
'link': padLink,
'server':server,
'uname': author.user.__unicode__(),
'error':_('etherpad-lite session request returned:') + ' "' + sessResp['message'] + '"'},
context_instance=RequestContext(request))
return response


# Set up the response
response = render_to_response('etherpad-lite/pad.html',
{'pad': pad, 'link': padLink, 'server':server, 'uname': author.user.__unicode__()},
{'pad': pad,
'link': padLink,
'server':server,
'uname': author.user.__unicode__(),
'error':False},
context_instance=RequestContext(request))


Expand All @@ -100,11 +121,6 @@ def pad(request, pk):
response.delete_cookie('sessionID', server.hostname)
response.delete_cookie('padSessionID')

# Create the session on the etherpad-lite side
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=config.SESSION_LENGTH)
sessReq = pad.server.url + 'api/1/createSession?apikey=' + pad.server.apikey + '&groupID=' + pad.group.groupID + '&authorID=' + author.authorID + '&validUntil=' + time.mktime(expires.timetuple()).__str__()
sessResp = simplecurl.json(sessReq)

# Set the new session cookie for both the server and the local site
response.set_cookie('sessionID',
value=sessResp['data']['sessionID'],
Expand Down

0 comments on commit e89ceed

Please sign in to comment.