|
@@ 87-109 (lines=23) @@
|
| 84 |
|
class RegisterMixin(object): |
| 85 |
|
"""If a biosample account is already registered, returns to dashboard""" |
| 86 |
|
|
| 87 |
|
def dispatch(self, request, *args, **kwargs): |
| 88 |
|
# get user from request and user model. This could be also Anonymous |
| 89 |
|
# user:however with metod decorator a login is required before dispatch |
| 90 |
|
# method is called |
| 91 |
|
User = get_user_model() |
| 92 |
|
user = self.request.user |
| 93 |
|
|
| 94 |
|
try: |
| 95 |
|
user.biosample_account |
| 96 |
|
|
| 97 |
|
except User.biosample_account.RelatedObjectDoesNotExist: |
| 98 |
|
# call the default get method |
| 99 |
|
return super( |
| 100 |
|
RegisterMixin, self).dispatch(request, *args, **kwargs) |
| 101 |
|
|
| 102 |
|
else: |
| 103 |
|
logger.warning("Error for user:%s: Already registered" % user) |
| 104 |
|
messages.warning( |
| 105 |
|
request=self.request, |
| 106 |
|
message='Your AAP profile is already registered', |
| 107 |
|
extra_tags="alert alert-dismissible alert-warning") |
| 108 |
|
|
| 109 |
|
return redirect('image_app:dashboard') |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
class MyFormMixin(object): |
|
@@ 59-81 (lines=23) @@
|
| 56 |
|
|
| 57 |
|
return initial |
| 58 |
|
|
| 59 |
|
def dispatch(self, request, *args, **kwargs): |
| 60 |
|
# get user from request and user model. This could be also Anonymous |
| 61 |
|
# user:however with metod decorator a login is required before dispatch |
| 62 |
|
# method is called |
| 63 |
|
User = get_user_model() |
| 64 |
|
user = self.request.user |
| 65 |
|
|
| 66 |
|
try: |
| 67 |
|
user.biosample_account |
| 68 |
|
|
| 69 |
|
except User.biosample_account.RelatedObjectDoesNotExist: |
| 70 |
|
logger.warning("Error for user:%s: not managed" % user) |
| 71 |
|
messages.warning( |
| 72 |
|
request=self.request, |
| 73 |
|
message='You need to register a valid AAP profile', |
| 74 |
|
extra_tags="alert alert-dismissible alert-warning") |
| 75 |
|
|
| 76 |
|
return redirect('accounts:registration_activation_complete') |
| 77 |
|
|
| 78 |
|
else: |
| 79 |
|
# call the default get method |
| 80 |
|
return super( |
| 81 |
|
TokenMixin, self).dispatch(request, *args, **kwargs) |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
class RegisterMixin(object): |