blob: 7b597715de8ded33e0cf3d0bfeb8014c428ca030 (
plain)
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
27
28
29
30
31
32
33
34
35
|
'''
Created on Feb 3, 2011
@author: leifj
'''
from django.db import models
from django.db.models.fields import CharField, URLField, TextField, IntegerField
import re
class ACCluster(models.Model):
api_url = URLField()
url = URLField()
user = CharField(max_length=128)
password = CharField(max_length=128)
name = CharField(max_length=128,blank=True,unique=True)
default_template_sco_id = IntegerField(blank=True,unique=True)
domain_match = TextField()
def __unicode__(self):
return self.url
def make_url(self,path=""):
return "%s%s" % (self.url,path)
def acc_for_user(user):
(local,domain) = user.username.split('@')
if not domain:
#raise Exception,"Improperly formatted user: %s" % user.username
domain = "nordu.net" # testing with local accts only
for acc in ACCluster.objects.all():
for regex in acc.domain_match.split():
if re.match(regex,domain):
return acc
raise Exception,"I don't know which cluster you belong to... (%s)" % user.username
|