Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1493 ruff format #1498

Merged
merged 2 commits into from
Mar 13, 2025
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
exclude = ["*"]
include = [
"vitrina/*.py",
]
line-length = 88
indent-width = 4

Expand Down
12 changes: 5 additions & 7 deletions vitrina/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@


class ClientIdFilter(admin.SimpleListFilter):
title = _('kliento id')
parameter_name = 'client_id'
title = _("kliento id")
parameter_name = "client_id"
default_value = None

def lookups(self, request, model_admin):
return [
('organization_null', _('Nepriskirti')),
("organization_null", _("Nepriskirti")),
]

def queryset(self, request, queryset):
Expand All @@ -27,11 +27,9 @@ class ApiScopeInline(admin.TabularInline):


class ApiKeyAdmin(VersionAdmin):
list_display = ('organization', 'client_id', 'client_name')
list_display = ("organization", "client_id", "client_name")
list_filter = [ClientIdFilter]
search_fields = (
'organization',
)
search_fields = ("organization",)
inlines = [ApiScopeInline]


Expand Down
4 changes: 2 additions & 2 deletions vitrina/api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class ApiConfig(AppConfig):
name = 'vitrina.api'
label = 'vitrina_api'
name = "vitrina.api"
label = "vitrina_api"
2 changes: 1 addition & 1 deletion vitrina/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DuplicateAPIKeyException(APIException):
"Baigėsi Jūsų API rakto galiojimas. "
"Raktą galite atsinaujinti savo organizacijos tvarkytojų sąraše: {url}"
)
default_code = 'duplicate_api_key'
default_code = "duplicate_api_key"

def __init__(self, detail=None, code=None, url=None):
if url:
Expand Down
2 changes: 1 addition & 1 deletion vitrina/api/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class APIKeyFactory(DjangoModelFactory):
class Meta:
model = ApiKey
django_get_or_create = ('api_key', 'enabled')
django_get_or_create = ("api_key", "enabled")

api_key = hash_api_key("test")
enabled = True
125 changes: 61 additions & 64 deletions vitrina/api/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,53 @@

def get_datasets_for_rdf(qs):
datasets = (
qs.
select_related('organization').
select_related('licence').
prefetch_related('category').
prefetch_related('translations').
prefetch_related('datasetdistribution_set').
prefetch_related('datasetdistribution_set__format').
order_by('published')
qs.select_related("organization")
.select_related("licence")
.prefetch_related("category")
.prefetch_related("translations")
.prefetch_related("datasetdistribution_set")
.prefetch_related("datasetdistribution_set__format")
.order_by("published")
)
for dataset in datasets:
distributions = [
distribution
for dist in dataset.datasetdistribution_set.all()
if (distribution := _get_distribution(dataset, dist)) is not None
distribution
for dist in dataset.datasetdistribution_set.all()
if (distribution := _get_distribution(dataset, dist)) is not None
]

if dataset.is_part_of_dataservice():
dataset_resources = DynamicResourceService(dataset)
dynamic_distributions = dataset_resources.generate_resources(is_for_rdf_export=True)
dynamic_distributions = dataset_resources.generate_resources(
is_for_rdf_export=True
)
distributions.extend(dynamic_distributions)

yield {
'uri': dataset.get_absolute_url(),
'translations': (
"uri": dataset.get_absolute_url(),
"translations": (
{
'lang': t.language_code,
'title': t.title,
'description': t.description,
"lang": t.language_code,
"title": t.title,
"description": t.description,
}
for t in dataset.translations.order_by('language_code')
for t in dataset.translations.order_by("language_code")
),
'categories': _get_categories(dataset),
'hvd_categories': [
"categories": _get_categories(dataset),
"hvd_categories": [
_get_category(c)
for c in dataset.category.filter(
groups__translations__title="Didelės vertės rinkiniai"
)
],
'keywords': [
k.name
for k in dataset.tags.all()
],
'published': dataset.published,
'modified': dataset.modified,
'organization': dataset.organization,
'frequency': _get_frequency(dataset.frequency),
'licence': _get_licence(dataset.licence),
'distributions': distributions,
'contact': _get_contact_email(dataset),
"keywords": [k.name for k in dataset.tags.all()],
"published": dataset.published,
"modified": dataset.modified,
"organization": dataset.organization,
"frequency": _get_frequency(dataset.frequency),
"licence": _get_licence(dataset.licence),
"distributions": distributions,
"contact": _get_contact_email(dataset),
}


Expand All @@ -70,31 +68,31 @@ def _get_distribution(dataset: Dataset, dist: Distribution):
if dist.format.extension in (FormatName.API, FormatName.UAPI):
if dataset.model_set.all():
return None
dist_type = 'WEB_SERVICE'
dist_type = "WEB_SERVICE"
else:
dist_type = 'DOWNLOADABLE_FILE'
dist_type = "DOWNLOADABLE_FILE"
dist_type = (
'http://publications.europa.eu/' +
'resource/authority/distribution-type/' +
dist_type
"http://publications.europa.eu/"
+ "resource/authority/distribution-type/"
+ dist_type
)

return {
'uri': dist.get_absolute_url(),
'type': dist_type,
'translations': [
"uri": dist.get_absolute_url(),
"type": dist_type,
"translations": [
{
'lang': 'lt',
'title': dist.title,
'description': dist.description,
"lang": "lt",
"title": dist.title,
"description": dist.description,
},
],
'access_url': dist.get_download_url(),
'licence': _get_licence(dataset.licence),
'format': _get_format(dist.format),
'media_type': _get_media_type(dist.format),
'created': dist.created,
'modified': dist.modified,
"access_url": dist.get_download_url(),
"licence": _get_licence(dataset.licence),
"format": _get_format(dist.format),
"media_type": _get_media_type(dist.format),
"created": dist.created,
"modified": dist.modified,
}


Expand All @@ -113,11 +111,11 @@ def _get_categories(dataset):

def _get_category(category: Category):
return {
'uri': category.uri,
'translations': [
"uri": category.uri,
"translations": [
{
'lang': 'lt',
'title': category.title,
"lang": "lt",
"title": category.title,
},
],
}
Expand All @@ -128,40 +126,39 @@ def _get_frequency(frequency: Optional[Frequency]):
return

return {
'uri': frequency.uri,
'translations': [
"uri": frequency.uri,
"translations": [
{
'lang': 'lt',
'title': frequency.title,
"lang": "lt",
"title": frequency.title,
},
{
'lang': 'en',
'title': frequency.title_en,
"lang": "en",
"title": frequency.title_en,
},
],
}


def _get_licence(licence: Optional[Licence]):
if licence and licence.url:
return {
'uri': licence.url
}
return {"uri": licence.url}


def _get_format(format: Optional[Format]):
if format and format.uri:
return {
'uri': format.uri,
"uri": format.uri,
}


def _get_media_type(format: Optional[Format]):
if format and format.media_type_uri:
return {
'uri': format.media_type_uri,
"uri": format.media_type_uri,
}


def _get_contact_email(dataset: Dataset) -> str:
dataset_contact = Contact.objects.filter(dataset=dataset).first()

Expand All @@ -174,4 +171,4 @@ def _get_contact_email(dataset: Dataset) -> str:
if dataset.organization and (email := dataset.organization.email):
return email

return ''
return ""
Loading