Commit 8bc3982f authored by felix.herrmann's avatar felix.herrmann
Browse files

Merge branch '433-publication-date-not-set-correctly' into 'master'

Resolve "publication date not set correctly"

Closes #433

See merge request !407
parents e70ce322 966f8c79
# Generated by Django 2.2.17 on 2021-11-03 10:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dddatasets', '0049_merge_20210302_1250'),
]
operations = [
migrations.AlterField(
model_name='dataset',
name='publication_date',
field=models.DateField(null=True),
),
]
# Generated by Django 2.2.17 on 2021-11-03 15:34
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('dddatasets', '0050_auto_20211103_1058'),
]
operations = [
migrations.AddField(
model_name='dataset',
name='created_at',
field=models.DateField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='dataset',
name='publication_date',
field=models.DateField(blank=True, null=True),
),
]
# Generated by Django 2.2.17 on 2021-11-03 15:34
# Generated by Django 2.2.17 on 2021-11-03 15:27
from django.db import migrations
def forwards_func(apps, schema_editor):
# set created_at to a reasonable date (= equal to publication_date)
DataSet = apps.get_model('dddatasets', 'DataSet')
for ds in DataSet.objects.all():
if ds.publication_date:
if ds.created_at > ds.publication_date:
ds.created_at = ds.publication_date
ds.save()
def reverse_func(apps, schema_editor):
# do nothing on reverse
pass
class Migration(migrations.Migration):
dependencies = [
('dddatasets', '0051_auto_20211103_1534'),
]
operations = [
migrations.RunPython(forwards_func, reverse_func),
]
......@@ -26,6 +26,7 @@ from django.utils.html import format_html
from django.utils.text import slugify
from django.utils.translation import gettext as _
from django_bleach.models import BleachField
from django.utils import timezone
from guardian.shortcuts import assign_perm, get_perms, get_users_with_perms, remove_perm
from PIL import Image
from taggit.managers import TaggableManager
......@@ -655,7 +656,6 @@ class DataSet(models.Model):
related_name="dataset_datarepository_data_repository",
on_delete=models.CASCADE,
)
publication_date = models.DateField(auto_now_add=True, null=True)
date_of_data_creation_from = models.DateField(
blank=True,
null=True,
......@@ -756,6 +756,8 @@ class DataSet(models.Model):
published_categories = models.ManyToManyField(
"Category", related_name="dataset_published_categories", blank=True
)
created_at = models.DateField(default=timezone.now)
publication_date = models.DateField(null=True, blank=True)
publication_accepted = models.BooleanField(default=False)
publication_accepted_by = models.ForeignKey(
User,
......@@ -1094,6 +1096,8 @@ class DataSet(models.Model):
ds.publication_accepted = False
ds.publication_accepted_by = None
ds.copyright_declaration = False
ds.publication_date = None
ds.created_at = timezone.now()
ds.doi = ""
ds.dhdoi = ""
ds.dsa = None
......@@ -1188,10 +1192,15 @@ class DataSet(models.Model):
else:
doi = "00.00000/00000000-0000-0000-0000-000000000000"
if self.publication_date:
year = self.publication_date.year
else:
year = timezone.now().year
return format_html(
"{} ({}): {}, v. {}, Discuss Data, <a href='https://doi.org/{}'>&lt;doi:{}&gt;</a>.",
self.creators_str(),
self.publication_date.year,
year,
self.title,
self.version,
doi,
......@@ -1488,6 +1497,8 @@ class DataSet(models.Model):
self.dataset_management_object.published = True
self.dataset_management_object.main_published_ds = self
self.dataset_management_object.save()
self.publication_date = timezone.now()
self.save()
try:
self.doi = generate_discuss_data_doi(self)
except DataCiteUnauthorizedError as e:
......
......@@ -7,6 +7,8 @@
<th>{% trans 'Title' %}</th>
<th>{% trans 'Version' %}</th>
<th>{% trans 'Status' %}</th>
<th>{% trans 'Creation date' %}</th>
<th>{% trans 'Publication date' %}</th>
<th>{% trans 'Action' %}</th>
</tr>
......@@ -20,6 +22,8 @@
<span class="badge badge-warning">{% trans "Not published" %}</span>
{% endif %}
</td>
<td>{{ ds.created_at }}</td>
<td>{{ ds.publication_date }}</td>
<td>
<div>
<button class="btn btn-primary" ic-get-from="{% url control_args.edit_url ds.uuid %}" ic-target="#ds-content">{% trans "Edit" %}</button>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment