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

Source Code for Module omeroweb.webclient.controller.share

  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  import string 
 26  import datetime 
 27  import time 
 28   
 29  from omero.rtypes import * 
 30  from omero.model import ImageI, DatasetI, ProjectI 
 31   
 32  from webclient.controller import BaseController 
 33   
34 -class BaseShare(BaseController):
35 36 shares = None 37 shSize = None 38 ownShares = None 39 oshSize = 0 40 memberShares = None 41 mshSize = 0 42 43 share = None 44 imageInShare = None 45 imgSize = 0 46 membersInShare = None 47 48 comments = None 49 cmSize = None 50
51 - def __init__(self, conn, conn_share=None, share_id=None, **kw):
52 BaseController.__init__(self, conn) 53 if conn_share is None: 54 if share_id is not None: 55 self.share = self.conn.getShare(share_id) 56 if self.share is None: 57 raise AttributeError("We are sorry, but that share either does not exist, or if it does, you have not been invited to see it. Contact the user you think might own this share for more information.") 58 if self.share._obj is None: 59 raise AttributeError("We are sorry, but that share either does not exist, or if it does, you have not been invited to see it. Contact the user you think might own this share for more information.") 60 if self.share is not None and not self.share.active and not self.share.isOwned(): 61 raise AttributeError("%s is not active and cannot be visible. Please contact the user you think might own this share for more information." % self.share.getShareType()) 62 else: 63 self.conn_share = conn_share 64 self.share = self.conn.getShare(share_id) 65 if self.share is not None and not self.share.active and not self.share.isOwned: 66 raise AttributeError("%s is not active and cannot be visible. Please contact the user you think might own this share for more information." % self.share.getShareType()) 67 if self.share is None: 68 raise AttributeError("We are sorry, but that share either does not exist, or if it does, you have not been invited to see it. Contact the user you think might own this share for more information.") 69 if self.share._obj is None: 70 raise AttributeError("We are sorry, but that share either does not exist, or if it does, you have not been invited to see it. Contact the user you think might own this share for more information.")
71
72 - def createShare(self, host, blitz_id, image, message, members, enable, expiration=None):
73 # only for python 2.5 74 # d1 = datetime.strptime(expiration+" 23:59:59", "%Y-%m-%d %H:%M:%S") 75 expiration_date = None 76 if expiration is not None: 77 d1 = datetime.datetime(*(time.strptime((expiration+" 23:59:59"), "%Y-%m-%d %H:%M:%S")[0:6])) 78 expiration_date = long(time.mktime(d1.timetuple())+1e-6*d1.microsecond)*1000 79 ms = [str(m) for m in members] 80 81 self.conn.createShare(host, int(blitz_id), image, message, ms, enable, expiration_date)
82
83 - def createDiscussion(self, host, blitz_id, message, members, enable, expiration=None):
84 # only for python 2.5 85 # d1 = datetime.strptime(expiration+" 23:59:59", "%Y-%m-%d %H:%M:%S") 86 expiration_date = None 87 if expiration is not None: 88 d1 = datetime.datetime(*(time.strptime((expiration+" 23:59:59"), "%Y-%m-%d %H:%M:%S")[0:6])) 89 expiration_date = rtime(long(time.mktime(d1.timetuple())+1e-6*d1.microsecond)*1000) 90 ms = [long(m) for m in members] 91 92 self.conn.createShare(host, int(blitz_id), [], message, ms, enable, expiration_date)
93
94 - def updateShareOrDiscussion(self, host, blitz_id, message, members, enable, expiration=None):
95 # only for python 2.5 96 # d1 = datetime.strptime(expiration+" 23:59:59", "%Y-%m-%d %H:%M:%S") 97 expiration_date = None 98 if expiration is not None: 99 d1 = datetime.datetime(*(time.strptime((expiration+" 23:59:59"), "%Y-%m-%d %H:%M:%S")[0:6])) 100 expiration_date = long(time.mktime(d1.timetuple())+1e-6*d1.microsecond)*1000 101 102 old_groups = [m._obj for m in self.conn.getAllMembers(self.share.id)] 103 new_groups = [e._obj for e in self.conn.getObjects("Experimenter", members)] 104 105 add_mem = list() 106 rm_mem = list() 107 108 # remove 109 for ogr in old_groups: 110 flag = False 111 for ngr in new_groups: 112 if ngr.id.val == ogr.id.val: 113 flag = True 114 if not flag: 115 rm_mem.append(ogr) 116 117 # add 118 for ngr in new_groups: 119 flag = False 120 for ogr in old_groups: 121 if ogr.id.val == ngr.id.val: 122 flag = True 123 if not flag: 124 add_mem.append(ngr) 125 126 self.conn.updateShareOrDiscussion(host, int(blitz_id), self.share.id, message, add_mem, rm_mem, enable, expiration_date)
127
128 - def addComment(self, host, blitz_id, comment):
129 self.conn.addComment(host, int(blitz_id), self.share.id, comment)
130
131 - def getShares(self):
132 sh_list = list(self.conn.getOwnShares()) 133 sh_list.extend(list(self.conn.getMemberShares())) 134 sh_list.sort(key=lambda x: x.id, reverse=True) 135 sh_list_with_counters = list() 136 137 sh_ids = [sh.id for sh in sh_list] 138 if len(sh_ids) > 0: 139 sh_annotation_counter = self.conn.getCommentCount(sh_ids) 140 141 for sh in sh_list: 142 sh.annotation_counter = sh_annotation_counter.get(sh.id) 143 sh_list_with_counters.append(sh) 144 145 self.shares = sh_list_with_counters 146 self.shSize = len(self.shares)
147
148 - def getComments(self, share_id):
149 self.comments = list(self.conn.getComments(share_id)) 150 self.comments.sort(key=lambda x: x.creationEventDate()) 151 self.cmSize = len(self.comments)
152
153 - def removeImage(self, image_id):
154 self.conn.removeImage(self.share.id, image_id)
155
156 - def getMembers(self, share_id):
157 self.membersInShare = [m.id for m in self.conn.getAllMembers(share_id)]
158
159 - def getAllUsers(self, share_id):
160 self.allInShare = list(self.conn.getAllMembers(share_id))#list(self.conn.getAllUsers(share_id))
161
162 - def loadShareContent(self):
163 try: 164 if self.conn_share._shareId is not None: 165 content = self.conn_share.getContents(self.conn_share._shareId) 166 else: 167 raise AttributeError('Share was not activated.') 168 except: 169 raise AttributeError('Share was not activated.') 170 self.imageInShare = list() 171 172 for ex in content: 173 if isinstance(ex._obj, omero.model.ImageI): 174 self.imageInShare.append(ex) 175 176 self.imgSize = len(self.imageInShare)
177
178 - def loadShareOwnerContent(self):
179 content = self.conn.getContents(self.share.id) 180 181 self.imageInShare = list() 182 183 for ex in content: 184 if isinstance(ex._obj, omero.model.ImageI): 185 self.imageInShare.append(ex) 186 187 self.imgSize = len(self.imageInShare)
188