1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
65 """ Same as BaseContainer. Used to create identifier E.g. share-123 in right-hand panel """
66 return self.share.getShareType().lower()
67
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
74
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
85
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
95
96
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
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
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
130
147
152
155
158
161
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