Skip to content
Draft
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
10 changes: 6 additions & 4 deletions cli/util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_arguments(default: str) -> Namespace:
return parser.parse_args()


def open_yml_file(file: str) -> Any:
def open_yml_file(file: str) -> Any: # Maybe could be used somewhere else?
print(os.path.abspath(file))
if os.path.isfile(file):
with open(file, "rb") as x:
Expand All @@ -33,18 +33,20 @@ def open_yml_file(file: str) -> Any:
return yaml.safe_load(models_yml)


def get_collection_names_and_filenames() -> dict[str, str]:
def get_collection_names_and_filenames() -> (
dict[str, str]
): # Not used. But maybe could?
filenames = sorted(os.listdir(SOURCE_COLLECTIONS))
return {os.path.splitext(filename)[0]: filename for filename in filenames}


def load_fields(filename: str) -> dict[str, Any]:
def load_fields(filename: str) -> dict[str, Any]: # Not used. But maybe could?
path = f"{SOURCE_COLLECTIONS}/{filename}"
content = get_file_content_text(path)
return yaml.safe_load(content)


def get_file_content_text(file: str) -> str:
def get_file_content_text(file: str) -> str: # Not used. But maybe could?
if os.path.isfile(file):
with open(file) as x:
return x.read()
Expand Down
14 changes: 0 additions & 14 deletions openslides_backend/action/actions/agenda_item/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ class AgendaItemForward(SingularActionMixin, UpdateAction):
meeting_id: int
use_meeting_ids_for_archived_meeting_check = True

def get_meeting_id(self, instance: dict[str, Any]) -> int:
if origin_item_ids := instance.get("agenda_item_ids"):
return self.datastore.get(
fqid_from_collection_and_id("agenda_item", origin_item_ids[0]),
["meeting_id"],
)["meeting_id"]
elif origin_item_ids == []:
raise ActionException(
"Cannot forward an agenda without the agenda_item_ids."
)
elif "id" in instance or "meeting_id" in instance:
return super().get_meeting_id(instance)
return self.meeting_id

def check_permissions(self, instance: dict[str, Any]) -> None:
meeting_ids = set(instance.get("meeting_ids", []))
agenda_items = self.datastore.get_many(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def check_permissions(self, instance: dict[str, Any]) -> None:
else:
permission = Permissions.Assignment.CAN_NOMINATE_OTHER
if not has_perm(self.datastore, self.user_id, permission, meeting_id):
missing_permission = permission
missing_permission = permission #

if missing_permission:
raise MissingPermission(missing_permission)
raise MissingPermission(missing_permission) #
4 changes: 2 additions & 2 deletions openslides_backend/action/actions/committee/import_.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ def update_rows_from_results(
for i in range(len(val)):
if isinstance(val[i], str):
if val[i] not in name_map:
val[i] = None
val[i] = None #
else:
val[i] = name_map[val[i]]
entry[self.field_map.get(field, field)] = list(filter(None, val))
else:
if isinstance(val, str):
if val not in name_map:
val = None
val = None #
else:
val = name_map[val]
entry[self.field_map.get(field, field)] = val
Expand Down
6 changes: 3 additions & 3 deletions openslides_backend/action/actions/committee/json_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def check_meetings(self) -> None:
"Template meetings can only be used for existing committees."
)
elif not entry.get("meeting_name"):
pass # message was already created in meeting_checks
pass # message was already created in meeting_checks - test it
else:
meetings = meeting_map[(template, committee_id)]
if len(meetings) > 1:
Expand All @@ -342,7 +342,7 @@ def check_meetings(self) -> None:

def is_same_day(self, dt_a: datetime | None, dt_b: datetime | None) -> bool:
if dt_a is None or dt_b is None:
return dt_a == dt_b
return dt_a == dt_b #
return dt_a.date() == dt_b.date()

def validate_with_lookup(
Expand Down Expand Up @@ -375,7 +375,7 @@ def validate_with_lookup(
else:
obj["info"] = ImportState.WARNING
missing.append(name)
elif result == ResultType.FOUND_MORE_IDS:
elif result == ResultType.FOUND_MORE_IDS: #
duplicates.append(name)
objects.append(obj)
if missing:
Expand Down
4 changes: 3 additions & 1 deletion openslides_backend/action/actions/mediafile/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ def get_meeting_id(self, instance: dict[str, Any]) -> int:
return id_
elif "meeting_id" in instance:
return instance["meeting_id"]
raise ActionException("Try to get a meeting id from a organization mediafile.")
raise ActionException(
"Try to get a meeting id from a organization mediafile."
) #

def get_owner_data(self, instance: dict[str, Any]) -> tuple[str, int]:
owner_id = instance.get("owner_id")
Expand Down
2 changes: 1 addition & 1 deletion openslides_backend/action/actions/mediafile/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def prepare_move_data(
)
for id_ in ids:
if id_ not in db_instances:
raise ActionException(f"Id {id_} not in db_instances.")
raise ActionException(f"Id {id_} not in db_instances.") #
if db_instances[id_].get(
"published_to_meetings_in_organization_id"
) and not db_instances[id_].get("parent_id"):
Expand Down
4 changes: 3 additions & 1 deletion openslides_backend/action/actions/mediafile/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def get_updated_instances(self, instances: ActionData) -> ActionData:
instance["inherited_access_group_ids"],
)
else:
raise ActionException("Cannot update access groups without meeting_id")
raise ActionException(
"Cannot update access groups without meeting_id"
) #

def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
instance = super().update_instance(instance)
Expand Down
6 changes: 3 additions & 3 deletions openslides_backend/action/actions/mediafile/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def get_updated_instances(self, action_data: ActionData) -> ActionData:
)
if len(results) == 0:
continue
elif len(results) == 1:
elif len(results) == 1: #
id = next(iter(results))
self.execute_other_action(MediafileDelete, [{"id": id}])
else:
else: #
text = f'Database corrupt: The resource token has to be unique, but there are {len(results)} tokens "{instance.get("token")}".'
self.logger.error(text)
raise ActionException(text)
Expand Down Expand Up @@ -173,7 +173,7 @@ def get_pdf_information(self, file_bytes: bytes) -> PDFInformation:
try:
pdf = PdfReader(bytes_io)
return {"pages": len(pdf.pages)}
except PdfReadError:
except PdfReadError: #
# File could be encrypted but not be detected by pypdf.
return {
"pages": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ def check_owner(self, mediafile: dict[str, Any], instance: dict[str, Any]) -> No
owner_id = mediafile["owner_id"]
collection, id_ = owner_id.split(KEYSEPARATOR)
if collection == "meeting" and int(id_) != instance["id"]:
raise ActionException("Mediafile has to belong to this meeting..")
raise ActionException("Mediafile has to belong to this meeting..") #
6 changes: 3 additions & 3 deletions openslides_backend/action/actions/meeting/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
for meeting_user in meeting_json.get("meeting_user", {}).values():
if (value := meeting_user.get("vote_weight")) is not None:
if Decimal(value) < vote_weight_min:
meeting_user["vote_weight"] = "0.000001"
meeting_user["vote_weight"] = "0.000001" #
else:
user_id = meeting_user.get("user_id", 0)
value = (
Expand All @@ -152,13 +152,13 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
.get("default_vote_weight")
)
if value is not None and Decimal(value) < vote_weight_min:
meeting_user["vote_weight"] = "0.000001"
meeting_user["vote_weight"] = "0.000001" #

# Necessary, because the check otherwise raise exception, even if user will not be imported
for user in meeting_json.get("user", {}).values():
if (value := user.get("default_vote_weight")) is not None:
if Decimal(value) < vote_weight_min:
user["default_vote_weight"] = "0.000001"
user["default_vote_weight"] = "0.000001" #

# check datavalidation
checker = Checker(
Expand Down
8 changes: 2 additions & 6 deletions openslides_backend/action/actions/meeting/import_.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def replace_field_ids(
) -> None:
model_field = model_registry[collection].try_get_field(field)
if model_field is None:
raise ActionException(f"{collection}/{field} is not allowed.")
raise ActionException(f"{collection}/{field} is not allowed.") #
if isinstance(model_field, BaseRelationField):
if isinstance(model_field, BaseGenericRelationField):
content_list = (
Expand Down Expand Up @@ -653,9 +653,7 @@ def upload_mediadata(self) -> None:
replaced_id = self.replace_map["mediafile"][id_]
self.media.upload_mediafile(blob, replaced_id, mimetype)

def create_events(
self, instance: dict[str, Any], pure_create_events: bool = False
) -> Iterable[Event]:
def create_events(self, instance: dict[str, Any]) -> Iterable[Event]:
"""Be careful, this method is also used by meeting.clone!"""
json_data = instance["meeting"]
meeting = self.get_meeting_from_json(json_data)
Expand Down Expand Up @@ -704,8 +702,6 @@ def create_events(
)
)

if pure_create_events:
return events
events.extend(update_events)

# add meeting to committee/meeting_ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
if instance.get("additional_submitter"):
instance["additional_submitter"] += ", " + text_submitter
else:
instance["additional_submitter"] = text_submitter
instance["additional_submitter"] = text_submitter #
else:
name = committee.get("name", f"Committee {committee['id']}")
instance["additional_submitter"] = name
Expand Down
4 changes: 2 additions & 2 deletions openslides_backend/action/actions/motion/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
raise ActionException(error_messages[0]["message"])
if instance.get("lead_motion_id"):
if instance.get("text") and "amendment_paragraphs" in instance:
del instance["amendment_paragraphs"]
del instance["amendment_paragraphs"] #
if instance.get("amendment_paragraphs") and "text" in instance:
del instance["text"]
del instance["text"] #
if amendment_paragraphs := instance.get("amendment_paragraphs"):
self.validate_amendment_paragraphs(instance)
instance["amendment_paragraphs"] = Jsonb(amendment_paragraphs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_updated_instances(self, action_data: ActionData) -> ActionData:
return action_data

def check_permissions(self, instance: dict[str, Any]) -> None:
super().check_permissions(instance)
super().check_permissions(instance) # this whole method

# check if origin motion is normal or statute_amendment
origin = self.datastore.get(
Expand Down
4 changes: 2 additions & 2 deletions openslides_backend/action/actions/motion/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def get_updated_instances(
def get_history_information(self) -> HistoryInformation | None:
information = super().get_history_information()
if self.history_information is None:
return information
return information #
# generate the history informations for the deleted amendments
fqids = [
fqid_from_collection_and_id("motion", id_) for id_ in self.all_motion_ids
]
if not information:
information = {fqid: [self.history_information] for fqid in fqids}
information = {fqid: [self.history_information] for fqid in fqids} #
else:
for fqid in fqids:
information[fqid] = [self.history_information]
Expand Down
2 changes: 1 addition & 1 deletion openslides_backend/action/actions/motion/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def create_history_information_for_field(
if field in instance:
value = instance.pop(field)
if value is None:
return [verbose_collection + " removed"]
return [verbose_collection + " removed"] #
else:
return [
verbose_collection + " set to {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ def get_updated_instances(self, action_data: ActionData) -> ActionData:
}
for field in ("options", "stable", "type"):
if instance.get(field):
data[field] = instance[field]
data[field] = instance[field] #
self.execute_other_action(ProjectionCreate, [data])
return []
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
if field == "scroll" and new_value < 0:
new_value = 0
else:
raise ActionException(f"Unknown direction {direction}")
raise ActionException(f"Unknown direction {direction}") #
instance[field] = new_value
return instance
2 changes: 1 addition & 1 deletion openslides_backend/action/actions/projector/next.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ def get_min_preview_projection(self, projector: dict[str, Any]) -> int:
pivot = preview_projections[0]
for projection in preview_projections:
if pivot.get("weight", 10000) > projection.get("weight", 10000):
pivot = projection
pivot = projection #
return pivot["id"]
2 changes: 1 addition & 1 deletion openslides_backend/action/actions/projector/previous.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ def get_max_history_projection(self, projector: dict[str, Any]) -> int:
pivot = history_projections[0]
for projection in history_projections:
if pivot.get("weight", 10000) < projection.get("weight", 10000):
pivot = projection
pivot = projection #
return pivot["id"]
7 changes: 2 additions & 5 deletions openslides_backend/action/actions/speaker/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
list_of_speakers_id = instance["list_of_speakers_id"]
max_weight = self._get_max_weight(list_of_speakers_id, instance["meeting_id"])
if max_weight is None:
if not answer_to:
instance["weight"] = 1
return instance
else:
max_weight = 0
instance["weight"] = 1
return instance

if not instance.get("point_of_order") and not (
is_interposed_question or is_intervention
Expand Down
2 changes: 0 additions & 2 deletions openslides_backend/action/actions/topic/import_.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any

from ....permissions.permissions import Permissions
from ....shared.exceptions import ActionException
from ....shared.patterns import fqid_from_collection_and_id
from ...mixins.import_mixins import BaseImportAction, ImportState
from ...util.register import register_action
Expand Down Expand Up @@ -40,4 +39,3 @@ def get_meeting_id(self, instance: dict[str, Any]) -> int:
)
if worker.get("name") == TopicImport.import_name:
return next(iter(worker.get("result", {})["rows"]))["data"]["meeting_id"]
raise ActionException("Import data cannot be found.")
6 changes: 3 additions & 3 deletions openslides_backend/action/actions/user/base_json_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def validate_entry(self, entry: dict[str, Any]) -> dict[str, Any]:
),
)
else:
check_result = ResultType.NOT_FOUND
check_result = ResultType.NOT_FOUND #
id_ = 0
if check_result == ResultType.FOUND_ID and id_ != 0:
username = self.names_email_lookup.get_field_by_name(
Expand Down Expand Up @@ -506,9 +506,9 @@ def check_field_failures(

if not entry.get("id"):
if "username" in failing_fields:
failing_fields.remove("username")
failing_fields.remove("username") #
if "member_number" in failing_fields:
failing_fields.remove("member_number")
failing_fields.remove("member_number") #

verbose_ff = [
field if field != "home_committee_id" else "home_committee"
Expand Down
4 changes: 2 additions & 2 deletions openslides_backend/action/actions/user/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check_permissions(self, instance: dict[str, Any]) -> None:
self.check_permissions_for_scope(instance["id"])

def get_removed_meeting_id(self, instance: dict[str, Any]) -> int | None:
return 0
return 0 #

@original_instances
def get_updated_instances(self, action_data: ActionData) -> ActionData:
Expand All @@ -45,7 +45,7 @@ def get_updated_instances(self, action_data: ActionData) -> ActionData:

def check_meeting_admin_integrity(self, delete_data: list[int] = []) -> None:
if not len(delete_data):
return
return #
meeting_ids_to_user_ids: dict[int, list[int]] = {}
users = self.datastore.get_many(
[GetManyRequest("user", delete_data, ["meeting_ids", "meeting_user_ids"])]
Expand Down
2 changes: 1 addition & 1 deletion openslides_backend/action/actions/user/merge_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_full_history_information(self) -> HistoryInformation | None:
if fqid not in information:
information[fqid] = ["Supporters merged"]
else:
information[fqid].append("Supporters merged")
information[fqid].append("Supporters merged") #
return information


Expand Down
Loading
Loading