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

Update project updated_time (#3810) #3814

Merged
merged 6 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Incorrect work when copy job list with "Copy" button (<https://github.com/openvinotoolkit/cvat/pull/3749>)
- Iterating over manifest (<https://github.com/openvinotoolkit/cvat/pull/3792>)
- Manifest removing (<https://github.com/openvinotoolkit/cvat/pull/3791>)
- Fixed project updated date (<https://github.com/openvinotoolkit/cvat/pull/3814>)
- Fixed dextr deployment (<https://github.com/openvinotoolkit/cvat/pull/3820>)
- Migration of `dataset_repo` application (<https://github.com/openvinotoolkit/cvat/pull/3827>)

Expand Down
18 changes: 18 additions & 0 deletions cvat/apps/engine/migrations/0043_auto_20211027_0718.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.13 on 2021-10-27 07:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('engine', '0042_auto_20210830_1056'),
]

operations = [
migrations.AlterField(
model_name='project',
name='updated_date',
field=models.DateTimeField(auto_now=True),
),
]
2 changes: 1 addition & 1 deletion cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class Project(models.Model):
on_delete=models.SET_NULL, related_name="+")
bug_tracker = models.CharField(max_length=2000, blank=True, default="")
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=32, choices=StatusChoice.choices(),
default=StatusChoice.ANNOTATION)
training_project = models.ForeignKey(TrainingProject, null=True, blank=True, on_delete=models.SET_NULL)
Expand Down
18 changes: 16 additions & 2 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,25 @@ def retrieve(self, request, pk=None):
raise serializers.ValidationError(
"Unexpected action specified for the request")

def perform_update(self, serializer):
instance = self.get_object()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serializer should already have the instance. Please use it: serializer.instance.
https://www.django-rest-framework.org/api-guide/serializers/#accessing-the-initial-data-and-instance

It is critical, because self.get_object will call check_object_permissions which ins't good here (it is already called in update method).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. updated.

project_id = instance.project_id
updated_instance = serializer.save()
if project_id != updated_instance.project_id:
Project.objects.get(id=project_id).save()
Project.objects.get(id=updated_instance.project_id).save()

def perform_create(self, serializer):
owner = self.request.data.get('owner', None)
if owner:
self._validate_task_limit(owner)
serializer.save()
instance = serializer.save()
else:
self._validate_task_limit(self.request.user)
serializer.save(owner=self.request.user)
instance = serializer.save(owner=self.request.user)
if instance.project:
db_project = instance.project
db_project.save()

def perform_destroy(self, instance):
task_dirname = instance.get_task_dirname()
Expand All @@ -580,6 +591,9 @@ def perform_destroy(self, instance):
if instance.data and not instance.data.tasks.all():
shutil.rmtree(instance.data.get_data_dirname(), ignore_errors=True)
instance.data.delete()
if instance.project:
db_project = instance.project
db_project.save()

@swagger_auto_schema(method='get', operation_summary='Returns a list of jobs for a specific task',
responses={'200': JobSerializer(many=True)})
Expand Down