Skip to content

Commit

Permalink
Merge pull request #1146 from rdmorganiser/2.2.1
Browse files Browse the repository at this point in the history
RDMO 2.2.1
  • Loading branch information
jochenklar authored Sep 13, 2024
2 parents a9772a0 + 2a245da commit 5ef624a
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 59 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.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",
Expand Down
2 changes: 1 addition & 1 deletion rdmo/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.2.0"
__version__ = "2.2.1"
37 changes: 37 additions & 0 deletions rdmo/accounts/adapter.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down Expand Up @@ -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()
36 changes: 1 addition & 35 deletions rdmo/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions rdmo/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rdmo/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
44 changes: 25 additions & 19 deletions rdmo/projects/static/projects/js/project_questions/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -920,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;
Expand All @@ -933,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);
Expand All @@ -944,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)) {
Expand Down Expand Up @@ -1221,13 +1227,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;
}
};

Expand Down

0 comments on commit 5ef624a

Please sign in to comment.