UI: Improve multi OS display #205
@ -64,10 +64,12 @@ class Platform(CreatedModifiedMixin, models.Model):
|
||||
def get_by_slug(cls, slug: str):
|
||||
return cls.objects.filter(slug=slug).first()
|
||||
|
||||
@property
|
||||
def name_first_word(self):
|
||||
"""Used for presentation in download_list."""
|
||||
return self.name.split(None, 1)[0]
|
||||
|
||||
@property
|
||||
def name_rest(self):
|
||||
"""Used for presentation in download_list."""
|
||||
parts = self.name.split(None, 1)
|
||||
@ -718,6 +720,18 @@ class Version(CreatedModifiedMixin, TrackChangesMixin, models.Model):
|
||||
return file
|
||||
return None
|
||||
|
||||
def get_supported_platforms(self):
|
||||
supported_platforms = {}
|
||||
for platform in self.platforms.all():
|
||||
architectures = supported_platforms.get(platform.name_first_word, [])
|
||||
architectures.append(platform.name_rest)
|
||||
supported_platforms[platform.name_first_word] = architectures
|
||||
result = []
|
||||
for platform, architectures in sorted(supported_platforms.items()):
|
||||
item = {'name': platform, 'architectures': architectures}
|
||||
result.append(item)
|
||||
return result
|
||||
|
||||
@property
|
||||
def is_listed(self):
|
||||
# To be public, at least one version file must have a public status.
|
||||
|
@ -1,16 +1,18 @@
|
||||
{% load i18n %}
|
||||
|
||||
{% if version.platforms.all %}
|
||||
{% with supported_platforms=version.get_supported_platforms %}
|
||||
{% if supported_platforms %}
|
||||
<div class="dl-row">
|
||||
<div class="dl-col">
|
||||
<dt>{% trans "Supported Platforms" %}</dt>
|
||||
<dd>
|
||||
<ul class="list-style-none mb-0 ps-0">
|
||||
{% for p in version.platforms.all|dictsortreversed:"slug" %}
|
||||
<li><i class="i-{{ p.name_first_word|lower }}"></i> {{p.name_first_word}} <span class="text-muted">{{ p.name_rest }}</span></li>
|
||||
{% for item in supported_platforms|dictsortreversed:"name" %}
|
||||
<li><i class="i-{{ item.name|lower }}"></i> {{ item.name }} <span class="text-muted">{{ item.architectures|join:', ' }}</span></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</dd>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
Loading…
Reference in New Issue
Block a user