Skip to content

Commit

Permalink
#1: Mainly prettification
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Breitner committed Mar 10, 2023
1 parent 4d5b0d7 commit 2eb4a04
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 57 deletions.
2 changes: 2 additions & 0 deletions ddam/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
FloatingField('title'),
Field('file'),
FloatingField('source_url'),
FloatingField('copyright_statement'),
FloatingField('description'),
Div(
Expand Down Expand Up @@ -92,6 +93,7 @@ class Meta:
"file",
"description",
"copyright_statement",
"source_url",
"licence",
"usage",
]
Expand Down
19 changes: 19 additions & 0 deletions ddam/core/migrations/0003_asset_filename_orig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.1.7 on 2023-03-10 17:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0002_licence_slug_alter_usage_slug'),
]

operations = [
migrations.AddField(
model_name='asset',
name='filename_orig',
field=models.CharField(default='bla', editable=False, help_text='Original filename. Set automatically while creating an asset.', max_length=255),
preserve_default=False,
),
]
18 changes: 18 additions & 0 deletions ddam/core/migrations/0004_asset_source_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2023-03-10 18:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0003_asset_filename_orig'),
]

operations = [
migrations.AddField(
model_name='asset',
name='source_url',
field=models.URLField(blank=True, help_text='Source/Origin of asset. Give an URL.', verbose_name='Source URL'),
),
]
107 changes: 59 additions & 48 deletions ddam/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,51 @@
from django.urls import reverse


class SingletonBaseModel(models.Model):

def save(self, *args, **kwargs):
self.pk = 1
super().save(*args, **kwargs)

def delete(self, *args, **kwargs):
pass

@classmethod
def load(cls):
obj, _ = cls.objects.get_or_create(pk=1)
return obj

class Meta:
abstract = True


class AbstractUuidModel(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False,
)

class Meta:
abstract = True


class AbstractTimestampedModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
abstract = True


class AbstractUserTrackedModel(models.Model):
created_by = models.EmailField(blank=True)
updated_by = models.EmailField(blank=True)

class Meta:
abstract = True


class Usage(models.Model):

class MediaChoices(models.TextChoices):
Expand Down Expand Up @@ -55,58 +100,13 @@ def save(self, *args, **kwargs):
return super().save(*args, **kwargs)

def __str__(self):
return self.name
return f"{self.name}"

class Meta:
verbose_name = _("Usage tag")
verbose_name_plural = _("Usage tags")


class SingletonBaseModel(models.Model):

def save(self, *args, **kwargs):
self.pk = 1
super().save(*args, **kwargs)

def delete(self, *args, **kwargs):
pass

@classmethod
def load(cls):
obj, _ = cls.objects.get_or_create(pk=1)
return obj

class Meta:
abstract = True


class AbstractUuidModel(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False,
)

class Meta:
abstract = True


class AbstractTimestampedModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
abstract = True


class AbstractUserTrackedModel(models.Model):
created_by = models.EmailField(blank=True)
updated_by = models.EmailField(blank=True)

class Meta:
abstract = True


class Licence(models.Model):
name = models.CharField(
max_length=255,
Expand Down Expand Up @@ -142,7 +142,7 @@ class UsageRestriction(models.Model):
description = models.TextField(blank=True)

def __str__(self):
return self.title
return f"{self.title}"


class Asset(AbstractTimestampedModel, AbstractUserTrackedModel, AbstractUuidModel, models.Model):
Expand All @@ -155,6 +155,12 @@ class Asset(AbstractTimestampedModel, AbstractUserTrackedModel, AbstractUuidMode
blank=False,
upload_to='assets/',
)
filename_orig = models.CharField(
max_length=255,
blank=False,
editable=False,
help_text="Original filename. Set automatically while creating an asset."
)
description = models.TextField(
blank=True
)
Expand All @@ -169,6 +175,11 @@ class Asset(AbstractTimestampedModel, AbstractUserTrackedModel, AbstractUuidMode
blank=True,
help_text="Appropriate credit/Licence holder (if required by license)",
)
source_url = models.URLField(
blank=True,
verbose_name="Source URL",
help_text="Source/Origin of asset. Give an URL."
)
usage_restriction = models.ForeignKey(
'core.usagerestriction',
blank=True,
Expand Down Expand Up @@ -201,4 +212,4 @@ def get_absolute_url(self):
return reverse('core:asset-detail', kwargs={'id': self.id})

def __str__(self):
return self.title
return f"{self.title}"
2 changes: 2 additions & 0 deletions ddam/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def post(self, request, *args, **kwargs):
asset = Asset(
file=f,
title=f.name,
filename_orig=f.name,
created_by=request.user.email,
)
assets_upload.append(asset)
Expand Down Expand Up @@ -82,6 +83,7 @@ class AssetCreate(CreateView):

def form_valid(self, form):
form.instance.created_by = self.request.user.email
form.instance.filename_orig = form.cleaned_data['file'].name
return super().form_valid(form)


Expand Down
23 changes: 14 additions & 9 deletions ddam/templates/core/asset_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,26 @@
n/a
{% endfor %}
</p>
<p class="text-muted">
<span>
<div>
<span class="text-muted">
Meta
</span>
<div class="small">
Filesize: {{ asset.file.size | filesizeformat }}
<div class="small text-muted">
Filesize: <span class="font-monospace">{{ asset.file.size | filesizeformat }}</span>
<br>
Uploaded: {{ asset.created_at | naturalday }} by {{ asset.created_by }}
{% if asset.updated_at != asset.created_at %}
Orig filename: <span class="font-monospace">{{ asset.filename_orig }}</span>
<br>
Updated: {{ asset.updated_at | naturalday }}
{% if asset.updated_by %} by {{ asset.updated_by }}{% endif %}
{% if asset.source_url %}
<a href="{{ asset.source_url }}" title="{{ asset.source_url }}">
<i class="bi bi-file-binary"></i> Source URL
</a>
{% endif %}
<br>
{% include 'core/includes/asset_audit.html' with action='uploaded' timestamp=asset.created_at by=asset.created_by %}
<br>
{% include 'core/includes/asset_audit.html' with action='updated' timestamp=asset.updated_at by=asset.updated_by %}
</div>
</p>
</div>

</div>
<div class="flex-grow-1">
Expand Down
11 changes: 11 additions & 0 deletions ddam/templates/core/includes/asset_audit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load humanize %}


{{ action|title}}:
<i class="bi bi-clock"></i> {{ timestamp | naturalday }}

{% if by %}
by <a href="mailto:{{ by }}">
<i class="bi bi-envelope"></i> {{ by }}
</a>
{% endif %}

0 comments on commit 2eb4a04

Please sign in to comment.