Package omeroweb :: Package webclient :: Package controller
[hide private]
[frames] | no frames]

Source Code for Package omeroweb.webclient.controller

 1  #!/usr/bin/env python 
 2  #  
 3  #  
 4  #  
 5  # Copyright (c) 2008-2011 University of Dundee. 
 6  #  
 7  # This program is free software: you can redistribute it and/or modify 
 8  # it under the terms of the GNU Affero General Public License as 
 9  # published by the Free Software Foundation, either version 3 of the 
10  # License, or (at your option) any later version. 
11  #  
12  # This program is distributed in the hope that it will be useful, 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15  # GNU Affero General Public License for more details. 
16  #  
17  # You should have received a copy of the GNU Affero General Public License 
18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
19  #  
20  # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008. 
21  #  
22  # Version: 1.0 
23  # 
24   
25  from django.conf import settings 
26  PAGE = settings.PAGE 
27   
28 -class BaseController(object):
29 30 conn = None 31 eContext = dict() 32
33 - def __init__(self, conn, **kw):
34 self.conn = conn 35 self.eContext['image_limit'] = PAGE 36 self.eContext['context'] = self.conn.getEventContext() 37 gr = self.conn.getObject("ExperimenterGroup", self.conn.getEventContext().groupId) 38 self.eContext['isReadOnly'] = gr.isReadOnly() 39 self.eContext['isLeader'] = gr.isLeader() 40 if not gr.isPrivate() and not gr.isReadOnly(): 41 self.eContext['isEditable'] = True 42 else: 43 self.eContext['isEditable'] = False 44 self.eContext['user'] = self.conn.getUser() 45 grs = list(self.conn.getGroupsMemberOf()) 46 grs.sort(key=lambda x: x.getName().lower()) 47 self.eContext['memberOfGroups'] = grs 48 self.eContext['allGroups'] = grs 49 self.eContext['advice'] = None
50
51 - def getShareId(self):
52 return self.conn._shareId
53 54 ########################################################### 55 # Paging 56
57 - def doPaging(self, page, page_size, total_size, limit=PAGE):
58 total = list() 59 t = (total_size/limit) + (total_size%limit > 0 and 1 or 0) 60 if total_size > (limit*10): 61 if page > 10 : 62 total.append(-1) 63 for i in range((1, page-9)[ page-9 >= 1 ], (t+1, page+10)[ page+9 < t ]): 64 total.append(i) 65 if page < t-9: 66 total.append(-1) 67 68 elif total_size > limit and total_size <= (limit*10): 69 for i in range(1, t+1): 70 total.append(i) 71 else: 72 total.append(1) 73 next = None 74 if page_size == limit and (page*limit) < total_size: 75 next = page + 1 76 prev = None 77 if page > 1: 78 prev = page - 1 79 if len(total)>1: 80 return {'page': page, 'total':total, 'next':next, "prev":prev} 81 return None
82