def _set_auth_api_choices(self): autorisatie_apis = Service.objects.filter(api_type=APITypes.ac) with parallel() as executor: applications = executor.map(_get_applications, autorisatie_apis) all_apps = sum(applications, []) all_apps = sorted(all_apps, key=lambda app: app["label"]) # if there's no data, no point in showing the field at all if not all_apps: del self.fields["autorisaties_application"] return self.fields["autorisaties_application"].choices = BLANK_CHOICE_DASH + [ (application["url"], application["label"]) for application in all_apps ] # the fields themselves are always required, but if an Autorisaties API app is # selected the user does not need to input them explicitly, we can derive them. # The ``def clean`` validation validates that these fields are filled out if # there's no Autorisaties API app selected. self.fields["label"].required = False self.fields["app_id"].required = False if self.instance.pk: self.fields[ "autorisaties_application"].initial = self.instance.app_id
def get_client_response(self) -> List[dict]: variables = self.task.get_variables() email_notification_list = variables.get("emailNotificationList", {}) usernames = [] groupnames = [] emails = [] try: assignees = check_variable(variables, "usernames") for assignee in assignees: # To not change normal expected behavior: # if no emailNotificationList is found in variables everybody gets an email if email_notification_list.get( assignee) or not email_notification_list: group_or_user, name = assignee.split(":", 1) if group_or_user.lower() == "group": groupnames.append(name) else: usernames.append(name) except MissingVariable: try: emails = check_variable(variables, "emailaddresses") except MissingVariable: raise MissingVariable( "Missing one of the required variables usernames or emailaddresses." ) users = [] with get_client(self.task) as client: if usernames: username_assignees = client.get( "api/accounts/users", params={"include_username": usernames}) for user in username_assignees["results"]: user["assignee"] = f'user:{user["username"]}' users += username_assignees["results"] if groupnames: groups = {} def _get_group_users(group: str): nonlocal groups, client groups[group] = client.get( "api/accounts/users", params={"include_groups": [group]}) with parallel() as executor: list(executor.map(_get_group_users, groupnames)) for group, groupusers in groups.items(): for user in groupusers["results"]: user["assignee"] = f"group:{group}" users += groupusers["results"] if emails: users += client.get("api/accounts/users", params={"include_email": emails})["results"] return users
def fetch_zaken(zaken_urls: List[str]) -> List[dict]: with parallel() as executor: _zaken = executor.map(fetch_zaak, zaken_urls) zaken = list(_zaken) fetched_zaaktypen = get_zaaktypen(dict_response=True) for zaak in zaken: zaak["zaaktype"] = fetched_zaaktypen[zaak["zaaktype"]] return zaken
def test_db_connection_cleaned_up_map(db: None): initial = get_num_connections() assert initial >= 1 with parallel() as executor: executor.map(execute_query, [1, 2, 3]) num_conns = get_num_connections() assert num_conns == initial
def test_db_connection_cleaned_up_submit(db: None): initial = get_num_connections() assert initial >= 1 with parallel() as executor: executor.submit(execute_query) num_conns = get_num_connections() assert num_conns == initial
def get(self, request, list_id): config = ArchiveConfig.get_solo() destruction_list = DestructionList.objects.get(id=list_id) last_review = destruction_list.last_review() fetched_zaaktypen = { zaaktype["url"]: zaaktype for zaaktype in get_zaaktypen() } zaak_urls = [item.zaak for item in destruction_list.items.all()] with parallel() as executor: zaken = list(executor.map(fetch_zaak, zaak_urls)) zaken = {zaak["url"]: zaak for zaak in zaken} items = [] for item in (destruction_list.items.exclude( status=ListItemStatus.removed).order_by("id").all()): # list item data list_item_data = {"id": item.id, "status": item.status} if (last_review and last_review.item_reviews.filter( destruction_list_item=item).exists()): item_review = last_review.item_reviews.get( destruction_list_item=item) list_item_data.update({ "review_text": item_review.text, "review_suggestion": item_review.suggestion, }) # full zaak data zaak = zaken[item.zaak] zaaktype = fetched_zaaktypen[zaak["zaaktype"]] # return only general information zaak_data = {attr: zaak.get(attr) for attr in NO_DETAIL_ZAAK_ATTRS} # Add link to zaak in ZAC zaak_data["zac_link"] = get_zaak_link_for_zaakafhandelcomponent( zaak, config.link_to_zac) zaaktype_data = { attr: zaaktype.get(attr) for attr in NO_DETAIL_ZAAKTYPE_ATTRS } zaak_data["zaaktype"] = zaaktype_data zaak_data = get_additional_zaak_info(zaak_data) if (not destruction_list.contains_sensitive_info or self.request.user.role.type != RoleTypeChoices.archivist): zaak_data["omschrijving"] = zaak.get("omschrijving") items.append({"listItem": list_item_data, "zaak": zaak_data}) return JsonResponse({"items": items})
def get(self, request): zaken = get_zaken(request.GET) with parallel() as executor: zaken_with_extra_info = list(executor.map(get_additional_zaak_info, zaken)) set_zaken_availability(zaken_with_extra_info) return JsonResponse({"zaken": zaken_with_extra_info})
def perform(self) -> dict: variables = self.task.get_variables() # Retrieve io url zaak_url = check_variable(variables, "zaakUrl") zaak_informatieobjecten = self.get_zaak_informatieobjecten(zaak_url) zios = [zio["informatieobject"] for zio in zaak_informatieobjecten] # lock io and set data with parallel() as executor: responses = list(executor.map(self.lock_document, zios)) # update io with parallel() as executor: list(executor.map(self.update_document, responses)) # unlock io with parallel() as executor: list(executor.map(self.unlock_document, responses)) return {}
def get(self, request): zaak_url = request.GET.get("zaak_url") if not zaak_url: return HttpResponseBadRequest("zaak_url query parameter must be specified") with parallel() as executor: resultaat = executor.submit(get_resultaat, zaak_url) documenten = executor.submit(get_documenten, zaak_url) besluiten = executor.submit(get_besluiten, zaak_url) result = { "resultaat": resultaat.result(), "documenten": documenten.result(), "besluiten": besluiten.result(), } return JsonResponse(result)
def fetch_zaken(startdatum, zaaktypen, bronorganisaties): config = ArchiveConfig.get_solo() current_date = config.archive_date or timezone.now().date() # default params for archived zaken query = { "archiefnominatie": "vernietigen", "archiefactiedatum__lt": current_date.isoformat(), } if startdatum: query["startdatum__gte"] = startdatum.strftime("%Y-%m-%d") queries = [] if zaaktypen and bronorganisaties: for zaaktype in zaaktypen: for bronorganisatie in bronorganisaties: queries.append( dict( query, **{ "zaaktype": zaaktype, "bronorganisatie": bronorganisatie, }, )) elif zaaktypen: queries = [ dict(query, **{"zaaktype": zaaktype}) for zaaktype in zaaktypen ] elif bronorganisaties: queries = [ dict(query, **{"bronorganisatie": bronorganisatie}) for bronorganisatie in bronorganisaties ] if len(queries) > 0: with parallel() as executor: zaken = list(executor.map(get_zaken, queries)) # flat the list zaken = list(itertools.chain(*zaken)) else: zaken = get_zaken(query_params=query) return zaken