Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
exclude: .pre-commit-config.yaml
- id: pt_structure
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.6
rev: v0.15.9
hooks:
- id: ruff-check
args: [ "--fix" ]
Expand All @@ -29,15 +29,15 @@ repos:
additional_dependencies:
- flake8-type-checking>=3.0.0
- repo: https://github.com/thibaudcolas/pre-commit-stylelint
rev: v17.4.0
rev: v17.6.0
hooks:
- id: stylelint
files: '^src/.*\.scss'
additional_dependencies:
- stylelint@16.19.1
- stylelint-config-standard-scss@15.0.0
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v10.0.3
rev: v10.2.0
hooks:
- id: eslint
files: '^src/.*\.jsx?$'
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ install_requires =
kerberos
lazy-object-proxy
ldap3
libres>=1
libres>=1.1
libsass
lingua-language-detector
lxml
Expand Down
17 changes: 17 additions & 0 deletions src/onegov/core/orm/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def on_delete(schema, session, obj):

self._ignore_bulk_updates = False
self._ignore_bulk_deletes = False
self._change_signals_disabled = False

self.on_schema_init = Signal()
self.on_transaction_join = Signal()
Expand Down Expand Up @@ -383,6 +384,16 @@ def ignore_bulk_deletes(self) -> Iterator[Self]:
finally:
self._ignore_bulk_deletes = previous_state

@contextmanager
def disable_change_signals(self) -> Iterator[Self]:
""" Disables the insert/update/delete signals temporarily. """
previous_state = self._change_signals_disabled
self._change_signals_disabled = True
try:
yield self
finally:
self._change_signals_disabled = previous_state

def register_engine(self, engine: Engine) -> None:
""" Takes the given engine and registers it with the schema
switching mechanism. Maybe used to register external engines with
Expand Down Expand Up @@ -470,6 +481,9 @@ def augment_bulk_updates_and_inserts(
if not orm_execution_state.is_orm_statement:
return None

if self._change_signals_disabled:
return None

stmt = orm_execution_state.statement
if isinstance(stmt, Update):
if self._ignore_bulk_updates:
Expand Down Expand Up @@ -557,6 +571,9 @@ def on_after_flush(
session: Session,
flush_context: Any
) -> None:
if self._change_signals_disabled:
return None

if self.on_insert.receivers:
for obj in session.new:
self.on_insert.send(self.current_schema, obj=obj)
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/feriennet/views/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def handle_donation(
if donation:
amount = f'{donation.amount:.2f}'

for key, value in form.amount.choices: # type:ignore[misc,str-unpack]
for key, value in form.amount.choices: # type:ignore
if key == amount:
form.amount.data = amount
break
Expand Down
14 changes: 14 additions & 0 deletions src/onegov/form/assets/css/treeselect.fixes.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
select.treeselect {
display: none !important;
}

.treeselect-list__item--disabled {
cursor: default !important;
}

.treeselect-list__item--disabled .treeselect-list__item-icon {
color: #999 !important;
cursor: default !important;
pointer-events: none;
}

.treeselect-list__item--disabled .treeselect-list__item-label {
color: #999 !important;
}
6 changes: 4 additions & 2 deletions src/onegov/form/assets/js/treeselect-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ $(document).ready(function() {
saveScrollPosition: true,
emptyText: $(select).data('no_results_text') || '',
placeholder: $(select).data('placeholder') || '',
showTags: true,
showTags: select.multiple,
searchable: true,
clearable: true,
isGroupedValue: true,
expandSelected: true,
isGroupedValue: select.multiple,
grouped: select.multiple,
inputCallback: function(value) {
$(select).val(value);
},
Expand Down
14 changes: 11 additions & 3 deletions src/onegov/form/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
FormT, Filter, PricingRules, RawFormValue, Validators, Widget)
from typing import NotRequired, TypedDict, Self
from webob.request import _FieldStorageWithFile
from wtforms.fields.choices import _Choice
from wtforms.form import BaseForm
from wtforms.meta import (
_MultiDictLikeWithGetlist, _SupportsGettextAndNgettext, DefaultMeta)
Expand Down Expand Up @@ -795,6 +794,8 @@ def formatted_data(self) -> str | None:

class _TreeSelectMixin(_TreeSelectMixinBase):

widget: TreeSelectWidget

def __init__(
self,
label: str | None = None,
Expand Down Expand Up @@ -855,9 +856,13 @@ def __init__(
def flatten_choices(
self,
choices: Iterable[TreeSelectNode]
) -> Iterator[_Choice]:
) -> Iterator[tuple[str, str]]:
multiple = self.widget.multiple
for choice in choices:
yield choice['value'], choice['name']
if not choice.get('disabled', False) and (
multiple or choice.get('isGroupSelectable', True)
):
yield choice['value'], choice['name']
yield from self.flatten_choices(choice['children'])

def set_choices(self, choices: Iterable[TreeSelectNode]) -> None:
Expand All @@ -866,6 +871,9 @@ def set_choices(self, choices: Iterable[TreeSelectNode]) -> None:

self.render_kw['data-choices'] = json.dumps(choices)
self.choices = list(self.flatten_choices(choices))
if not self.widget.multiple:
# NOTE: Add a blank choice so the field can be cleared
self.choices.insert(0, ('', ''))


class TreeSelectField(_TreeSelectMixin, SelectField):
Expand Down
70 changes: 36 additions & 34 deletions src/onegov/onboarding/models/town_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,40 +177,42 @@ def add_town(
schema = self.get_schema(name)
custom_config = self.config['configuration']

self.app.session_manager.set_current_schema(schema)
session = self.app.session_manager.session()

if session.query(Organisation).first():
raise AlreadyExistsError

with self.app.temporary_depot(schema, **custom_config):
create_new_organisation(self.app, name=name, reply_to=user)

org = session.query(Organisation).first()
assert org is not None and org.theme_options is not None
org.theme_options['primary-color-ui'] = color

users = UserCollection(self.app.session_manager.session())
assert not users.query().first()

users.add(user, password, 'admin')

title = request.translate(_('Welcome to OneGov Cloud'))
welcome_mail = render_template('mail_welcome.pt', request, {
'url': 'https://{}'.format(self.get_domain(name)),
'mail': user,
'layout': MailLayout(self, request),
'title': title,
'org': name
})

self.app.perform_reindex()
self.app.send_transactional_email(
subject=title,
receivers=(user, ),
content=welcome_mail,
reply_to='onegov@seantis.ch'
)
with self.app.session_manager.disable_change_signals():
self.app.session_manager.set_current_schema(schema)
session = self.app.session_manager.session()

if session.query(Organisation).first():
raise AlreadyExistsError

with self.app.temporary_depot(schema, **custom_config):
create_new_organisation(self.app, name=name, reply_to=user)

org = session.query(Organisation).first()
assert org is not None and org.theme_options is not None
org.theme_options['primary-color-ui'] = color

users = UserCollection(self.app.session_manager.session())
assert not users.query().first()

users.add(user, password, 'admin')

title = request.translate(_('Welcome to OneGov Cloud'))
welcome_mail = render_template('mail_welcome.pt', request, {
'url': 'https://{}'.format(self.get_domain(name)),
'mail': user,
'layout': MailLayout(self, request),
'title': title,
'org': name
})

self.app.perform_reindex()
self.app.send_transactional_email(
subject=title,
receivers=(user, ),
content=welcome_mail,
reply_to='onegov@seantis.ch'
)
session.flush()

finally:
self.app.session_manager.set_current_schema(current_schema)
Expand Down
Loading
Loading