user.get_profile()->user.profile
This commit is contained in:
parent
3e8f28ff47
commit
1cc795995d
27 changed files with 72 additions and 70 deletions
|
@ -103,7 +103,7 @@ class Annotation(models.Model):
|
|||
|
||||
def editable(self, user):
|
||||
if user.is_authenticated():
|
||||
if user.get_profile().capability('canEditAnnotations') or \
|
||||
if user.profile.capability('canEditAnnotations') or \
|
||||
self.user == user or \
|
||||
user.groups.filter(id__in=self.item.groups.all()).count() > 0:
|
||||
return True
|
||||
|
|
|
@ -170,7 +170,7 @@ def addAnnotation(request, data):
|
|||
|
||||
layer_id = data['layer']
|
||||
layer = get_by_id(settings.CONFIG['layers'], layer_id)
|
||||
if layer['canAddAnnotations'].get(request.user.get_profile().get_level()):
|
||||
if layer['canAddAnnotations'].get(request.user.profile.get_level()):
|
||||
if layer['type'] == 'entity':
|
||||
try:
|
||||
value = Entity.get_by_name(ox.decode_html(data['value']), layer['entity']).get_id()
|
||||
|
@ -229,7 +229,7 @@ def addAnnotations(request, data):
|
|||
layer_id = data['layer']
|
||||
layer = get_by_id(settings.CONFIG['layers'], layer_id)
|
||||
if item.editable(request.user) \
|
||||
and layer['canAddAnnotations'].get(request.user.get_profile().get_level()):
|
||||
and layer['canAddAnnotations'].get(request.user.profile.get_level()):
|
||||
response = json_response()
|
||||
data['user'] = request.user.username
|
||||
t = add_annotations.delay(data)
|
||||
|
|
|
@ -173,7 +173,7 @@ check the README for further details.
|
|||
try:
|
||||
if User.objects.filter(profile__level=admin).count() == 0:
|
||||
for u in User.objects.filter(is_superuser=True):
|
||||
p = u.get_profile()
|
||||
p = u.profile
|
||||
p.level = admin
|
||||
p.save()
|
||||
settings.ADMIN = tuple([(u.username, u.email)
|
||||
|
|
|
@ -133,7 +133,7 @@ def editPage(request, data):
|
|||
}
|
||||
see: getPage
|
||||
'''
|
||||
if request.user.get_profile().capability('canEditSitePages'):
|
||||
if request.user.profile.capability('canEditSitePages'):
|
||||
page, created = models.Page.objects.get_or_create(name=data['name'])
|
||||
page.text = ox.sanitize_html(data['text'])
|
||||
page.save()
|
||||
|
|
|
@ -305,7 +305,7 @@ class File(models.Model):
|
|||
return srt
|
||||
|
||||
def editable(self, user):
|
||||
p = user.get_profile()
|
||||
p = user.profile
|
||||
return p.get_level() in ('admin', 'staff') or \
|
||||
(not self.available and p.capability('canAddItems')) or \
|
||||
self.instances.filter(volume__user=user).count() > 0 or \
|
||||
|
|
|
@ -83,7 +83,7 @@ def update(request, data):
|
|||
t = tasks.update_files.delay(user.username, data['volume'], data['files'])
|
||||
response['data']['taskId'] = t.task_id
|
||||
|
||||
user_profile = user.get_profile()
|
||||
user_profile = user.profile
|
||||
user_profile.files_updated = datetime.now()
|
||||
user_profile.save()
|
||||
|
||||
|
@ -179,7 +179,7 @@ def addMedia(request, data):
|
|||
'''
|
||||
response = json_response({})
|
||||
oshash = data.pop('id')
|
||||
if not request.user.get_profile().capability('canAddItems'):
|
||||
if not request.user.profile.capability('canAddItems'):
|
||||
response = json_response(status=403, text='permission denied')
|
||||
elif models.File.objects.filter(oshash=oshash).count() > 0:
|
||||
f = models.File.objects.get(oshash=oshash)
|
||||
|
@ -496,7 +496,7 @@ def removeMedia(request, data):
|
|||
see: addMedia, editMedia, findMedia, moveMedia
|
||||
'''
|
||||
response = json_response()
|
||||
if request.user.get_profile().get_level() == 'admin':
|
||||
if request.user.profile.get_level() == 'admin':
|
||||
qs = models.File.objects.filter(oshash__in=data['ids'], instances__id=None)
|
||||
selected = set([f.item.id for f in qs if f.selected])
|
||||
items = list(set([f.item.id for f in qs]))
|
||||
|
|
|
@ -219,7 +219,7 @@ class ClipManager(Manager):
|
|||
qs = qs.filter(sort__rightslevel__lte=allowed_level)
|
||||
#users can see public clips, there own clips and clips of there groups
|
||||
else:
|
||||
allowed_level = settings.CONFIG['capabilities']['canSeeItem'][user.get_profile().get_level()]
|
||||
allowed_level = settings.CONFIG['capabilities']['canSeeItem'][user.profile.get_level()]
|
||||
q = Q(sort__rightslevel__lte=allowed_level)|Q(user=user.id)
|
||||
if user.groups.count():
|
||||
q |= Q(item__groups__in=user.groups.all())
|
||||
|
|
|
@ -103,7 +103,7 @@ class Document(models.Model):
|
|||
return False
|
||||
if self.user == user or \
|
||||
user.is_staff or \
|
||||
user.get_profile().capability('canEditDocuments') == True or \
|
||||
user.profile.capability('canEditDocuments') == True or \
|
||||
(item and item.editable(user)):
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -131,7 +131,7 @@ class Edit(models.Model):
|
|||
return False
|
||||
if self.user == user or \
|
||||
user.is_staff or \
|
||||
user.get_profile().capability('canEditFeaturedEdits') == True:
|
||||
user.profile.capability('canEditFeaturedEdits') == True:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -151,7 +151,7 @@ class Edit(models.Model):
|
|||
pos.section = 'personal'
|
||||
pos.save()
|
||||
elif value == 'featured':
|
||||
if user.get_profile().capability('canEditFeaturedEdits'):
|
||||
if user.profile.capability('canEditFeaturedEdits'):
|
||||
pos, created = Position.objects.get_or_create(edit=self, user=user,
|
||||
section='featured')
|
||||
if created:
|
||||
|
@ -527,7 +527,7 @@ class Position(models.Model):
|
|||
|
||||
edit = models.ForeignKey(Edit, related_name='position')
|
||||
user = models.ForeignKey(User, related_name='edit_position')
|
||||
section = models.CharField(max_length='255')
|
||||
section = models.CharField(max_length=255)
|
||||
position = models.IntegerField(default=0)
|
||||
|
||||
def __unicode__(self):
|
||||
|
|
|
@ -491,7 +491,7 @@ def sortEdits(request, data):
|
|||
}.get(section,section)
|
||||
#ids = list(set(data['ids']))
|
||||
ids = data['ids']
|
||||
if section == 'featured' and not request.user.get_profile().capability('canEditFeaturedEdits'):
|
||||
if section == 'featured' and not request.user.profile.capability('canEditFeaturedEdits'):
|
||||
response = json_response(status=403, text='not allowed')
|
||||
else:
|
||||
user = request.user
|
||||
|
|
|
@ -102,7 +102,7 @@ class Entity(models.Model):
|
|||
if not user or user.is_anonymous():
|
||||
return False
|
||||
if user.is_staff or \
|
||||
user.get_profile().capability('canEditEntities') == True or \
|
||||
user.profile.capability('canEditEntities') == True or \
|
||||
(item and item.editable(user)):
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -74,7 +74,7 @@ class Event(models.Model):
|
|||
if user and not user.is_anonymous() \
|
||||
and (not self.user or \
|
||||
self.user == user or \
|
||||
user.get_profile().capability('canEditEvents')):
|
||||
user.profile.capability('canEditEvents')):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ def parseCondition(condition, user, owner=None):
|
|||
if (not exclude and op == '=' or op in ('$', '^')) and v == '':
|
||||
return Q()
|
||||
elif k == 'filename' and (user.is_anonymous() or \
|
||||
not user.get_profile().capability('canSeeMedia')):
|
||||
not user.profile.capability('canSeeMedia')):
|
||||
return Q(id=0)
|
||||
elif k == 'oshash':
|
||||
return Q(files__oshash=v)
|
||||
|
@ -117,7 +117,7 @@ def parseCondition(condition, user, owner=None):
|
|||
q = ~q
|
||||
return q
|
||||
elif k in ('canplayvideo', 'canplayclips'):
|
||||
level = user.is_anonymous() and 'guest' or user.get_profile().get_level()
|
||||
level = user.is_anonymous() and 'guest' or user.profile.get_level()
|
||||
allowed_level = settings.CONFIG['capabilities'][{
|
||||
'canplayvideo': 'canPlayVideo',
|
||||
'canplayclips': 'canPlayClips'
|
||||
|
@ -326,7 +326,7 @@ class ItemManager(Manager):
|
|||
rendered_q = Q(rendered=True)
|
||||
#users can see public items, there own items and items of there groups
|
||||
else:
|
||||
level = user.get_profile().get_level()
|
||||
level = user.profile.get_level()
|
||||
allowed_level = settings.CONFIG['capabilities']['canSeeItem'][level]
|
||||
q = Q(level__lte=allowed_level)|Q(user=user)
|
||||
rendered_q = Q(rendered=True)|Q(user=user)
|
||||
|
|
|
@ -206,7 +206,7 @@ class Item(models.Model):
|
|||
if user.is_anonymous():
|
||||
level = 'guest'
|
||||
else:
|
||||
level = user.get_profile().get_level()
|
||||
level = user.profile.get_level()
|
||||
editable = self.editable(user)
|
||||
if editable:
|
||||
return True
|
||||
|
@ -220,7 +220,7 @@ class Item(models.Model):
|
|||
def editable(self, user):
|
||||
if user.is_anonymous():
|
||||
return False
|
||||
if user.get_profile().capability('canEditMetadata') == True or \
|
||||
if user.profile.capability('canEditMetadata') == True or \
|
||||
user.is_staff or \
|
||||
self.user == user or \
|
||||
self.groups.filter(id__in=user.groups.all()).count() > 0:
|
||||
|
@ -346,7 +346,7 @@ class Item(models.Model):
|
|||
update_ids = False
|
||||
if not self.id:
|
||||
if self.user:
|
||||
self.level = settings.CONFIG['rightsLevel'][self.user.get_profile().get_level()]
|
||||
self.level = settings.CONFIG['rightsLevel'][self.user.profile.get_level()]
|
||||
else:
|
||||
self.level = settings.CONFIG['rightsLevel']['member']
|
||||
if not self.public_id:
|
||||
|
@ -1139,7 +1139,7 @@ class Item(models.Model):
|
|||
|
||||
def get_files(self, user):
|
||||
files = self.files.all().select_related()
|
||||
if user.get_profile().get_level() != 'admin':
|
||||
if user.profile.get_level() != 'admin':
|
||||
files = files.filter(instances__volume__user=user)
|
||||
return [f.json() for f in files]
|
||||
|
||||
|
@ -1779,7 +1779,7 @@ class Description(models.Model):
|
|||
|
||||
|
||||
class AnnotationSequence(models.Model):
|
||||
item = models.ForeignKey('Item', related_name='_annotation_sequence', unique=True)
|
||||
item = models.OneToOneField('Item', related_name='_annotation_sequence')
|
||||
value = models.BigIntegerField(default=1)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -504,7 +504,7 @@ def add(request, data):
|
|||
notes: To allow for this, set config option `itemRequiresVideo` to false.
|
||||
see: edit, find, get, lookup, remove, upload
|
||||
'''
|
||||
if not request.user.get_profile().capability('canAddItems'):
|
||||
if not request.user.profile.capability('canAddItems'):
|
||||
response = json_response(status=403, text='permission denied')
|
||||
else:
|
||||
data['title'] = data.get('title', 'Untitled')
|
||||
|
@ -542,13 +542,13 @@ def edit(request, data):
|
|||
if item.editable(request.user):
|
||||
response = json_response(status=200, text='ok')
|
||||
if 'rightslevel' in data:
|
||||
if request.user.get_profile().capability('canEditRightsLevel') == True:
|
||||
if request.user.profile.capability('canEditRightsLevel') == True:
|
||||
item.level = int(data['rightslevel'])
|
||||
else:
|
||||
response = json_response(status=403, text='permission denied')
|
||||
del data['rightslevel']
|
||||
if 'user' in data:
|
||||
if request.user.get_profile().get_level() in ('admin', 'staff') and \
|
||||
if request.user.profile.get_level() in ('admin', 'staff') and \
|
||||
models.User.objects.filter(username=data['user']).exists():
|
||||
new_user = models.User.objects.get(username=data['user'])
|
||||
if new_user != item.user:
|
||||
|
@ -556,7 +556,7 @@ def edit(request, data):
|
|||
update_clips = True
|
||||
del data['user']
|
||||
if 'groups' in data:
|
||||
if not request.user.get_profile().capability('canManageUsers'):
|
||||
if not request.user.profile.capability('canManageUsers'):
|
||||
# Users wihtout canManageUsers can only add/remove groups they are not in
|
||||
groups = set([g.name for g in item.groups.all()])
|
||||
user_groups = set([g.name for g in request.user.groups.all()])
|
||||
|
@ -588,7 +588,7 @@ def remove(request, data):
|
|||
response = json_response({})
|
||||
item = get_object_or_404_json(models.Item, public_id=data['id'])
|
||||
user = request.user
|
||||
if user.get_profile().capability('canRemoveItems') == True or \
|
||||
if user.profile.capability('canRemoveItems') == True or \
|
||||
user.is_staff or \
|
||||
item.user == user or \
|
||||
item.groups.filter(id__in=user.groups.all()).count() > 0:
|
||||
|
@ -1016,7 +1016,7 @@ def atom_xml(request):
|
|||
|
||||
level = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
||||
if not request.user.is_anonymous():
|
||||
level = request.user.get_profile().level
|
||||
level = request.user.profile.level
|
||||
for item in models.Item.objects.filter(level__lte=level, rendered=True).order_by('-created')[:7]:
|
||||
if add_updated:
|
||||
updated = ET.SubElement(feed, "updated")
|
||||
|
@ -1185,7 +1185,7 @@ def sitemap_xml(request):
|
|||
def item_json(request, id):
|
||||
level = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
||||
if not request.user.is_anonymous():
|
||||
level = request.user.get_profile().level
|
||||
level = request.user.profile.level
|
||||
qs = models.Item.objects.filter(public_id=id, level__lte=level)
|
||||
if qs.count() == 0:
|
||||
response = json_response(status=404, text='not found')
|
||||
|
@ -1198,7 +1198,7 @@ def item_json(request, id):
|
|||
def item_xml(request, id):
|
||||
level = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
||||
if not request.user.is_anonymous():
|
||||
level = request.user.get_profile().level
|
||||
level = request.user.profile.level
|
||||
qs = models.Item.objects.filter(public_id=id, level__lte=level)
|
||||
if qs.count() == 0:
|
||||
response = json_response(status=404, text='not found')
|
||||
|
@ -1237,7 +1237,7 @@ def item(request, id):
|
|||
template = 'index.html'
|
||||
level = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
||||
if not request.user.is_anonymous():
|
||||
level = request.user.get_profile().level
|
||||
level = request.user.profile.level
|
||||
qs = models.Item.objects.filter(public_id=id, level__lte=level)
|
||||
if qs.count() == 0:
|
||||
context = RequestContext(request, {
|
||||
|
|
|
@ -112,7 +112,7 @@ class List(models.Model):
|
|||
return False
|
||||
if self.user == user or \
|
||||
user.is_staff or \
|
||||
user.get_profile().capability('canEditFeaturedLists') == True:
|
||||
user.profile.capability('canEditFeaturedLists') == True:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -143,7 +143,7 @@ class List(models.Model):
|
|||
pos.section = 'personal'
|
||||
pos.save()
|
||||
elif value == 'featured':
|
||||
if user.get_profile().capability('canEditFeaturedLists'):
|
||||
if user.profile.capability('canEditFeaturedLists'):
|
||||
pos, created = Position.objects.get_or_create(list=self, user=user,
|
||||
section='featured')
|
||||
if created:
|
||||
|
@ -301,7 +301,7 @@ class Position(models.Model):
|
|||
|
||||
list = models.ForeignKey(List, related_name='position')
|
||||
user = models.ForeignKey(User)
|
||||
section = models.CharField(max_length='255')
|
||||
section = models.CharField(max_length=255)
|
||||
position = models.IntegerField(default=0)
|
||||
|
||||
def __unicode__(self):
|
||||
|
|
|
@ -394,7 +394,7 @@ def sortLists(request, data):
|
|||
}.get(section,section)
|
||||
#ids = list(set(data['ids']))
|
||||
ids = data['ids']
|
||||
if section == 'featured' and not request.user.get_profile().capability('canEditFeaturedLists'):
|
||||
if section == 'featured' and not request.user.profile.capability('canEditFeaturedLists'):
|
||||
response = json_response(status=403, text='not allowed')
|
||||
else:
|
||||
user = request.user
|
||||
|
|
|
@ -114,7 +114,7 @@ class NewsManager(Manager):
|
|||
if conditions:
|
||||
qs = qs.filter(conditions)
|
||||
if user:
|
||||
if not user.get_profile().get_level() in ('staff', 'admin'):
|
||||
if not user.profile.get_level() in ('staff', 'admin'):
|
||||
qs = qs.filter(Q(public=True)|Q(user=user))
|
||||
else:
|
||||
qs = qs.filter(public=True)
|
||||
|
|
|
@ -19,7 +19,7 @@ class News(models.Model):
|
|||
text = models.TextField()
|
||||
|
||||
def editable(self, user):
|
||||
return user.is_authenticated() and user.get_profile().capability("canEditSitePages")
|
||||
return user.is_authenticated() and user.profile.capability("canEditSitePages")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(News, self).save(*args, **kwargs)
|
||||
|
|
|
@ -68,7 +68,7 @@ class Place(models.Model):
|
|||
if user and not user.is_anonymous() \
|
||||
and (not self.user or \
|
||||
self.user == user or \
|
||||
user.get_profile().capability('canEditPlaces')):
|
||||
user.profile.capability('canEditPlaces')):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
@ -108,9 +108,7 @@ INSTALLED_APPS = (
|
|||
# 'django.contrib.admindocs',
|
||||
'django.contrib.humanize',
|
||||
|
||||
'django_extensions',
|
||||
'devserver',
|
||||
'south',
|
||||
#'django_extensions',
|
||||
'djcelery',
|
||||
'app',
|
||||
'log',
|
||||
|
@ -246,3 +244,6 @@ except NameError:
|
|||
Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)
|
||||
|
||||
INSTALLED_APPS = tuple(list(INSTALLED_APPS) + LOCAL_APPS)
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class Text(models.Model):
|
|||
return False
|
||||
if self.user == user or \
|
||||
user.is_staff or \
|
||||
user.get_profile().capability('canEditFeaturedTexts') == True:
|
||||
user.profile.capability('canEditFeaturedTexts') == True:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -104,7 +104,7 @@ class Text(models.Model):
|
|||
pos.section = 'personal'
|
||||
pos.save()
|
||||
elif value == 'featured':
|
||||
if user.get_profile().capability('canEditFeaturedTexts'):
|
||||
if user.profile.capability('canEditFeaturedTexts'):
|
||||
pos, created = Position.objects.get_or_create(text=self, user=user,
|
||||
section='featured')
|
||||
if created:
|
||||
|
@ -305,7 +305,7 @@ class Position(models.Model):
|
|||
|
||||
text = models.ForeignKey(Text, related_name='position')
|
||||
user = models.ForeignKey(User, related_name='text_position')
|
||||
section = models.CharField(max_length='255')
|
||||
section = models.CharField(max_length=255)
|
||||
position = models.IntegerField(default=0)
|
||||
|
||||
def __unicode__(self):
|
||||
|
|
|
@ -99,7 +99,7 @@ def getText(request, data):
|
|||
'name': '',
|
||||
'text': '',
|
||||
'type': 'html',
|
||||
'editable': not request.user.is_anonymous() and request.user.get_profile().capability('canEditFeaturedTexts')
|
||||
'editable': not request.user.is_anonymous() and request.user.profile.capability('canEditFeaturedTexts')
|
||||
}
|
||||
else:
|
||||
text = qs[0]
|
||||
|
@ -140,7 +140,7 @@ def editText(request, data):
|
|||
else:
|
||||
qs = models.Text.objects.filter(name='')
|
||||
if qs.count() == 0:
|
||||
if request.user.get_profile().capability('canEditFeaturedTexts'):
|
||||
if request.user.profile.capability('canEditFeaturedTexts'):
|
||||
text = models.Text(name='', user=request.user)
|
||||
text.save()
|
||||
else:
|
||||
|
@ -331,7 +331,7 @@ def sortTexts(request, data):
|
|||
}.get(section,section)
|
||||
#ids = list(set(data['ids']))
|
||||
ids = data['ids']
|
||||
if section == 'featured' and not request.user.get_profile().capability('canEditFeaturedTexts'):
|
||||
if section == 'featured' and not request.user.profile.capability('canEditFeaturedTexts'):
|
||||
response = json_response(status=403, text='not allowed')
|
||||
else:
|
||||
user = request.user
|
||||
|
|
|
@ -16,7 +16,8 @@ class Channel(models.Model):
|
|||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
run = models.IntegerField(default=0)
|
||||
list = models.ForeignKey('itemlist.List', related_name='channel', null=True, unique=True, blank=True)
|
||||
list = models.OneToOneField('itemlist.List', related_name='channel', null=True, blank=True)
|
||||
#list = models.ForeignKey('itemlist.List', related_name='channel', null=True, unique=True, blank=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s %s" % (self.list or 'All', self.run)
|
||||
|
|
|
@ -10,7 +10,7 @@ def capability_required_json(capability):
|
|||
def capability_required(function=None):
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
if request.user.is_authenticated() and \
|
||||
request.user.get_profile().capability(capability):
|
||||
request.user.profile.capability(capability):
|
||||
return function(request, *args, **kwargs)
|
||||
return render_to_json_response(json_response(status=403, text='permission denied'))
|
||||
return wraps(function)(_wrapped_view)
|
||||
|
|
|
@ -23,7 +23,7 @@ import tasks
|
|||
|
||||
class SessionData(models.Model):
|
||||
session_key = models.CharField(max_length=40, primary_key=True)
|
||||
user = models.ForeignKey(User, unique=True, null=True, blank=True, related_name='data')
|
||||
user = models.OneToOneField(User, null=True, blank=True, related_name='data')
|
||||
firstseen = models.DateTimeField(auto_now_add=True, db_index=True)
|
||||
lastseen = models.DateTimeField(default=datetime.now, db_index=True)
|
||||
username = models.CharField(max_length=255, null=True, db_index=True)
|
||||
|
@ -87,7 +87,7 @@ class SessionData(models.Model):
|
|||
def save(self, *args, **kwargs):
|
||||
if self.user:
|
||||
self.username = self.user.username
|
||||
self.level = self.user.get_profile().level
|
||||
self.level = self.user.profile.level
|
||||
self.firstseen = self.user.date_joined
|
||||
if self.user.groups.exists():
|
||||
self.groupssort = ''.join([g.name for g in self.user.groups.all()])
|
||||
|
@ -160,7 +160,7 @@ class SessionData(models.Model):
|
|||
'windowsize': self.windowsize,
|
||||
}
|
||||
if self.user:
|
||||
p = self.user.get_profile()
|
||||
p = self.user.profile
|
||||
j['disabled'] = not self.user.is_active
|
||||
j['email'] = self.user.email
|
||||
j['groups'] = [g.name for g in self.user.groups.all()]
|
||||
|
@ -176,7 +176,7 @@ class SessionData(models.Model):
|
|||
|
||||
class UserProfile(models.Model):
|
||||
reset_code = models.CharField(max_length=255, blank=True, null=True, unique=True)
|
||||
user = models.ForeignKey(User, unique=True, related_name='profile')
|
||||
user = models.OneToOneField(User, related_name='profile')
|
||||
|
||||
level = models.IntegerField(default=1)
|
||||
files_updated = models.DateTimeField(default=datetime.now)
|
||||
|
@ -343,7 +343,7 @@ def init_user(user, request=None):
|
|||
result = settings.CONFIG['user'].copy()
|
||||
result['ui'] = get_ui(json.loads(request.session.get('ui', '{}')))
|
||||
else:
|
||||
profile = user.get_profile()
|
||||
profile = user.profile
|
||||
result = {}
|
||||
for key in ('username', ):
|
||||
result[key] = getattr(user, key)
|
||||
|
@ -357,7 +357,7 @@ def init_user(user, request=None):
|
|||
return result
|
||||
|
||||
def user_json(user, keys=None):
|
||||
p = user.get_profile()
|
||||
p = user.profile
|
||||
j = {
|
||||
'disabled': not user.is_active,
|
||||
'email': user.email,
|
||||
|
@ -381,7 +381,7 @@ def has_capability(user, capability):
|
|||
if user.is_anonymous():
|
||||
level = 'guest'
|
||||
else:
|
||||
level = user.get_profile().get_level()
|
||||
level = user.profile.get_level()
|
||||
return level in settings.CONFIG['capabilities'][capability] \
|
||||
and settings.CONFIG['capabilities'][capability][level]
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ def signout(request, data):
|
|||
response = json_response(text='ok')
|
||||
if request.user.is_authenticated():
|
||||
uid = request.user.id
|
||||
profile = request.user.get_profile()
|
||||
profile = request.user.profile
|
||||
if profile.ui.get('page') == 'signout':
|
||||
profile.ui['page'] = ''
|
||||
profile.save()
|
||||
|
@ -201,7 +201,7 @@ def signup(request, data):
|
|||
user = authenticate(username=data['username'],
|
||||
password=data['password'])
|
||||
if ui:
|
||||
profile = user.get_profile()
|
||||
profile = user.profile
|
||||
profile.ui = ui
|
||||
profile.save()
|
||||
|
||||
|
@ -245,7 +245,7 @@ def resetPassword(request, data):
|
|||
user = qs[0].user
|
||||
user.set_password(data['password'])
|
||||
user.save()
|
||||
user_profile = user.get_profile()
|
||||
user_profile = user.profile
|
||||
user_profile.reset_code = None
|
||||
user_profile.save()
|
||||
user = authenticate(username=user.username, password=data['password'])
|
||||
|
@ -301,7 +301,7 @@ def requestToken(request, data):
|
|||
ox.fromAZ('AAAAAAAAAAAAAAAAA')))
|
||||
if models.UserProfile.objects.filter(reset_code=code).count() == 0:
|
||||
break
|
||||
user_profile = user.get_profile()
|
||||
user_profile = user.profile
|
||||
user_profile.reset_code = code
|
||||
user_profile.save()
|
||||
|
||||
|
@ -349,7 +349,7 @@ def editUser(request, data):
|
|||
response = json_response()
|
||||
user = get_object_or_404_json(User, pk=ox.fromAZ(data['id']))
|
||||
|
||||
profile = user.get_profile()
|
||||
profile = user.profile
|
||||
if 'disabled' in data:
|
||||
user.is_active = not data['disabled']
|
||||
if 'email' in data:
|
||||
|
@ -567,7 +567,7 @@ def mail(request, data):
|
|||
see: contact
|
||||
'''
|
||||
response = json_response()
|
||||
p = request.user.get_profile()
|
||||
p = request.user.profile
|
||||
if p.capability('canSendMail'):
|
||||
email_from = '"%s" <%s>' % (settings.SITENAME, settings.CONFIG['site']['email']['system'])
|
||||
headers = {
|
||||
|
@ -707,14 +707,14 @@ def editPreferences(request, data):
|
|||
change = True
|
||||
request.user.email = ox.escape_html(data['email'])
|
||||
if 'newsletter' in data:
|
||||
profile = request.user.get_profile()
|
||||
profile = request.user.profile
|
||||
profile.newsletter = data['newsletter']
|
||||
profile.save()
|
||||
if 'password' in data:
|
||||
change = True
|
||||
request.user.set_password(data['password'])
|
||||
if 'script' in data:
|
||||
profile = request.user.get_profile()
|
||||
profile = request.user.profile
|
||||
profile.preferences['script'] = data['script']
|
||||
profile.save()
|
||||
if change:
|
||||
|
@ -727,7 +727,7 @@ actions.register(editPreferences, cache=False)
|
|||
|
||||
def reset_ui(request):
|
||||
if request.user.is_authenticated():
|
||||
profile = request.user.get_profile()
|
||||
profile = request.user.profile
|
||||
profile.ui = {}
|
||||
profile.save()
|
||||
else:
|
||||
|
@ -744,7 +744,7 @@ def resetUI(request, data):
|
|||
'''
|
||||
response = json_response()
|
||||
if request.user.is_authenticated():
|
||||
profile = request.user.get_profile()
|
||||
profile = request.user.profile
|
||||
profile.ui = {}
|
||||
profile.save()
|
||||
else:
|
||||
|
@ -765,7 +765,7 @@ def setUI(request, data):
|
|||
see: resetUI
|
||||
'''
|
||||
if request.user.is_authenticated():
|
||||
profile = request.user.get_profile()
|
||||
profile = request.user.profile
|
||||
ui = profile.ui
|
||||
else:
|
||||
ui = json.loads(request.session.get('ui', '{}'))
|
||||
|
|
Loading…
Reference in a new issue