From fcf901606fc6f5e6575155fc297df7fd6295376d Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Wed, 5 Sep 2012 18:13:04 +0300 Subject: [PATCH] AstakosUser signed_terms property instead of function --- snf-astakos-app/astakos/im/api/admin.py | 6 +++--- snf-astakos-app/astakos/im/management/commands/user_show.py | 2 +- snf-astakos-app/astakos/im/models.py | 5 +---- snf-astakos-app/astakos/im/target/redirect.py | 2 +- snf-astakos-app/astakos/im/views.py | 4 ++-- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/snf-astakos-app/astakos/im/api/admin.py b/snf-astakos-app/astakos/im/api/admin.py index ee32568..b34217c 100644 --- a/snf-astakos-app/astakos/im/api/admin.py +++ b/snf-astakos-app/astakos/im/api/admin.py @@ -98,7 +98,7 @@ def authenticate_old(request, user=None): if (time() - mktime(user.auth_token_expires.timetuple())) > 0: raise Unauthorized('Authentication expired') - if not user.signed_terms(): + if not user.signed_terms: raise Unauthorized('Pending approval terms') response = HttpResponse() @@ -109,7 +109,7 @@ def authenticate_old(request, user=None): 'auth_token_created':user.auth_token_created.isoformat(), 'auth_token_expires':user.auth_token_expires.isoformat(), 'has_credits':user.has_credits, - 'has_signed_terms':user.signed_terms(), + 'has_signed_terms':user.signed_terms, 'groups':[g.name for g in user.groups.all()]} response.content = json.dumps(user_info) response['Content-Type'] = 'application/json; charset=UTF-8' @@ -133,7 +133,7 @@ def authenticate(request, user=None): if (time() - mktime(user.auth_token_expires.timetuple())) > 0: raise Unauthorized('Authentication expired') - if not user.signed_terms(): + if not user.signed_terms: raise Unauthorized('Pending approval terms') response = HttpResponse() diff --git a/snf-astakos-app/astakos/im/management/commands/user_show.py b/snf-astakos-app/astakos/im/management/commands/user_show.py index 4c89780..b8d670b 100644 --- a/snf-astakos-app/astakos/im/management/commands/user_show.py +++ b/snf-astakos-app/astakos/im/management/commands/user_show.py @@ -84,7 +84,7 @@ class Command(BaseCommand): 'resources' : user.quota } if get_latest_terms(): - has_signed_terms = user.signed_terms() + has_signed_terms = user.signed_terms kv['has_signed_terms'] = format_bool(has_signed_terms) if has_signed_terms: kv['date_signed_terms'] = format_date(user.date_signed_terms) diff --git a/snf-astakos-app/astakos/im/models.py b/snf-astakos-app/astakos/im/models.py index b05c14e..f7e797a 100644 --- a/snf-astakos-app/astakos/im/models.py +++ b/snf-astakos-app/astakos/im/models.py @@ -149,10 +149,6 @@ class AstakosGroup(Group): return False return True -# @property -# def participants(self): -# return len(self.approved_members) - def enable(self): if self.is_enabled: return @@ -351,6 +347,7 @@ class AstakosUser(User): if q.count() != 0: raise ValidationError({'__all__':[_('Another account with the same email & is_active combination found.')]}) + @property def signed_terms(self): term = get_latest_terms() if not term: diff --git a/snf-astakos-app/astakos/im/target/redirect.py b/snf-astakos-app/astakos/im/target/redirect.py index 3276c7b..4411ec2 100644 --- a/snf-astakos-app/astakos/im/target/redirect.py +++ b/snf-astakos-app/astakos/im/target/redirect.py @@ -68,7 +68,7 @@ def login(request): if request.user.is_authenticated(): # if user has not signed the approval terms # redirect to approval terms with next the request path - if not request.user.signed_terms(): + if not request.user.signed_terms: # first build next parameter parts = list(urlsplit(request.build_absolute_uri())) params = dict(parse_qsl(parts[3], keep_blank_values=True)) diff --git a/snf-astakos-app/astakos/im/views.py b/snf-astakos-app/astakos/im/views.py index 9f0e35b..cc66267 100644 --- a/snf-astakos-app/astakos/im/views.py +++ b/snf-astakos-app/astakos/im/views.py @@ -113,7 +113,7 @@ def signed_terms_required(func): """ @wraps(func) def wrapper(request, *args, **kwargs): - if request.user.is_authenticated() and not request.user.signed_terms(): + if request.user.is_authenticated() and not request.user.signed_terms: params = urlencode({'next': request.build_absolute_uri(), 'show_form':''}) terms_uri = reverse('latest_terms') + '?' + params @@ -545,7 +545,7 @@ def approval_terms(request, term_id=None, template_name='im/approval_terms.html' return HttpResponseRedirect(next) else: form = None - if request.user.is_authenticated() and not request.user.signed_terms(): + if request.user.is_authenticated() and not request.user.signed_terms: form = SignApprovalTermsForm(instance=request.user) return render_response(template_name, terms = terms, -- 1.7.10.4