Package omeroweb :: Package webadmin :: Package controller :: Module enums
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webadmin.controller.enums

  1  #!/usr/bin/env python 
  2  #  
  3  #  
  4  #  
  5  # Copyright (c) 2008 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 omero.rtypes import * 
 26  from omero.model import AcquisitionModeI, ArcTypeI, BinningI, ContrastMethodI, \ 
 27                          ContrastMethodI, CorrectionI, DetectorTypeI, DimensionOrderI, \ 
 28                          EventTypeI, ExperimentTypeI, FamilyI, FilamentTypeI, FilterTypeI, \ 
 29                          FormatI, IlluminationI, ImmersionI, JobStatusI, LaserMediumI, \ 
 30                          LaserTypeI, MediumI, MicrobeamManipulationTypeI, MicroscopeTypeI, \ 
 31                          PhotometricInterpretationI, PixelsTypeI, PulseI, RenderingModelI 
 32   
 33  from webadmin.controller import BaseController 
 34   
35 -class BaseEnums(BaseController):
36 37 klass = None 38 enums = None 39 enumsCount = 0 40 entries = None 41 entriesCount = 0 42
43 - def __init__(self, conn, klass=None):
44 BaseController.__init__(self, conn) 45 if klass is not None and klass!="": 46 self.klass = klass 47 self.entries = list(self.conn.getEnumerationEntries(self.klass)) 48 else: 49 self.enums = self.conn.getEnumerationsWithEntries() 50 self.enumsCount = len(self.enums) 51 52 ext = self.enums 53 org = self.conn.getOriginalEnumerations() 54 55 result = set() 56 if len(ext.keys()) == len(org.keys()): 57 result.update(org.keys()) 58 else: 59 result.update(ext.keys()) 60 result.update(org.keys()) 61 62 check = dict() 63 for key in list(result): 64 o_enums = org.get(key) 65 e_enums = ext.get(key) 66 if o_enums is not None and e_enums is not None: 67 if len(o_enums) == len(e_enums): 68 for e in e_enums: 69 flag = False 70 for o in o_enums: 71 if o.value == e.value: 72 flag = True 73 break 74 check[key] = flag 75 if not flag: 76 break 77 else: 78 check[key] = False 79 self.check = check
80
81 - def saveEntry(self, entry):
82 obj = None 83 try: 84 obj = self.conn.getEnumeration(self.klass, entry)._obj 85 except: 86 pass 87 if obj is None: 88 obj = eval("%s" % (self.klass))() 89 obj.setValue(rstring(str(entry))) 90 self.conn.createEnumeration(obj)
91
92 - def saveEntries(self, entries):
93 new_entries = list() 94 for e in self.entries: 95 new_entry = rstring(str(entries[unicode(e.id)])) 96 new_entries.append(e._obj.setValue(new_entry)) 97 self.conn.updateEnumerations(new_entries)
98
99 - def deleteEntry(self, eid):
100 try: 101 obj = self.conn.getEnumerationById(self.klass, eid)._obj 102 if obj is not None: 103 self.conn.deleteEnumeration(obj) 104 except Exception, x: 105 raise AttributeError(x)
106
107 - def resetEnumerations(self):
108 self.conn.resetEnumerations(self.klass)
109