From 8b8991d4c132b95d74bc4c79ae303447cc9c9a74 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Mon, 9 Sep 2024 14:50:59 +0200 Subject: [PATCH 1/7] Move allauth forms to adapter.py (#1145) --- rdmo/accounts/adapter.py | 37 +++++++++++++++++++++++++++++++++++++ rdmo/accounts/forms.py | 36 +----------------------------------- rdmo/core/settings.py | 5 ++--- rdmo/core/views.py | 2 +- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/rdmo/accounts/adapter.py b/rdmo/accounts/adapter.py index efa7902ce4..1d756001e5 100644 --- a/rdmo/accounts/adapter.py +++ b/rdmo/accounts/adapter.py @@ -1,9 +1,15 @@ from django.conf import settings from django.contrib.auth.models import Group +from django.forms import BooleanField from allauth.account.adapter import DefaultAccountAdapter +from allauth.account.forms import LoginForm as AllauthLoginForm +from allauth.account.forms import SignupForm as AllauthSignupForm from allauth.socialaccount.adapter import DefaultSocialAccountAdapter +from .forms import ProfileForm +from .models import ConsentFieldValue + class AccountAdapter(DefaultAccountAdapter): @@ -33,3 +39,34 @@ def save_user(self, request, sociallogin, form=None): user.groups.set(groups) return user + + +class LoginForm(AllauthLoginForm): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # remove forget password link introduced with allauth 0.57.0 + password_field = self.fields.get('password') + if password_field: + password_field.help_text = None + + +class SignupForm(AllauthSignupForm, ProfileForm): + + use_required_attribute = False + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # add a consent field, the label is added in the template + if settings.ACCOUNT_TERMS_OF_USE: + self.fields['consent'] = BooleanField(required=True) + + def signup(self, request, user): + self._save_additional_values(user) + + # store the consent field + if settings.ACCOUNT_TERMS_OF_USE: + consent = ConsentFieldValue(user=user, consent=self.cleaned_data['consent']) + consent.save() diff --git a/rdmo/accounts/forms.py b/rdmo/accounts/forms.py index fe75e98b4b..52ad754417 100644 --- a/rdmo/accounts/forms.py +++ b/rdmo/accounts/forms.py @@ -5,10 +5,7 @@ from django.contrib.auth import get_user_model from django.utils.translation import gettext_lazy as _ -from allauth.account.forms import LoginForm as AllauthLoginForm -from allauth.account.forms import SignupForm as AllauthSignupForm - -from .models import AdditionalField, AdditionalFieldValue, ConsentFieldValue +from .models import AdditionalField, AdditionalFieldValue log = logging.getLogger(__name__) @@ -71,37 +68,6 @@ def _save_additional_values(self, user=None): additional_value.save() -class LoginForm(AllauthLoginForm): - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - # remove forget password link introduced with allauth 0.57.0 - password_field = self.fields.get('password') - if password_field: - password_field.help_text = None - - -class SignupForm(AllauthSignupForm, ProfileForm): - - use_required_attribute = False - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - # add a consent field, the label is added in the template - if settings.ACCOUNT_TERMS_OF_USE: - self.fields['consent'] = forms.BooleanField(required=True) - - def signup(self, request, user): - self._save_additional_values(user) - - # store the consent field - if settings.ACCOUNT_TERMS_OF_USE: - consent = ConsentFieldValue(user=user, consent=self.cleaned_data['consent']) - consent.save() - - class RemoveForm(forms.Form): def __init__(self, *args, **kwargs): diff --git a/rdmo/core/settings.py b/rdmo/core/settings.py index e7cb03ba58..35fa8c667c 100644 --- a/rdmo/core/settings.py +++ b/rdmo/core/settings.py @@ -102,9 +102,8 @@ ACCOUNT_TERMS_OF_USE = False ACCOUNT_ADAPTER = 'rdmo.accounts.adapter.AccountAdapter' ACCOUNT_FORMS = { - 'login': 'rdmo.accounts.forms.LoginForm', - 'signup': 'rdmo.accounts.forms.SignupForm' - + 'login': 'rdmo.accounts.adapter.LoginForm', + 'signup': 'rdmo.accounts.adapter.SignupForm' } ACCOUNT_USER_DISPLAY = 'rdmo.accounts.utils.get_full_name' ACCOUNT_EMAIL_REQUIRED = True diff --git a/rdmo/core/views.py b/rdmo/core/views.py index 3ec0930d7e..ca2fad62b0 100644 --- a/rdmo/core/views.py +++ b/rdmo/core/views.py @@ -32,7 +32,7 @@ def home(request): else: if settings.LOGIN_FORM: if settings.ACCOUNT or settings.SOCIALACCOUNT: - from rdmo.accounts.forms import LoginForm + from rdmo.accounts.adapter import LoginForm return render(request, 'core/home.html', { 'form': LoginForm(), 'signup_url': reverse("account_signup") From b1963de782ee3a16dc4dce9fd8c44e0fd13c9ec0 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Tue, 10 Sep 2024 13:04:24 +0200 Subject: [PATCH 2/7] Fix initView after activateValueSet (#1147) --- .../projects/js/project_questions/services.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/rdmo/projects/static/projects/js/project_questions/services.js b/rdmo/projects/static/projects/js/project_questions/services.js index 2537843d03..e24c168bcc 100644 --- a/rdmo/projects/static/projects/js/project_questions/services.js +++ b/rdmo/projects/static/projects/js/project_questions/services.js @@ -162,19 +162,21 @@ angular.module('project_questions') service[key] = angular.copy(future[key]); }); - // activate fist valueset - if (angular.isDefined(service.valuesets[service.page.id][service.set_prefix])) { - if (angular.isDefined(past.page) && - past.page.is_collection && - past.page.attribute == service.page.attribute && - !service.settings.project_questions_cycle_sets) { - // use the same set index as before - service.set_index = past.set_index + // activate first or current valueset, but only if the page did actually change + if (angular.isUndefined(past.page) || past.page.id !== page_id) { + if (angular.isDefined(service.valuesets[service.page.id][service.set_prefix])) { + if (angular.isDefined(past.page) && + past.page.is_collection && + past.page.attribute == service.page.attribute && + !service.settings.project_questions_cycle_sets) { + // use the same set index as before + service.set_index = past.set_index + } else { + service.set_index = service.valuesets[service.page.id][service.set_prefix][0].set_index; + } } else { - service.set_index = service.valuesets[service.page.id][service.set_prefix][0].set_index; + service.set_index = null; } - } else { - service.set_index = null; } // focus the first field @@ -1221,13 +1223,13 @@ angular.module('project_questions') }); }; - service.activateValueSet = function(set_prefix) { + service.activateValueSet = function(set_index) { if (service.settings.project_questions_autosave) { service.save(false).then(function() { - service.set_index = set_prefix; + service.set_index = set_index; }); } else { - service.set_index = set_prefix; + service.set_index = set_index; } }; From d8b788fc85b8901526b1d4443210200d8b15ba07 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Tue, 10 Sep 2024 18:23:02 +0200 Subject: [PATCH 3/7] Prevent the page to change when a validation error occurs on project_questions (#1134) --- .../projects/js/project_questions/services.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/rdmo/projects/static/projects/js/project_questions/services.js b/rdmo/projects/static/projects/js/project_questions/services.js index e24c168bcc..5fcff49715 100644 --- a/rdmo/projects/static/projects/js/project_questions/services.js +++ b/rdmo/projects/static/projects/js/project_questions/services.js @@ -922,8 +922,10 @@ angular.module('project_questions') service.error = null; // reset error when moving to previous questionset if (service.settings.project_questions_autosave) { service.save(false, true).then(function() { - back = true; - service.initView(service.page.prev_page); + if (service.error === null) { + back = true; + service.initView(service.page.prev_page); + } }) } else { back = true; @@ -935,7 +937,9 @@ angular.module('project_questions') service.error = null; // reset error when moving to next questionset if (service.settings.project_questions_autosave) { service.save(false, true).then(function() { - service.initView(service.page.next_page); + if (service.error === null) { + service.initView(service.page.next_page); + } }) } else { service.initView(service.page.next_page); @@ -946,8 +950,8 @@ angular.module('project_questions') service.error = null; // reset error before saving if (service.settings.project_questions_autosave) { service.save(false, true).then(function() { - if (service.error !== null && service.error.status !== 400) { - // pass, dont jump (but not on a validation error) + if (service.error !== null) { + // pass, dont jump } else if (angular.isDefined(page)) { service.initView(page.id); } else if (angular.isDefined(section)) { From 44087806625b1d8ab3c8b0e80eee5b0634dd54f9 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Fri, 13 Sep 2024 10:11:10 +0200 Subject: [PATCH 4/7] Pin importlib_metadata to 0.8.4 --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 9df7193c84..1990b6a028 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,7 @@ dependencies = [ "django-widget-tweaks>=1.5,<2.0", "djangorestframework>=3.15,<4.0", "drf-extensions>=0.7.1,<1.0", + "importlib_metadata=<8.4.0", # upstrem problem, see https://github.com/python/importlib_metadata/issues/506 "iso8601>=2.0,<3.0", "markdown>=3.4,<4.0", "packaging>=23.2,<25.0", From 566d3251025055491b079e5e4ddb0fc47e4fa382 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Fri, 13 Sep 2024 10:17:28 +0200 Subject: [PATCH 5/7] Update CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6eee5651c..1b5c50aa88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [RDMO 2.2.1](https://github.com/rdmorganiser/rdmo/compare/2.2.0...2.2.1) (Sep 13, 2024) + +* Fix import error when allauth is not used (#1145) +* Fix a bug with collection pages when optionset refresh is true (#1147) +* Prevent the page to change when a validation error occurs on project_questions (#1134) +* Pin importlib_metadata to 0.8.4 due to an upstream problem + ## [RDMO 2.2.0](https://github.com/rdmorganiser/rdmo/compare/2.1.3...2.2.0) (Sep 05, 2024) * Add new projects overview (#865, #355) From 98d0c63031256b006cde301044c265b70a8c632b Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Fri, 13 Sep 2024 10:17:49 +0200 Subject: [PATCH 6/7] Bump version to 2.2.1 --- rdmo/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdmo/__init__.py b/rdmo/__init__.py index 8a124bf648..b19ee4b77e 100644 --- a/rdmo/__init__.py +++ b/rdmo/__init__.py @@ -1 +1 @@ -__version__ = "2.2.0" +__version__ = "2.2.1" From 2a245da8d411b8a9dd7c905c46f518fe3a2f412c Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Fri, 13 Sep 2024 11:47:21 +0200 Subject: [PATCH 7/7] Fix pinning --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1990b6a028..6103cd7faa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ dependencies = [ "django-widget-tweaks>=1.5,<2.0", "djangorestframework>=3.15,<4.0", "drf-extensions>=0.7.1,<1.0", - "importlib_metadata=<8.4.0", # upstrem problem, see https://github.com/python/importlib_metadata/issues/506 + "importlib_metadata<8.5.0", # upstrem problem, see https://github.com/python/importlib_metadata/issues/506 "iso8601>=2.0,<3.0", "markdown>=3.4,<4.0", "packaging>=23.2,<25.0",