Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit 7aad22af38cee227f09d3eeac1748592b7ad217d

  • avatar
  • Sebastian Silva <sebastian @somos…car.org>
  • Mon Apr 22 05:06:16 EDT 2013
fix offline nickname & enable offline notifications
  
3535import tempfile
3636
3737from sugar_network import client
38from sugar_network.toolkit.http import NotFound
3839from client import Client
3940
4041_BUFFER_SIZE = 1024 * 10
105105 conf = gconf.client_get_default()
106106 return conf.get_string('/desktop/sugar/user/color').split(',')
107107
108def get_user():
109 import gconf
110 conf = gconf.client_get_default()
111 return conf.get_string('/desktop/sugar/user/nick')
108112
113
109114def get_documents_path():
110115 """Gets the path of the DOCUMENTS folder
111116
141141 stroke, fill = get_colors()
142142 kwvar = {
143143 'userid': client.sugar_uid(),
144 'sugar_nick' : get_user()
144145 }
145146 return dict(stroke=stroke, fill=fill, **kwvar)
146147
150150def before_request():
151151 g.home_mount = home_mount
152152 g.network_mount = network_mount
153 if 'connected' not in session:
154 session['connected'] = network_mount.client.inline
155 if session['connected'] and not network_mount.client.inline:
156 session['connected'] = False
153 session['connected'] = network_mount.client.inline
157154 if not session['connected']:
158155 g.client = home_mount.client
159156 g.Contexts = home_mount.Contexts
184184def incoming(event):
185185 global _pull_events
186186 _pull_events.append(event)
187 #if event['event']=='inline' and event.get('state')=='offline':
188 # session['connected'] = False
189 #if event['event']=='inline' and event.get('state')=='online':
190 # session['connected'] = True
187191 return None
188192_pull_listener = Client.connect(incoming)
189193
485485
486486@app.errorhandler(404)
487487def page_not_found(error):
488 template = 'browser-view.html'
489 return render_template(template, total=0, info=_('Error'),
490 resource_type='context', query='', total_pages=0,
491 browser_view='true', result=[], type='context',
492 meta=_('Object not found.'), page=1), 404
488 title = _('Object not found.')
489 body = _('The resource you are looking for '\
490 + 'is not available at the moment.\n\n'\
491 + 'If you are offline try connecting.');
492 return render_template('dialog.html', title=title, body=body)
493493
494494
495495@app.errorhandler(500)
518518 else:
519519 session['page'] = int(request.args['_preload'])
520520 session.modified = True
521 logging.debug("page " + str(page) + " preload " + str(preload))
522 logging.debug("session-page " + str(session['page']))
523521 except KeyError:
524522 return redirect(url_for('context_grid',
525523 type=request.args.get('type'),
609609 'summary', 'favorite', 'clone', 'type'])
610610 try:
611611 session['last_context_title'] = context['title']
612 except RuntimeError:
612 except NotFound:
613613 abort(404)
614614 session['last_context'] = context['guid']
615615 session.modified = True
653653 'summary', 'favorite', 'clone', 'type'])
654654 try:
655655 session['last_context_title'] = context['title']
656 except RuntimeError:
656 except NotFound:
657657 abort(404)
658658 session['last_context'] = context['guid']
659659 session.modified = True
761761 session['last_context'] = context['guid']
762762 session['last_context_title'] = context['title']
763763 session.modified = True
764 except RuntimeError:
764 except NotFound:
765765 abort(404)
766766
767767 stroke, fill = get_colors()
  
3636 </a>
3737 </div>
3838 <div class="mtime">
39 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
39 {% if (session['connected'] or False) %}
40 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
41 {% else %}
42 {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}}
43 {% endif %}
4044 </div>
4145 <div class="resource-meta">
4246 {%- for tag in item['tags'] %}
  
66 <img class="comment-icon" src="/static/icons/comments.png" />
77 <div class="comment-content">{{item['message']}}</div>
88 </div>
9 <div class='mtime mtime-comment'>{{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
9 <div class='mtime mtime-comment'>
10 {% if (session['connected'] or False) %}
11 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
12 {% else %}
13 {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}}
14 {% endif %}
15
1016 {%- if item.is_author -%}
1117 <span class="delete-comment-button has_tooltip" title="{{_('delete')}}" data-guid="{{item['guid']}}"><img class="action-button" src="/static/icons/edit-delete.png"></img></span>
1218 {%- endif -%}
  
3636 </a>
3737 </div>
3838 <div class="mtime">
39 {% if (session['connected'] or False) %}
3940 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
41 {% else %}
42 {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}}
43 {% endif %}
4044 </div>
4145 <div class="resource-meta">
4246 {%- for tag in item['tags'] %}
  
3131 {{item['content']}}
3232 </div>
3333 <div class='mtime'>
34 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
34 {% if (session['connected'] or False) %}
35 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
36 {% else %}
37 {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}}
38 {% endif %}
3539 </div>
3640 <div class="resource-meta">
3741 {%- for tag in item['tags'] %}
  
1111 <div class="resource-content">
1212 <pre>{{resource['content']|safe}}</pre>
1313 </div>
14 <div class='mtime'>{{_('by %(author)s on %(date)s', author=resource['author'][0]['name'], date=resource['mtime']|timedelta)}}
14 <div class='mtime'>
15 {% if (session['connected'] or False) %}
16 {{_('by %(author)s on %(date)s', author=resource['author'][0]['name'], date=resource['mtime']|timedelta)}}
17 {% else %}
18 {{_('by %(author)s on %(date)s', author=sugar_nick, date=resource['mtime']|timedelta)}}
19 {% endif %}
1520 </div>
1621 <div class="resource-meta">
1722 {%- for tag in resource['tags'] %}
6666 {{item['content']|safe}}
6767 </div>
6868 <div class='mtime'>
69 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
69 {% if (session['connected'] or False) %}
70 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
71 {% else %}
72 {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}}
73 {% endif %}
7074 </div>
7175 <div class="resource-meta">
7276 {%- for tag in item['tags'] %}
  
2929 {{item['content']}}</a>
3030 </div>
3131 <div class="resource-meta">
32 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
32 {% if (session['connected'] or False) %}
33 {{_('by %(author)s on %(date)s', author=item['author'][0]['name'], date=item['mtime']|timedelta)}}
34 {% else %}
35 {{_('by %(author)s on %(date)s', author=sugar_nick, date=item['mtime']|timedelta)}}
36 {% endif %}
37
3338 {%- for tag in item['tags'] %}
3439 <span class="tag">{{tag}}</span>
3540 {%- endfor %}
  
99 <script src="/static/js/jquery.history.js"></script>
1010 <script src="/static/js/jquery-ui-1.8.16.sugar.min.js" type="text/javascript"></script>
1111 <script src="/static/js/jquery.livequery.min.js" type="text/javascript" charset="utf-8"></script>
12 <!--script src="/static/js/toastr.js"></script-->
13 <!--link href="/static/css/toastr.css" rel="stylesheet"/-->
12 <script src="/static/js/toastr.js"></script>
13 <link href="/static/css/toastr.css" rel="stylesheet"/>
1414 <!--script src="/static/js/sticky.full.js" type="text/javascript"></script-->
1515 <!--link rel="stylesheet" href="/static/css/sticky.full.css" type="text/css" /-->
1616 <style>
398398 };
399399
400400 $(document).ready( function() {
401 /*
402 sse = new EventSource('/my_event_source');
401 sse = new EventSource('/my_event_source');
403402
404403 sse.onmessage = function(message) {
405404 data = $.parseJSON(message.data);
406405 if (data.event=="inline" && data.state=="offline") {
407406 toastr.info('Your are now in offline mode.');
408407 $('#sn-button-img').removeClass('sugar-network-online');
408 location.reload();
409 // TODO: proper ajaxy reload
409410 }
410411 if (data.event=="inline" && data.state=="online") {
411412 toastr.info('Your are now in online mode.');
412413 $('#sn-button-img').addClass('sugar-network-online');
414 location.reload();
415 // TODO: proper ajaxy reload
413416 }
417 /* TODO: Handle these
414418 if (data.event=="push") {
415419 toastr.info('Sugar Network is synchronized.');
416420 }
417421 if (data.event=="create") {
418422 toastr.warning('New ' + data.props.type[0]);
419423 }
420 console.log('A message has arrived!');
424 console.log('A message has arrived!');*/
421425 }
422 */
423426
424427 $( "#sn-button" ).tooltip({position:"bottom right", offset:[-3,-60], predelay:500});
425428 $( "#browser-button" ).tooltip({position:"bottom right", offset:[-3,-60], predelay:500});
486486 var term = $('#query').val();
487487 if(e.keyCode == 13 && _selected==false) {
488488 location='/context/search/'+term;
489 /* For adding tag filters */
490 /** if (term[0]=='#') {
491 /* Send the data using post *
492 $('#query').val('{{query or ''}}');
493 $.post( '/_tags', { tag:term },
494 function( data ) {
495 $( "#tags-section" ).empty().append( data );
496 /* bind_del(); *
497 location.reload();
498 }
499 );
500 }
501 else {
502 /* location='/resource/{{resource_type}}s/'+term; *
503 location='/context/search/'+term;
504 }*/
505489 return false; //prevents form from being submitted.
506490 }
507491 }
  
8989 <img class="toolbar-icon" src="/static/icons/list-add.png" />
9090 </div>
9191 </li-->
92 <!-- TODO: useful until properly updating cursor on events -->
93 <li class="toolbar-items" onclick="location.href='/reload'+location.pathname;">
94 <div class="toolbar-button has_tooltip" title="{{_('reload')}}">
95 <img class="toolbar-icon" src="/static/icons/reload.png" />
96 </div>
97 </li>
9298 <li class="toolbar-items" onclick="location='/project/new?returnto=' + location.href">
9399 <div class="toolbar-button has_tooltip" title="{{_('create new context')}}">
94100 <img class="toolbar-icon" src="/static/icons/go-up.png" />
105105 <img class="toolbar-icon" src="/static/icons/activity-about.png" />
106106 </div>
107107 </li>
108
109 <!--li class="toolbar-items" onclick="location.href='/reload'+location.pathname;">
110 <div class="toolbar-button has_tooltip" title="{{_('reload')}}">
111 <img class="toolbar-icon" src="/static/icons/reload.png" />
112 </div>
113 </li-->
114108 </ul>
115109 </div>