Permalink
Browse files

Add some error handling to the pad view

  • Loading branch information...
1 parent c48185c commit e89ceed4b9d3e714681ad0d6e155fef4c3eb4f6b @sfyn committed Mar 21, 2012
Showing with 46 additions and 22 deletions.
  1. +24 −16 etherpadlite/templates/etherpad-lite/pad.html
  2. +22 −6 etherpadlite/views.py
@@ -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 %}
View
@@ -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))
@@ -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'],

0 comments on commit e89ceed

Please sign in to comment.