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

Source Code for Module omeroweb.webadmin.custom_models

 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  from django.utils.encoding import smart_unicode, force_unicode 
25   
26 -class Server(object):
27
28 - def __init__ (self, pk, host, port, server=None):
29 self.id = pk 30 self.host = host 31 self.port = port 32 self.server = None 33 if server is not None and server != '': 34 self.server = server
35
36 - def __repr__(self):
37 """ 38 Json for printin settings.py: [["localhost", 4064, "omero"]]' 39 """ 40 return """["%s", %s, "%s"]""" % (self.host, self.port, self.server)
41
42 - def __str__(self):
43 if hasattr(self, '__unicode__'): 44 return force_unicode(self).encode('utf-8') 45 return '%s object' % (self.__class__.__name__)
46
47 - def __unicode__(self):
48 return str(self.id)
49 50
51 -class ServerObjects(object):
52
53 - def __init__ (self, glist):
54 self.blitz_list = list() 55 i = 1 56 for s in glist: 57 self.blitz_list.append(Server(pk=i, host=s[0], port=s[1], server=s[2])) 58 i+=1
59
60 - def get(self, pk):
61 try: 62 pk = int(pk) 63 except: 64 pass 65 else: 66 for b in self.blitz_list: 67 if b.id == pk: 68 return b 69 return None
70
71 - def find(self, server_host):
72 for b in self.blitz_list: 73 if b.host == server_host: 74 return b 75 return None
76
77 - def all(self):
78 return self.blitz_list
79
80 - def __repr__(self):
81 return repr(self.blitz_list)
82