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  # -*- coding: utf-8 -*- 
  3  #  
  4  #  
  5  #  
  6  # Copyright (c) 2008-2011 University of Dundee. 
  7  #  
  8  # This program is free software: you can redistribute it and/or modify 
  9  # it under the terms of the GNU Affero General Public License as 
 10  # published by the Free Software Foundation, either version 3 of the 
 11  # License, or (at your option) any later version. 
 12  #  
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU Affero General Public License for more details. 
 17  #  
 18  # You should have received a copy of the GNU Affero General Public License 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 20  #  
 21  # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008. 
 22  #  
 23  # Version: 1.0 
 24  # 
 25   
 26  import string 
 27  import datetime 
 28  import time 
 29   
 30  from omero.rtypes import * 
 31  from omero.model import ImageI, DatasetI, ProjectI 
 32   
 33  from webclient.controller import BaseController 
 34   
35 -class BaseShare(BaseController):
36 37 shares = None 38 shSize = None 39 ownShares = None 40 oshSize = 0 41 memberShares = None 42 mshSize = 0 43 44 share = None 45 imageInShare = None 46 imgSize = 0 47 membersInShare = None 48 49 comments = None 50 cmSize = None 51
52 - def __init__(self, conn, share_id=None, **kw):
53 BaseController.__init__(self, conn) 54 55 if share_id is not None: 56 self.share = self.conn.getShare(share_id) 57 if self.share is None: 58 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.") 59 if self.share._obj is None: 60 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.") 61 if self.share is not None and not self.share.active and not self.share.isOwned(): 62 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())
63
64 - def obj_type(self):
65 """ Same as BaseContainer. Used to create identifier E.g. share-123 in right-hand panel """ 66 return self.share.getShareType().lower()
67
68 - def obj_id(self):
69 """ Same as BaseContainer. Used to create identifier E.g. share-123 in right-hand panel """ 70 return self.share.getId()
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 return 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(), reverse=True) 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 content = self.conn.getContents(self.share.id) 164 165 self.imageInShare = list() 166 167 for ex in content: 168 if isinstance(ex._obj, omero.model.ImageI): 169 self.imageInShare.append(ex) 170 171 self.imgSize = len(self.imageInShare)
172