From 626b9d63d755b67a7e81e297d4f0482d53540910 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 27 Sep 2024 16:01:43 -0700 Subject: [PATCH 01/16] Add Media Collection Feature to Django Admin --- TEKDB/TEKDB/admin.py | 18 ++++++++ TEKDB/TEKDB/forms.py | 26 +++++++++++ .../migrations/0013_auto_20240927_1553.py | 43 +++++++++++++++++++ TEKDB/TEKDB/models.py | 19 +++++++- .../templates/admin/MediaCollectionForm.html | 5 +++ TEKDB/TEKDB/views.py | 41 +++++++++++++++++- ...figuration_preferredinitialismplacement.py | 18 ++++++++ 7 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 TEKDB/TEKDB/forms.py create mode 100644 TEKDB/TEKDB/migrations/0013_auto_20240927_1553.py create mode 100644 TEKDB/TEKDB/templates/admin/MediaCollectionForm.html create mode 100644 TEKDB/configuration/migrations/0010_alter_configuration_preferredinitialismplacement.py diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index 41b7a5b3..542e28b7 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -440,6 +440,24 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin): ) form = CitationsForm +# * Media COllection Admin +from .models import MediaCollection +from .forms import MediaCollectionForm + +class MediaCollectionAdmin(admin.ModelAdmin): + form = MediaCollectionForm + + def save_model(self, request, obj, form, change): + super().save_model(request, obj, form, change) + for file in request.FILES.getlist('files'): + Media.objects.create( + collection=obj, + mediafile=file, + date=form.cleaned_data['date'], + ) + +admin.site.register(MediaCollection, MediaCollectionAdmin) + class MediaAdmin(RecordAdminProxy, RecordModelAdmin): readonly_fields = ('medialink', 'enteredbyname', 'enteredbytribe','enteredbytitle','enteredbydate', diff --git a/TEKDB/TEKDB/forms.py b/TEKDB/TEKDB/forms.py new file mode 100644 index 00000000..1c76956e --- /dev/null +++ b/TEKDB/TEKDB/forms.py @@ -0,0 +1,26 @@ +from django import forms +from .models import MediaCollection, Media + +class MultipleFileInput(forms.ClearableFileInput): + allow_multiple_selected = True + +class MultipleFileField(forms.FileField): + def __init__(self, *args, **kwargs): + kwargs.setdefault("widget", MultipleFileInput()) + super().__init__(*args, **kwargs) + + def clean(self, data, initial=None): + single_file_clean = super().clean + if isinstance(data, (list, tuple)): + result = [single_file_clean(d, initial) for d in data] + else: + result = [single_file_clean(data, initial)] + return result + +class MediaCollectionForm(forms.ModelForm): + files = MultipleFileField() + date = forms.DateField(widget=forms.SelectDateWidget) + + class Meta: + model = MediaCollection + fields = ['name', 'files', 'date'] \ No newline at end of file diff --git a/TEKDB/TEKDB/migrations/0013_auto_20240927_1553.py b/TEKDB/TEKDB/migrations/0013_auto_20240927_1553.py new file mode 100644 index 00000000..05965e14 --- /dev/null +++ b/TEKDB/TEKDB/migrations/0013_auto_20240927_1553.py @@ -0,0 +1,43 @@ +# Generated by Django 3.2.25 on 2024-09-27 22:53 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('TEKDB', '0012_auto_20240926_1440'), + ] + + operations = [ + migrations.CreateModel( + name='MediaCollection', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(blank=True, max_length=255, null=True)), + ('created_at', models.DateTimeField(auto_now_add=True, null=True)), + ('updated_at', models.DateTimeField(auto_now=True, null=True)), + ], + ), + migrations.AddField( + model_name='media', + name='created_at', + field=models.DateTimeField(auto_now_add=True, null=True), + ), + migrations.AddField( + model_name='media', + name='date', + field=models.DateField(blank=True, default=None, null=True), + ), + migrations.AddField( + model_name='media', + name='updated_at', + field=models.DateTimeField(auto_now=True, null=True), + ), + migrations.AddField( + model_name='media', + name='collection', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='media_records', to='TEKDB.mediacollection'), + ), + ] diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index 75b729a2..a647d8a2 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1830,6 +1830,15 @@ def __unicode__(self): def __str__(self): return self.username or '' + +# * Media Collection +# * + +class MediaCollection(models.Model): + name = models.CharField(max_length=255, blank=True, null=True) + created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) + updated_at = models.DateTimeField(auto_now=True, blank=True, null=True) + class Media(Reviewable, Queryable, Record, ModeratedModel): mediaid = models.AutoField(db_column='mediaid', primary_key=True) mediatype = models.ForeignKey(LookupMediaType, db_column='mediatype', max_length=255, blank=True, null=True, verbose_name='type', default=None, on_delete=models.SET_DEFAULT) @@ -1839,6 +1848,14 @@ class Media(Reviewable, Queryable, Record, ModeratedModel): mediafile = models.FileField(db_column='mediafile', max_length=255, blank=True, null=True, verbose_name='file') limitedaccess = models.BooleanField(db_column='limitedaccess', null=True, default=False, verbose_name='limited access?') + # * Media Collection + collection = models.ForeignKey(MediaCollection, related_name='media_records', on_delete=models.CASCADE, blank=True, null=True) + date = models.DateField(blank=True, null=True, default=None) + created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) + updated_at = models.DateTimeField(auto_now=True, blank=True, null=True) + + + class Meta: managed = MANAGED db_table = 'media' @@ -2880,4 +2897,4 @@ def save(self, *args, **kwargs): self.is_superuser = True else: self.is_superuser = False - super(Users, self).save(*args, **kwargs) + super(Users, self).save(*args, **kwargs) \ No newline at end of file diff --git a/TEKDB/TEKDB/templates/admin/MediaCollectionForm.html b/TEKDB/TEKDB/templates/admin/MediaCollectionForm.html new file mode 100644 index 00000000..6f3dc194 --- /dev/null +++ b/TEKDB/TEKDB/templates/admin/MediaCollectionForm.html @@ -0,0 +1,5 @@ +
+ {% csrf_token %} + {{ form.as_p }} + +
\ No newline at end of file diff --git a/TEKDB/TEKDB/views.py b/TEKDB/TEKDB/views.py index 1b826633..7040cdd4 100644 --- a/TEKDB/TEKDB/views.py +++ b/TEKDB/TEKDB/views.py @@ -9,7 +9,7 @@ from django.db.models import Q from django.db.utils import OperationalError from django.http import HttpResponse, Http404, FileResponse, JsonResponse -from django.shortcuts import render +from django.shortcuts import render, redirect import io import os import shutil @@ -344,3 +344,42 @@ def get_queryset(self): ) return qs.order_by(Lower('activityshortdescription__activity'), Lower('placeresourceid__placeid__indigenousplacename'), Lower('placeresourceid__resourceid__commonname')) + + +from django.views import View +from .models import MediaCollection, Media +from .forms import MediaCollectionForm + +# class FileFieldFormView(FormView): +# form_class = MediaCollectionForm +# template_name = "admin/MediaCollectionForm.html" # Replace with your template. +# success_url = reverse() # Replace with your URL or reverse(). + +# def form_valid(self, form): +# media_collection = form.save() +# for file in request.FILES.getlist('files'): +# Media.objects.create( +# collection=media_collection, +# file=file, +# date=form.cleaned_data['date'], +# location=form.cleaned_data['location'], +# species=form.cleaned_data['species'] +# ) +# return super().form_valid(form) + +class MediaCollectionCreateView(View): + def get(self, request): + form = MediaCollectionForm() + return render(request, 'admin/MediaCollectionForm.html', {'form': form}) + + def post(self, request): + form = MediaCollectionForm(request.POST, request.FILES) + if form.is_valid(): + media_collection = form.save() + for file in request.FILES.getlist('files'): + Media.objects.create( + collection=media_collection, + file=file, + ) + return redirect('media_collection_list') + return render(request, 'admin/MediaCollectionForm.html', {'form': form}) \ No newline at end of file diff --git a/TEKDB/configuration/migrations/0010_alter_configuration_preferredinitialismplacement.py b/TEKDB/configuration/migrations/0010_alter_configuration_preferredinitialismplacement.py new file mode 100644 index 00000000..f3b087c8 --- /dev/null +++ b/TEKDB/configuration/migrations/0010_alter_configuration_preferredinitialismplacement.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.25 on 2024-09-27 22:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('configuration', '0009_configuration_preferredinitialismplacement'), + ] + + operations = [ + migrations.AlterField( + model_name='configuration', + name='preferredInitialismPlacement', + field=models.CharField(choices=[('default', 'Default'), ('before', 'Before'), ('after', 'After')], default=('default', 'Default'), help_text='Select the position of the preferred initialism in relative to the logo.', max_length=255), + ), + ] From 689ee9bdd7b1634fc9c1907cafe6ee3c1fb9cd8e Mon Sep 17 00:00:00 2001 From: David Pollard Date: Tue, 1 Oct 2024 15:35:30 -0700 Subject: [PATCH 02/16] Use correct name for media collection --- TEKDB/TEKDB/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index a647d8a2..bbc9de90 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1849,7 +1849,7 @@ class Media(Reviewable, Queryable, Record, ModeratedModel): limitedaccess = models.BooleanField(db_column='limitedaccess', null=True, default=False, verbose_name='limited access?') # * Media Collection - collection = models.ForeignKey(MediaCollection, related_name='media_records', on_delete=models.CASCADE, blank=True, null=True) + collection = models.ForeignKey(MediaCollection, related_name='media_collection', on_delete=models.CASCADE, blank=True, null=True) date = models.DateField(blank=True, null=True, default=None) created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) updated_at = models.DateTimeField(auto_now=True, blank=True, null=True) From ac7b6f90e6d011f96b4f73ae7a401f51fd477a00 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 4 Oct 2024 13:20:00 -0700 Subject: [PATCH 03/16] Changing Media Collection to Media Bulk Upload. Add additional fields from media --- TEKDB/TEKDB/admin.py | 10 ++++---- TEKDB/TEKDB/forms.py | 6 ++--- TEKDB/TEKDB/models.py | 56 +++++++++++++++++++++++++++++++++++++++++-- TEKDB/TEKDB/views.py | 18 +++++++------- 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index 542e28b7..5f850f7f 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -441,11 +441,11 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin): form = CitationsForm # * Media COllection Admin -from .models import MediaCollection -from .forms import MediaCollectionForm +from .models import MediaBulkUpload +from .forms import MediaBulkUploadForm -class MediaCollectionAdmin(admin.ModelAdmin): - form = MediaCollectionForm +class MediaBulkUploadAdmin(admin.ModelAdmin): + form = MediaBulkUploadForm def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) @@ -456,7 +456,7 @@ def save_model(self, request, obj, form, change): date=form.cleaned_data['date'], ) -admin.site.register(MediaCollection, MediaCollectionAdmin) +admin.site.register(MediaBulkUpload, MediaBulkUploadAdmin) class MediaAdmin(RecordAdminProxy, RecordModelAdmin): readonly_fields = ('medialink', diff --git a/TEKDB/TEKDB/forms.py b/TEKDB/TEKDB/forms.py index 1c76956e..81d94576 100644 --- a/TEKDB/TEKDB/forms.py +++ b/TEKDB/TEKDB/forms.py @@ -1,5 +1,5 @@ from django import forms -from .models import MediaCollection, Media +from .models import MediaBulkUpload, Media class MultipleFileInput(forms.ClearableFileInput): allow_multiple_selected = True @@ -17,10 +17,10 @@ def clean(self, data, initial=None): result = [single_file_clean(data, initial)] return result -class MediaCollectionForm(forms.ModelForm): +class MediaBulkUploadForm(forms.ModelForm): files = MultipleFileField() date = forms.DateField(widget=forms.SelectDateWidget) class Meta: - model = MediaCollection + model = MediaBulkUpload fields = ['name', 'files', 'date'] \ No newline at end of file diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index bbc9de90..3952b0cc 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1834,10 +1834,62 @@ def __str__(self): # * Media Collection # * -class MediaCollection(models.Model): +# Through tables or one to many relationship, reference Anna's work on MidA +# * PlacesMediaEvents +# * ResourcesMediaEvents +# * MediaCitationEvents +# * ResourceActivityMediaEvents +# * PlacesResourceMediaEvents + +# Change name to reflect that this is a bulk media upload event +# Sorting +class MediaBulkUpload(models.Model): name = models.CharField(max_length=255, blank=True, null=True) + description = models.TextField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) updated_at = models.DateTimeField(auto_now=True, blank=True, null=True) + user = models.ForeignKey(LookupUserInfo, db_column='user', blank=True, null=True, verbose_name='user', default=None, on_delete=models.SET_DEFAULT) + media = models.ManyToManyField('Media', related_name='media', blank=True, null=True) + + # @property + # def count(self): + # number of media items uploaded + + # Suggested Additions + # Multi upload + # Visual displayed of uploads + # Example in blue pages + # Gallery of Media + # Ability to edit Media + + # Media Fields + Relationships + # mediatype = models.ForeignKey(LookupMediaType, db_column='mediatype', max_length=255, blank=True, null=True, verbose_name='type', default=None, on_delete=models.SET_DEFAULT) + # medianame = models.CharField(db_column='medianame', max_length=255, blank=True, null=True, verbose_name='name') + # mediadescription = RichTextField(db_column='mediadescription', blank=True, null=True, verbose_name='description', config_name="custom") #CKEditor Rich Text Editor Field + # medialink = models.CharField(db_column='medialink', max_length=255, blank=True, null=True, verbose_name='historic location') + # mediafile = models.FileField(db_column='mediafile', max_length=255, blank=True, null=True, verbose_name='file') + + # PlaceMedia relationship + # other 5 relationships ... + # def relationships(self): + # relationship_list = [] + # places = [x.get_relationship_json(type(self)) for x in self.placesmediaevents_set.all()] + # if len(places) > 0: + # relationship_list.append({'key': 'Places', 'value': places}) + # resources = [x.get_relationship_json(type(self)) for x in self.resourcesmediaevents_set.all()] + # if len(resources) > 0: + # relationship_list.append({'key': 'Resources', 'value': resources}) + # citations = [x.get_relationship_json(type(self)) for x in self.mediacitationevents_set.all()] + # if len(citations) > 0: + # relationship_list.append({'key': 'Bibliographic Sources', 'value': citations}) + # activities = [x.get_relationship_json(type(self)) for x in self.resourceactivitymediaevents_set.all()] + # if len(activities) > 0: + # relationship_list.append({'key': 'Activities', 'value': activities}) + # placeresources = [x.get_relationship_json(type(self)) for x in self.placesresourcemediaevents_set.all()] + # if len(placeresources) > 0: + # relationship_list.append({'key': 'Place-Resources', 'value': placeresources}) + # return relationship_list + class Media(Reviewable, Queryable, Record, ModeratedModel): mediaid = models.AutoField(db_column='mediaid', primary_key=True) @@ -1849,7 +1901,7 @@ class Media(Reviewable, Queryable, Record, ModeratedModel): limitedaccess = models.BooleanField(db_column='limitedaccess', null=True, default=False, verbose_name='limited access?') # * Media Collection - collection = models.ForeignKey(MediaCollection, related_name='media_collection', on_delete=models.CASCADE, blank=True, null=True) + media_collection = models.ManyToManyField(MediaBulkUpload, related_name='media_collection', blank=True, null=True) date = models.DateField(blank=True, null=True, default=None) created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) updated_at = models.DateTimeField(auto_now=True, blank=True, null=True) diff --git a/TEKDB/TEKDB/views.py b/TEKDB/TEKDB/views.py index 7040cdd4..a3d239c2 100644 --- a/TEKDB/TEKDB/views.py +++ b/TEKDB/TEKDB/views.py @@ -347,12 +347,12 @@ def get_queryset(self): from django.views import View -from .models import MediaCollection, Media -from .forms import MediaCollectionForm +from .models import MediaBulkUpload, Media +from .forms import MediaBulkUploadForm # class FileFieldFormView(FormView): -# form_class = MediaCollectionForm -# template_name = "admin/MediaCollectionForm.html" # Replace with your template. +# form_class = MediaBulkUploadForm +# template_name = "admin/MediaBulkUploadForm.html" # Replace with your template. # success_url = reverse() # Replace with your URL or reverse(). # def form_valid(self, form): @@ -367,13 +367,13 @@ def get_queryset(self): # ) # return super().form_valid(form) -class MediaCollectionCreateView(View): +class MediaBulkUploadCreateView(View): def get(self, request): - form = MediaCollectionForm() - return render(request, 'admin/MediaCollectionForm.html', {'form': form}) + form = MediaBulkUploadForm() + return render(request, 'admin/MediaBulkUploadForm.html', {'form': form}) def post(self, request): - form = MediaCollectionForm(request.POST, request.FILES) + form = MediaBulkUploadForm(request.POST, request.FILES) if form.is_valid(): media_collection = form.save() for file in request.FILES.getlist('files'): @@ -382,4 +382,4 @@ def post(self, request): file=file, ) return redirect('media_collection_list') - return render(request, 'admin/MediaCollectionForm.html', {'form': form}) \ No newline at end of file + return render(request, 'admin/MediaBulkUploadForm.html', {'form': form}) \ No newline at end of file From a8a165a89e29ae54e26b4e02553f508e2f79c42a Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 4 Oct 2024 13:20:23 -0700 Subject: [PATCH 04/16] Add migration for previous commit --- .../migrations/0014_auto_20241004_1319.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 TEKDB/TEKDB/migrations/0014_auto_20241004_1319.py diff --git a/TEKDB/TEKDB/migrations/0014_auto_20241004_1319.py b/TEKDB/TEKDB/migrations/0014_auto_20241004_1319.py new file mode 100644 index 00000000..9d0eb134 --- /dev/null +++ b/TEKDB/TEKDB/migrations/0014_auto_20241004_1319.py @@ -0,0 +1,47 @@ +# Generated by Django 3.2.25 on 2024-10-04 20:19 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('Lookup', '0005_alter_lookupuserinfo_id'), + ('TEKDB', '0013_auto_20240927_1553'), + ] + + operations = [ + migrations.CreateModel( + name='MediaBulkUpload', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(blank=True, max_length=255, null=True)), + ('description', models.TextField(blank=True, null=True)), + ('created_at', models.DateTimeField(auto_now_add=True, null=True)), + ('updated_at', models.DateTimeField(auto_now=True, null=True)), + ], + ), + migrations.RemoveField( + model_name='media', + name='collection', + ), + migrations.DeleteModel( + name='MediaCollection', + ), + migrations.AddField( + model_name='mediabulkupload', + name='media', + field=models.ManyToManyField(blank=True, null=True, related_name='media', to='TEKDB.Media'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='user', + field=models.ForeignKey(blank=True, db_column='user', default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='Lookup.lookupuserinfo', verbose_name='user'), + ), + migrations.AddField( + model_name='media', + name='media_collection', + field=models.ManyToManyField(blank=True, null=True, related_name='media_collection', to='TEKDB.MediaBulkUpload'), + ), + ] From 94790ca2aa86311b1ea53991a5d5aec1957d37e1 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 4 Oct 2024 15:59:35 -0700 Subject: [PATCH 05/16] Multiple Media uploads with ForeignKey to mediabulkupload --- TEKDB/TEKDB/admin.py | 19 ++++++-- TEKDB/TEKDB/forms.py | 6 ++- ...927_1553.py => 0013_auto_20241004_1547.py} | 27 ++++------- .../0014_alter_media_mediauploadevent.py | 19 ++++++++ .../migrations/0014_auto_20241004_1319.py | 47 ------------------- TEKDB/TEKDB/models.py | 12 ++--- .../widgets/thumbnail_file_input.html | 6 +++ TEKDB/TEKDB/views.py | 39 --------------- TEKDB/TEKDB/widgets.py | 14 +++++- 9 files changed, 70 insertions(+), 119 deletions(-) rename TEKDB/TEKDB/migrations/{0013_auto_20240927_1553.py => 0013_auto_20241004_1547.py} (52%) create mode 100644 TEKDB/TEKDB/migrations/0014_alter_media_mediauploadevent.py delete mode 100644 TEKDB/TEKDB/migrations/0014_auto_20241004_1319.py create mode 100644 TEKDB/TEKDB/templates/widgets/thumbnail_file_input.html diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index 5f850f7f..0f9d471d 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -450,11 +450,22 @@ class MediaBulkUploadAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) for file in request.FILES.getlist('files'): - Media.objects.create( - collection=obj, + media_instance = Media( mediafile=file, - date=form.cleaned_data['date'], ) + media_instance.save() + obj.mediabulkupload.set([media_instance]) + + def thumbnail_gallery(self, obj): + thumbnails = [ + format_html('', media.mediafile.url) + for media in obj.mediabulkupload.all() + ] + return format_html(''.join(thumbnails)) + + thumbnail_gallery.short_description = 'Thumbnails' + + readonly_fields = ('thumbnail_gallery',) admin.site.register(MediaBulkUpload, MediaBulkUploadAdmin) @@ -466,7 +477,7 @@ class MediaAdmin(RecordAdminProxy, RecordModelAdmin): 'enteredbyname','enteredbydate') fieldsets = ( (None, { - 'fields': (('medianame','mediatype','limitedaccess'),'mediafile','medialink','mediadescription',) + 'fields': (('medianame','mediatype','limitedaccess'),'mediafile','medialink','mediadescription','media_collection',) }), ('Review', { 'fields': ( diff --git a/TEKDB/TEKDB/forms.py b/TEKDB/TEKDB/forms.py index 81d94576..015c31a6 100644 --- a/TEKDB/TEKDB/forms.py +++ b/TEKDB/TEKDB/forms.py @@ -1,5 +1,6 @@ from django import forms from .models import MediaBulkUpload, Media +from .widgets import ThumbnailFileInput class MultipleFileInput(forms.ClearableFileInput): allow_multiple_selected = True @@ -17,10 +18,13 @@ def clean(self, data, initial=None): result = [single_file_clean(data, initial)] return result +# class MultipleFileField(forms.FileField): +# widget = ThumbnailFileInput + class MediaBulkUploadForm(forms.ModelForm): files = MultipleFileField() date = forms.DateField(widget=forms.SelectDateWidget) class Meta: model = MediaBulkUpload - fields = ['name', 'files', 'date'] \ No newline at end of file + fields = ['name', 'description', 'files', 'date'] \ No newline at end of file diff --git a/TEKDB/TEKDB/migrations/0013_auto_20240927_1553.py b/TEKDB/TEKDB/migrations/0013_auto_20241004_1547.py similarity index 52% rename from TEKDB/TEKDB/migrations/0013_auto_20240927_1553.py rename to TEKDB/TEKDB/migrations/0013_auto_20241004_1547.py index 05965e14..750cb883 100644 --- a/TEKDB/TEKDB/migrations/0013_auto_20240927_1553.py +++ b/TEKDB/TEKDB/migrations/0013_auto_20241004_1547.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.25 on 2024-09-27 22:53 +# Generated by Django 3.2.25 on 2024-10-04 22:47 from django.db import migrations, models import django.db.models.deletion @@ -7,37 +7,26 @@ class Migration(migrations.Migration): dependencies = [ + ('Lookup', '0005_alter_lookupuserinfo_id'), ('TEKDB', '0012_auto_20240926_1440'), ] operations = [ migrations.CreateModel( - name='MediaCollection', + name='MediaBulkUpload', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(blank=True, max_length=255, null=True)), + ('description', models.TextField(blank=True, null=True)), + ('date', models.DateField(blank=True, default=None, null=True)), ('created_at', models.DateTimeField(auto_now_add=True, null=True)), ('updated_at', models.DateTimeField(auto_now=True, null=True)), + ('user', models.ForeignKey(blank=True, db_column='user', default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='Lookup.lookupuserinfo', verbose_name='user')), ], ), migrations.AddField( model_name='media', - name='created_at', - field=models.DateTimeField(auto_now_add=True, null=True), - ), - migrations.AddField( - model_name='media', - name='date', - field=models.DateField(blank=True, default=None, null=True), - ), - migrations.AddField( - model_name='media', - name='updated_at', - field=models.DateTimeField(auto_now=True, null=True), - ), - migrations.AddField( - model_name='media', - name='collection', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='media_records', to='TEKDB.mediacollection'), + name='mediauploadevent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='mediabulkupload', to='TEKDB.mediabulkupload'), ), ] diff --git a/TEKDB/TEKDB/migrations/0014_alter_media_mediauploadevent.py b/TEKDB/TEKDB/migrations/0014_alter_media_mediauploadevent.py new file mode 100644 index 00000000..0b511fb9 --- /dev/null +++ b/TEKDB/TEKDB/migrations/0014_alter_media_mediauploadevent.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.25 on 2024-10-04 22:55 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('TEKDB', '0013_auto_20241004_1547'), + ] + + operations = [ + migrations.AlterField( + model_name='media', + name='mediauploadevent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='mediauploadevent', to='TEKDB.mediabulkupload'), + ), + ] diff --git a/TEKDB/TEKDB/migrations/0014_auto_20241004_1319.py b/TEKDB/TEKDB/migrations/0014_auto_20241004_1319.py deleted file mode 100644 index 9d0eb134..00000000 --- a/TEKDB/TEKDB/migrations/0014_auto_20241004_1319.py +++ /dev/null @@ -1,47 +0,0 @@ -# Generated by Django 3.2.25 on 2024-10-04 20:19 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('Lookup', '0005_alter_lookupuserinfo_id'), - ('TEKDB', '0013_auto_20240927_1553'), - ] - - operations = [ - migrations.CreateModel( - name='MediaBulkUpload', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(blank=True, max_length=255, null=True)), - ('description', models.TextField(blank=True, null=True)), - ('created_at', models.DateTimeField(auto_now_add=True, null=True)), - ('updated_at', models.DateTimeField(auto_now=True, null=True)), - ], - ), - migrations.RemoveField( - model_name='media', - name='collection', - ), - migrations.DeleteModel( - name='MediaCollection', - ), - migrations.AddField( - model_name='mediabulkupload', - name='media', - field=models.ManyToManyField(blank=True, null=True, related_name='media', to='TEKDB.Media'), - ), - migrations.AddField( - model_name='mediabulkupload', - name='user', - field=models.ForeignKey(blank=True, db_column='user', default=None, null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='Lookup.lookupuserinfo', verbose_name='user'), - ), - migrations.AddField( - model_name='media', - name='media_collection', - field=models.ManyToManyField(blank=True, null=True, related_name='media_collection', to='TEKDB.MediaBulkUpload'), - ), - ] diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index 3952b0cc..1520bb16 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1846,10 +1846,10 @@ def __str__(self): class MediaBulkUpload(models.Model): name = models.CharField(max_length=255, blank=True, null=True) description = models.TextField(blank=True, null=True) + date = models.DateField(blank=True, null=True, default=None) created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) updated_at = models.DateTimeField(auto_now=True, blank=True, null=True) user = models.ForeignKey(LookupUserInfo, db_column='user', blank=True, null=True, verbose_name='user', default=None, on_delete=models.SET_DEFAULT) - media = models.ManyToManyField('Media', related_name='media', blank=True, null=True) # @property # def count(self): @@ -1900,13 +1900,9 @@ class Media(Reviewable, Queryable, Record, ModeratedModel): mediafile = models.FileField(db_column='mediafile', max_length=255, blank=True, null=True, verbose_name='file') limitedaccess = models.BooleanField(db_column='limitedaccess', null=True, default=False, verbose_name='limited access?') - # * Media Collection - media_collection = models.ManyToManyField(MediaBulkUpload, related_name='media_collection', blank=True, null=True) - date = models.DateField(blank=True, null=True, default=None) - created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) - updated_at = models.DateTimeField(auto_now=True, blank=True, null=True) - - + # * Media Bulk Upload Event + mediabulkupload = models.ForeignKey(MediaBulkUpload, related_name='mediabulkupload', blank=True, null=True, on_delete=models.SET_NULL) + # media_collection = models.ForeignKey(MediaBulkUpload, related_name='mediauploadevent', blank=True, null=True, on_delete=models.SET_NULL) class Meta: managed = MANAGED diff --git a/TEKDB/TEKDB/templates/widgets/thumbnail_file_input.html b/TEKDB/TEKDB/templates/widgets/thumbnail_file_input.html new file mode 100644 index 00000000..04ba4993 --- /dev/null +++ b/TEKDB/TEKDB/templates/widgets/thumbnail_file_input.html @@ -0,0 +1,6 @@ +{% if widget.value %} +
+ {{ widget.value }} +
+{% endif %} + \ No newline at end of file diff --git a/TEKDB/TEKDB/views.py b/TEKDB/TEKDB/views.py index a3d239c2..260251d7 100644 --- a/TEKDB/TEKDB/views.py +++ b/TEKDB/TEKDB/views.py @@ -344,42 +344,3 @@ def get_queryset(self): ) return qs.order_by(Lower('activityshortdescription__activity'), Lower('placeresourceid__placeid__indigenousplacename'), Lower('placeresourceid__resourceid__commonname')) - - -from django.views import View -from .models import MediaBulkUpload, Media -from .forms import MediaBulkUploadForm - -# class FileFieldFormView(FormView): -# form_class = MediaBulkUploadForm -# template_name = "admin/MediaBulkUploadForm.html" # Replace with your template. -# success_url = reverse() # Replace with your URL or reverse(). - -# def form_valid(self, form): -# media_collection = form.save() -# for file in request.FILES.getlist('files'): -# Media.objects.create( -# collection=media_collection, -# file=file, -# date=form.cleaned_data['date'], -# location=form.cleaned_data['location'], -# species=form.cleaned_data['species'] -# ) -# return super().form_valid(form) - -class MediaBulkUploadCreateView(View): - def get(self, request): - form = MediaBulkUploadForm() - return render(request, 'admin/MediaBulkUploadForm.html', {'form': form}) - - def post(self, request): - form = MediaBulkUploadForm(request.POST, request.FILES) - if form.is_valid(): - media_collection = form.save() - for file in request.FILES.getlist('files'): - Media.objects.create( - collection=media_collection, - file=file, - ) - return redirect('media_collection_list') - return render(request, 'admin/MediaBulkUploadForm.html', {'form': form}) \ No newline at end of file diff --git a/TEKDB/TEKDB/widgets.py b/TEKDB/TEKDB/widgets.py index a2a2d81a..b1ba4568 100644 --- a/TEKDB/TEKDB/widgets.py +++ b/TEKDB/TEKDB/widgets.py @@ -59,4 +59,16 @@ class Media: js = ( 'assets/openlayers6/ol.js', 'gis/js/OL6MapPolygonWidget.js', - ) \ No newline at end of file + ) + + +from django.forms.widgets import ClearableFileInput +from django.utils.safestring import mark_safe + +class ThumbnailFileInput(ClearableFileInput): + template_name = 'widgets/thumbnail_file_input.html' + + def format_value(self, value): + if value and hasattr(value, 'url'): + return mark_safe(f'') + return super().format_value(value) \ No newline at end of file From 36e6b0b5a629eb209f29acd5794251a07c038fc4 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 4 Oct 2024 15:59:56 -0700 Subject: [PATCH 06/16] Add additional migrations --- .../migrations/0015_auto_20241004_1559.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 TEKDB/TEKDB/migrations/0015_auto_20241004_1559.py diff --git a/TEKDB/TEKDB/migrations/0015_auto_20241004_1559.py b/TEKDB/TEKDB/migrations/0015_auto_20241004_1559.py new file mode 100644 index 00000000..8ecc5443 --- /dev/null +++ b/TEKDB/TEKDB/migrations/0015_auto_20241004_1559.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.25 on 2024-10-04 22:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('TEKDB', '0014_alter_media_mediauploadevent'), + ] + + operations = [ + migrations.RemoveField( + model_name='media', + name='mediauploadevent', + ), + migrations.AddField( + model_name='media', + name='mediabulkupload', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='mediabulkupload', to='TEKDB.mediabulkupload'), + ), + ] From f9f4ff692f0d11f1147b15264e0d97d4db022a6c Mon Sep 17 00:00:00 2001 From: David Pollard Date: Tue, 8 Oct 2024 13:52:12 -0700 Subject: [PATCH 07/16] Added name for media from bulk upload --- TEKDB/TEKDB/admin.py | 14 ++++++++++++-- TEKDB/TEKDB/models.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index 0f9d471d..620b1cd9 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -441,7 +441,9 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin): form = CitationsForm # * Media COllection Admin -from .models import MediaBulkUpload +from django.utils.html import format_html +from django.contrib import admin +from .models import MediaBulkUpload, Media from .forms import MediaBulkUploadForm class MediaBulkUploadAdmin(admin.ModelAdmin): @@ -451,10 +453,12 @@ def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) for file in request.FILES.getlist('files'): media_instance = Media( + medianame=obj.name, + mediadescription=obj.description, mediafile=file, ) media_instance.save() - obj.mediabulkupload.set([media_instance]) + obj.mediabulkupload.add(media_instance) def thumbnail_gallery(self, obj): thumbnails = [ @@ -467,6 +471,12 @@ def thumbnail_gallery(self, obj): readonly_fields = ('thumbnail_gallery',) + fieldsets = ( + (None, { + 'fields': ('name', 'description', 'files', 'date', 'thumbnail_gallery') + }), + ) + admin.site.register(MediaBulkUpload, MediaBulkUploadAdmin) class MediaAdmin(RecordAdminProxy, RecordModelAdmin): diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index 1520bb16..907e8a2f 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1902,7 +1902,7 @@ class Media(Reviewable, Queryable, Record, ModeratedModel): # * Media Bulk Upload Event mediabulkupload = models.ForeignKey(MediaBulkUpload, related_name='mediabulkupload', blank=True, null=True, on_delete=models.SET_NULL) - # media_collection = models.ForeignKey(MediaBulkUpload, related_name='mediauploadevent', blank=True, null=True, on_delete=models.SET_NULL) + media_collection = models.ForeignKey(MediaBulkUpload, related_name='mediauploadevent', blank=True, null=True, on_delete=models.SET_NULL) class Meta: managed = MANAGED From 802e64d53d588d9b11d75eb70a736251a6389534 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Tue, 8 Oct 2024 13:54:24 -0700 Subject: [PATCH 08/16] Fix the media_collection --- TEKDB/TEKDB/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index 907e8a2f..1520bb16 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1902,7 +1902,7 @@ class Media(Reviewable, Queryable, Record, ModeratedModel): # * Media Bulk Upload Event mediabulkupload = models.ForeignKey(MediaBulkUpload, related_name='mediabulkupload', blank=True, null=True, on_delete=models.SET_NULL) - media_collection = models.ForeignKey(MediaBulkUpload, related_name='mediauploadevent', blank=True, null=True, on_delete=models.SET_NULL) + # media_collection = models.ForeignKey(MediaBulkUpload, related_name='mediauploadevent', blank=True, null=True, on_delete=models.SET_NULL) class Meta: managed = MANAGED From 47660216d32c14fec90cdf576819588179eab031 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Wed, 9 Oct 2024 17:08:04 -0700 Subject: [PATCH 09/16] Finish changing media_collection to mediabulkupload --- TEKDB/TEKDB/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index 1520bb16..3c596332 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1902,7 +1902,6 @@ class Media(Reviewable, Queryable, Record, ModeratedModel): # * Media Bulk Upload Event mediabulkupload = models.ForeignKey(MediaBulkUpload, related_name='mediabulkupload', blank=True, null=True, on_delete=models.SET_NULL) - # media_collection = models.ForeignKey(MediaBulkUpload, related_name='mediauploadevent', blank=True, null=True, on_delete=models.SET_NULL) class Meta: managed = MANAGED From 9b991efa85fdc45c5bb26a539aa7ddca79e99527 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 11 Oct 2024 10:56:15 -0700 Subject: [PATCH 10/16] Get rid of extra media_collection in admin --- TEKDB/TEKDB/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index 620b1cd9..d655189e 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -487,7 +487,7 @@ class MediaAdmin(RecordAdminProxy, RecordModelAdmin): 'enteredbyname','enteredbydate') fieldsets = ( (None, { - 'fields': (('medianame','mediatype','limitedaccess'),'mediafile','medialink','mediadescription','media_collection',) + 'fields': (('medianame','mediatype','limitedaccess'),'mediafile','medialink','mediadescription',) }), ('Review', { 'fields': ( From 54bb6f4b7c84f2114fe45a24ac44da5854430a1a Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 11 Oct 2024 10:56:29 -0700 Subject: [PATCH 11/16] Remove comments --- TEKDB/TEKDB/models.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index 3c596332..47d4d03f 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1841,8 +1841,7 @@ def __str__(self): # * ResourceActivityMediaEvents # * PlacesResourceMediaEvents -# Change name to reflect that this is a bulk media upload event -# Sorting +# add Sorting class MediaBulkUpload(models.Model): name = models.CharField(max_length=255, blank=True, null=True) description = models.TextField(blank=True, null=True) From d10493c2653cbe7d4b2948ab6de63ebaa681bed1 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 11 Oct 2024 12:56:07 -0700 Subject: [PATCH 12/16] Revise imports in admin --- TEKDB/TEKDB/admin.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index d655189e..30236cd6 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -11,6 +11,7 @@ from ckeditor.widgets import CKEditorWidget from reversion.admin import VersionAdmin +from .forms import MediaBulkUploadForm from .models import * from TEKDB.settings import ADMIN_SITE_HEADER @@ -440,12 +441,8 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin): ) form = CitationsForm -# * Media COllection Admin -from django.utils.html import format_html -from django.contrib import admin -from .models import MediaBulkUpload, Media -from .forms import MediaBulkUploadForm +# * Bulk Media Upload Admin class MediaBulkUploadAdmin(admin.ModelAdmin): form = MediaBulkUploadForm @@ -479,6 +476,7 @@ def thumbnail_gallery(self, obj): admin.site.register(MediaBulkUpload, MediaBulkUploadAdmin) + class MediaAdmin(RecordAdminProxy, RecordModelAdmin): readonly_fields = ('medialink', 'enteredbyname', 'enteredbytribe','enteredbytitle','enteredbydate', From d18ecff0c167bd1c53878cbf25b2b3c6b3d24255 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Fri, 11 Oct 2024 13:14:40 -0700 Subject: [PATCH 13/16] Add relationships for Media when uploading a bulk media --- TEKDB/TEKDB/admin.py | 28 +++++++++++++++++++++++++--- TEKDB/TEKDB/forms.py | 9 +++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index 30236cd6..d26ecdee 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -448,6 +448,12 @@ class MediaBulkUploadAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) + places = form.cleaned_data.get('places') + resources = form.cleaned_data.get('resources') + citations = form.cleaned_data.get('citations') + activities = form.cleaned_data.get('activities') + placeresources = form.cleaned_data.get('placeresources') + for file in request.FILES.getlist('files'): media_instance = Media( medianame=obj.name, @@ -457,6 +463,24 @@ def save_model(self, request, obj, form, change): media_instance.save() obj.mediabulkupload.add(media_instance) + # Add relationships + if places: + for place in places: + PlacesMediaEvents.objects.create(placeid=place, mediaid=media_instance) + if resources: + for resource in resources: + ResourcesMediaEvents.objects.create(resourceid=resource, mediaid=media_instance) + if citations: + for citation in citations: + MediaCitationEvents.objects.create(citationid=citation, mediaid=media_instance) + if activities: + for activity in activities: + ResourceActivityMediaEvents.objects.create(resourceactivityid=activity, mediaid=media_instance) + if placeresources: + for placeresource in placeresources: + PlaceResourceMediaEvents.objects.create(placeresourceid=placeresource, mediaid=media_instance) + + def thumbnail_gallery(self, obj): thumbnails = [ format_html('', media.mediafile.url) @@ -465,12 +489,10 @@ def thumbnail_gallery(self, obj): return format_html(''.join(thumbnails)) thumbnail_gallery.short_description = 'Thumbnails' - readonly_fields = ('thumbnail_gallery',) - fieldsets = ( (None, { - 'fields': ('name', 'description', 'files', 'date', 'thumbnail_gallery') + 'fields': ('name', 'description', 'files', 'date', 'places', 'resources', 'citations', 'activities', 'placeresources', 'thumbnail_gallery') }), ) diff --git a/TEKDB/TEKDB/forms.py b/TEKDB/TEKDB/forms.py index 015c31a6..8f010e81 100644 --- a/TEKDB/TEKDB/forms.py +++ b/TEKDB/TEKDB/forms.py @@ -1,5 +1,5 @@ from django import forms -from .models import MediaBulkUpload, Media +from .models import MediaBulkUpload, Media, Places, Resources, Citations, ResourcesActivityEvents, PlacesResourceMediaEvents from .widgets import ThumbnailFileInput class MultipleFileInput(forms.ClearableFileInput): @@ -24,7 +24,12 @@ def clean(self, data, initial=None): class MediaBulkUploadForm(forms.ModelForm): files = MultipleFileField() date = forms.DateField(widget=forms.SelectDateWidget) + places = forms.ModelMultipleChoiceField(queryset=Places.objects.all(), required=False) + resources = forms.ModelMultipleChoiceField(queryset=Resources.objects.all(), required=False) + citations = forms.ModelMultipleChoiceField(queryset=Citations.objects.all(), required=False) + activities = forms.ModelMultipleChoiceField(queryset=ResourcesActivityEvents.objects.all(), required=False) + placeresources = forms.ModelMultipleChoiceField(queryset=PlacesResourceMediaEvents.objects.all(), required=False) class Meta: model = MediaBulkUpload - fields = ['name', 'description', 'files', 'date'] \ No newline at end of file + fields = ['name', 'description', 'files', 'date', 'places', 'resources', 'citations', 'activities', 'placeresources'] \ No newline at end of file From a4076b09ee32dac2a2ea2b87beaa6d1eeb4e3168 Mon Sep 17 00:00:00 2001 From: Anna Cho <103462904+bwithchewoo@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:00:15 -0700 Subject: [PATCH 14/16] changed how thumbnails are displayed based on file type, fixed None showing for indigenous and english names --- TEKDB/TEKDB/admin.py | 60 ++++++++++++++++-- TEKDB/TEKDB/models.py | 24 ++++++- .../assets/audio-x-generic-symbolic.svg | 1 + TEKDB/TEKDB/static/assets/doc-text.svg | 1 + TEKDB/TEKDB/static/assets/unknown-mail.png | Bin 0 -> 10506 bytes TEKDB/TEKDB/static/assets/video-x-generic.svg | 1 + TEKDB/explore/context_processors.py | 1 + 7 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 TEKDB/TEKDB/static/assets/audio-x-generic-symbolic.svg create mode 100644 TEKDB/TEKDB/static/assets/doc-text.svg create mode 100644 TEKDB/TEKDB/static/assets/unknown-mail.png create mode 100644 TEKDB/TEKDB/static/assets/video-x-generic.svg diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index 620b1cd9..8d10070b 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -6,6 +6,8 @@ from django.utils.html import format_html from django.utils.translation import ugettext, ugettext_lazy as _ from dal import autocomplete +from mimetypes import guess_type +from django.templatetags.static import static # from moderation.admin import ModerationAdmin import nested_admin from ckeditor.widgets import CKEditorWidget @@ -461,10 +463,60 @@ def save_model(self, request, obj, form, change): obj.mediabulkupload.add(media_instance) def thumbnail_gallery(self, obj): - thumbnails = [ - format_html('', media.mediafile.url) - for media in obj.mediabulkupload.all() - ] + thumbnails = [] + for media in obj.mediabulkupload.all(): + # Guess the MIME type of the file + mime_type, _ = guess_type(media.mediafile.url) + + file_name = media.mediafile.name + + if mime_type: + if mime_type.startswith('image'): + thumbnails.append(format_html( + '
' + '' + '
{}' + '
', media.mediafile.url, file_name)) + elif mime_type.startswith('video'): + thumbnails.append(format_html( + '
' + '' + '
{}' + '
', media.mediafile.url, mime_type, file_name)) + elif mime_type.startswith('audio'): + generic_audio_icon = static('assets/audio-x-generic.svg') + thumbnails.append(format_html( + '
' + 'Audio File' + '
{}' + '
', generic_audio_icon, file_name)) + elif mime_type.startswith('text') or 'application/msword' in mime_type or 'application/vnd' in mime_type: + generic_doc_icon = static('assets/doc-text.svg') + thumbnails.append(format_html( + '
' + 'Document File' + '
{}' + '
', generic_doc_icon, file_name)) + else: + # For unknown or other file types, show a generic file image + generic_file_icon = static('assets/unknown-mail.png') + thumbnails.append(format_html( + '
' + 'File' + '
{}' + '
', generic_file_icon, file_name)) + else: + # In case the MIME type could not be determined, use a generic file icon + generic_file_icon = static('assets/unknown-mail.png') + thumbnails.append(format_html( + '
' + 'File' + '
{}' + '
', generic_file_icon, file_name)) + return format_html(''.join(thumbnails)) thumbnail_gallery.short_description = 'Thumbnails' diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index 1520bb16..475c2181 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -512,10 +512,30 @@ def get_related_objects(self, object_id): ] def __unicode__(self): - return unicode('%s (%s)' % (self.indigenousplacename, self.englishplacename)) + indigenous = self.indigenousplacename or "" + english = self.englishplacename or "" + + if indigenous and english: + return u'%s (%s)' % (indigenous, english) + elif indigenous: + return unicode(indigenous) + elif english: + return unicode(english) + else: + return u'No Name Given' def __str__(self): - return "%s (%s)" % (self.indigenousplacename, self.englishplacename) or '' + indigenous = self.indigenousplacename or "" + english = self.englishplacename or "" + + if indigenous and english: + return "%s (%s)" % (indigenous, english) + elif indigenous: + return indigenous + elif english: + return english + else: + return "No Name Given" class LookupResourceGroup(DefaultModeratedModel, ModeratedModel): id = models.AutoField(db_column='id', primary_key=True) diff --git a/TEKDB/TEKDB/static/assets/audio-x-generic-symbolic.svg b/TEKDB/TEKDB/static/assets/audio-x-generic-symbolic.svg new file mode 100644 index 00000000..e62ffdf8 --- /dev/null +++ b/TEKDB/TEKDB/static/assets/audio-x-generic-symbolic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/TEKDB/TEKDB/static/assets/doc-text.svg b/TEKDB/TEKDB/static/assets/doc-text.svg new file mode 100644 index 00000000..0993a48a --- /dev/null +++ b/TEKDB/TEKDB/static/assets/doc-text.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/TEKDB/TEKDB/static/assets/unknown-mail.png b/TEKDB/TEKDB/static/assets/unknown-mail.png new file mode 100644 index 0000000000000000000000000000000000000000..7620a662c8c98a7315970d2ca8cc2a051b7b0d48 GIT binary patch literal 10506 zcmeHtc{CK>|M#6iv{_0EvSi8jK_w|nWJ%VMHDsxj5F<;NEJH~pOC$v4`@-uK@3ec$(XU-y0QQzJv|{d;)# z008#uT-G!O015v^0=8Z7&zf)77W~8Psjg$n27mn79G<}MyWKBadIG@yjq!_!lV<0G zL>@1#t6nCU+g?7`J#GOXA0JsKHy6*F*WGW)VmurZ7gTrw5CS@y7fpSW<_G=mCiw&o zFSpAd`93OR%GPv8?C9oDO7t=gRn{++__>O ze3*^XzW*3o+Te-)R;-U}zRYmELo!jzn0WC@`nT;r(ekTn9G1m%hs0t${Zn2KZ?pWf z9#ur~FMN3pgIaA_^$p>vp8u)-yCn-kT^?ludo=sT7Kh}oJ-l*_7IIea0_*)RInY3)7y#ExbWMeMXEJ=p>AyrKt4V%x?+Z3UgTEXHpPMk$T18R%gBWv53?iDP zQaq!UIN(1Y^X7P*tkN`U$IkY9D+2dG1bnW+&=V(Dz7EIc2RT%-s2#Qmm?T=_t}WLY zPp(w22v9nQe+*v4m5YGW6D9mxW|Xa}bQYpDaOllcjp^w8qH5SX7TXbGGc+!D!ZYaP z$g5~FPJL4F!m(xRprzpnlJ;1=poAgCcR4=&X&#{?f<&{Xd*2IWXX6B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Y^wvxMzotKc-4V;Ltu0+7v%U^~6vy z*GdEqm@?O(d}UbeV#F^Tg3zsTJFjHDpWcquisk|v@@JM(L@RH>w<{<0s@Pph=~20k z%={%tJWKU_e)dG;(96PB>|QV;pptAZS~hG=Hoz}o1(Og7ESPy!esd+Vw@!R+34CYb zrPDd;=)0W4kFoT~F5+CtGk zHt3qheOM0YfbkWJP7WhHnAY0kq*I|!&h`trrkJfuBK(+DP($HxpY{2chTxyt}rydv7CK6B(4w|^=EpHQqhkPa|K@v^` z_$*CA0&gW2U}3VQhv}@9B%QB+0-BhrsXq-fDi<%)FuK_#LregnAZn-jYKk686!33d zRlzsB(O^~+U_3L*&e}wTR)|lKaOpB*>iS?oS5HZ@J;-L}r^}wW>NY1DL>BufQ?xw8 z(V6*`BE#dDO8=tER-#$P#u4dzbWU}?04IY?VlIj8*X4cTrLiK{v^P0E#m!6#JJ7%6 f5>R|_kW5EJs~p9oPO3eD`4{MD8EWRK+lTxIWgs#Z literal 0 HcmV?d00001 diff --git a/TEKDB/TEKDB/static/assets/video-x-generic.svg b/TEKDB/TEKDB/static/assets/video-x-generic.svg new file mode 100644 index 00000000..a208932d --- /dev/null +++ b/TEKDB/TEKDB/static/assets/video-x-generic.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/TEKDB/explore/context_processors.py b/TEKDB/explore/context_processors.py index 6579a656..1ca70275 100644 --- a/TEKDB/explore/context_processors.py +++ b/TEKDB/explore/context_processors.py @@ -20,6 +20,7 @@ def explore_context(request): ###################################### project_logo_text = 'ITK' + # project_text_placement = "default" if settings: try: From 6c8101a8bab29cbd431404b9e6d76b75066f9019 Mon Sep 17 00:00:00 2001 From: David Pollard Date: Wed, 16 Oct 2024 16:03:04 -0700 Subject: [PATCH 15/16] Use convention for MediaBulkUpload Model of class parameters Queryable, Record, Reviewable, and ModeratedMedia --- TEKDB/TEKDB/admin.py | 8 ++- TEKDB/TEKDB/forms.py | 4 +- .../migrations/0016_auto_20241016_1549.py | 71 +++++++++++++++++++ .../migrations/0017_auto_20241016_1552.py | 32 +++++++++ TEKDB/TEKDB/models.py | 32 ++++----- 5 files changed, 122 insertions(+), 25 deletions(-) create mode 100644 TEKDB/TEKDB/migrations/0016_auto_20241016_1549.py create mode 100644 TEKDB/TEKDB/migrations/0017_auto_20241016_1552.py diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index e905e817..2dfdbbed 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -448,6 +448,8 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin): class MediaBulkUploadAdmin(admin.ModelAdmin): form = MediaBulkUploadForm + list_display = ('mediabulkname',) + def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) places = form.cleaned_data.get('places') @@ -458,8 +460,8 @@ def save_model(self, request, obj, form, change): for file in request.FILES.getlist('files'): media_instance = Media( - medianame=obj.name, - mediadescription=obj.description, + medianame=obj.mediabulkname, + mediadescription=obj.mediabulkdescription, mediafile=file, ) media_instance.save() @@ -544,7 +546,7 @@ def thumbnail_gallery(self, obj): readonly_fields = ('thumbnail_gallery',) fieldsets = ( (None, { - 'fields': ('name', 'description', 'files', 'date', 'places', 'resources', 'citations', 'activities', 'placeresources', 'thumbnail_gallery') + 'fields': ('mediabulkname', 'mediabulkdescription', 'files', 'mediabulkdate', 'places', 'resources', 'citations', 'activities', 'placeresources', 'thumbnail_gallery') }), ) diff --git a/TEKDB/TEKDB/forms.py b/TEKDB/TEKDB/forms.py index 8f010e81..c53a696d 100644 --- a/TEKDB/TEKDB/forms.py +++ b/TEKDB/TEKDB/forms.py @@ -23,7 +23,7 @@ def clean(self, data, initial=None): class MediaBulkUploadForm(forms.ModelForm): files = MultipleFileField() - date = forms.DateField(widget=forms.SelectDateWidget) + mediabulkdate = forms.DateField(widget=forms.SelectDateWidget) places = forms.ModelMultipleChoiceField(queryset=Places.objects.all(), required=False) resources = forms.ModelMultipleChoiceField(queryset=Resources.objects.all(), required=False) citations = forms.ModelMultipleChoiceField(queryset=Citations.objects.all(), required=False) @@ -32,4 +32,4 @@ class MediaBulkUploadForm(forms.ModelForm): class Meta: model = MediaBulkUpload - fields = ['name', 'description', 'files', 'date', 'places', 'resources', 'citations', 'activities', 'placeresources'] \ No newline at end of file + fields = ['mediabulkname', 'mediabulkdescription', 'files', 'mediabulkdate', 'places', 'resources', 'citations', 'activities', 'placeresources'] \ No newline at end of file diff --git a/TEKDB/TEKDB/migrations/0016_auto_20241016_1549.py b/TEKDB/TEKDB/migrations/0016_auto_20241016_1549.py new file mode 100644 index 00000000..823f0def --- /dev/null +++ b/TEKDB/TEKDB/migrations/0016_auto_20241016_1549.py @@ -0,0 +1,71 @@ +# Generated by Django 3.2.25 on 2024-10-16 22:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('TEKDB', '0015_auto_20241004_1559'), + ] + + operations = [ + migrations.RemoveField( + model_name='mediabulkupload', + name='created_at', + ), + migrations.RemoveField( + model_name='mediabulkupload', + name='updated_at', + ), + migrations.AddField( + model_name='mediabulkupload', + name='enteredbydate', + field=models.DateTimeField(auto_now_add=True, db_column='enteredbydate', null=True, verbose_name='entered by date'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='enteredbyname', + field=models.CharField(blank=True, db_column='enteredbyname', max_length=25, null=True, verbose_name='entered by name'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='enteredbytitle', + field=models.CharField(blank=True, db_column='enteredbytitle', max_length=100, null=True, verbose_name='entered by title'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='enteredbytribe', + field=models.CharField(blank=True, db_column='enteredbytribe', max_length=100, null=True, verbose_name='entered by tribe'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='modifiedbydate', + field=models.DateTimeField(auto_now=True, db_column='modifiedbydate', null=True, verbose_name='modified by date'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='modifiedbyname', + field=models.CharField(blank=True, db_column='modifiedbyname', max_length=25, null=True, verbose_name='modified by name'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='modifiedbytitle', + field=models.CharField(blank=True, db_column='modifiedbytitle', max_length=100, null=True, verbose_name='modified by title'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='modifiedbytribe', + field=models.CharField(blank=True, db_column='modifiedbytribe', max_length=100, null=True, verbose_name='modified by tribe'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='needsReview', + field=models.BooleanField(db_column='needsreview', default=True, verbose_name='Needs Review'), + ), + migrations.AddField( + model_name='mediabulkupload', + name='researchComments', + field=models.TextField(blank=True, db_column='researchcomments', default=None, null=True, verbose_name='Research Comments'), + ), + ] diff --git a/TEKDB/TEKDB/migrations/0017_auto_20241016_1552.py b/TEKDB/TEKDB/migrations/0017_auto_20241016_1552.py new file mode 100644 index 00000000..d1835fd1 --- /dev/null +++ b/TEKDB/TEKDB/migrations/0017_auto_20241016_1552.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.25 on 2024-10-16 22:52 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('TEKDB', '0016_auto_20241016_1549'), + ] + + operations = [ + migrations.RenameField( + model_name='mediabulkupload', + old_name='date', + new_name='mediabulkdate', + ), + migrations.RenameField( + model_name='mediabulkupload', + old_name='description', + new_name='mediabulkdescription', + ), + migrations.RenameField( + model_name='mediabulkupload', + old_name='name', + new_name='mediabulkname', + ), + migrations.RemoveField( + model_name='mediabulkupload', + name='user', + ), + ] diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index 35b52728..ba13dc1a 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1851,31 +1851,23 @@ def __str__(self): return self.username or '' -# * Media Collection -# * - -# Through tables or one to many relationship, reference Anna's work on MidA -# * PlacesMediaEvents -# * ResourcesMediaEvents -# * MediaCitationEvents -# * ResourceActivityMediaEvents -# * PlacesResourceMediaEvents - -# add Sorting -class MediaBulkUpload(models.Model): - name = models.CharField(max_length=255, blank=True, null=True) - description = models.TextField(blank=True, null=True) - date = models.DateField(blank=True, null=True, default=None) - created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) - updated_at = models.DateTimeField(auto_now=True, blank=True, null=True) - user = models.ForeignKey(LookupUserInfo, db_column='user', blank=True, null=True, verbose_name='user', default=None, on_delete=models.SET_DEFAULT) +# * Bulk Media Upload +# formerly known as Media Collection +# class MediaBulkUpload(models.Model): +class MediaBulkUpload(Reviewable, Queryable, Record, ModeratedModel): + mediabulkname = models.CharField(max_length=255, blank=True, null=True) + mediabulkdescription = models.TextField(blank=True, null=True) + mediabulkdate = models.DateField(blank=True, null=True, default=None) + # created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) + # modifieddate = models.DateTimeField(auto_now=True, blank=True, null=True) + # user = models.ForeignKey(LookupUserInfo, db_column='user', blank=True, null=True, verbose_name='user', default=None, on_delete=models.SET_DEFAULT) + # todo add Sorting # @property # def count(self): # number of media items uploaded - # Suggested Additions - # Multi upload + # Visual displayed of uploads # Example in blue pages # Gallery of Media From 5d37198aa20b3116993508dae18b41e05411e95a Mon Sep 17 00:00:00 2001 From: David Pollard Date: Wed, 16 Oct 2024 18:11:27 -0700 Subject: [PATCH 16/16] Add additional sorting options to list view --- TEKDB/TEKDB/admin.py | 2 +- TEKDB/TEKDB/models.py | 40 +--------------------------------------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/TEKDB/TEKDB/admin.py b/TEKDB/TEKDB/admin.py index 2dfdbbed..a8d542d9 100644 --- a/TEKDB/TEKDB/admin.py +++ b/TEKDB/TEKDB/admin.py @@ -448,7 +448,7 @@ class CitationsAdmin(RecordAdminProxy, RecordModelAdmin): class MediaBulkUploadAdmin(admin.ModelAdmin): form = MediaBulkUploadForm - list_display = ('mediabulkname',) + list_display = ('mediabulkname','mediabulkdate','modifiedbydate','enteredbydate',) def save_model(self, request, obj, form, change): super().save_model(request, obj, form, change) diff --git a/TEKDB/TEKDB/models.py b/TEKDB/TEKDB/models.py index ba13dc1a..b461b4c7 100644 --- a/TEKDB/TEKDB/models.py +++ b/TEKDB/TEKDB/models.py @@ -1853,54 +1853,16 @@ def __str__(self): # * Bulk Media Upload # formerly known as Media Collection -# class MediaBulkUpload(models.Model): class MediaBulkUpload(Reviewable, Queryable, Record, ModeratedModel): mediabulkname = models.CharField(max_length=255, blank=True, null=True) mediabulkdescription = models.TextField(blank=True, null=True) mediabulkdate = models.DateField(blank=True, null=True, default=None) - # created_at = models.DateTimeField(auto_now_add=True, blank=True, null=True) - # modifieddate = models.DateTimeField(auto_now=True, blank=True, null=True) - # user = models.ForeignKey(LookupUserInfo, db_column='user', blank=True, null=True, verbose_name='user', default=None, on_delete=models.SET_DEFAULT) - # todo add Sorting # @property # def count(self): # number of media items uploaded - - # Visual displayed of uploads - # Example in blue pages - # Gallery of Media - # Ability to edit Media - - # Media Fields + Relationships - # mediatype = models.ForeignKey(LookupMediaType, db_column='mediatype', max_length=255, blank=True, null=True, verbose_name='type', default=None, on_delete=models.SET_DEFAULT) - # medianame = models.CharField(db_column='medianame', max_length=255, blank=True, null=True, verbose_name='name') - # mediadescription = RichTextField(db_column='mediadescription', blank=True, null=True, verbose_name='description', config_name="custom") #CKEditor Rich Text Editor Field - # medialink = models.CharField(db_column='medialink', max_length=255, blank=True, null=True, verbose_name='historic location') - # mediafile = models.FileField(db_column='mediafile', max_length=255, blank=True, null=True, verbose_name='file') - - # PlaceMedia relationship - # other 5 relationships ... - # def relationships(self): - # relationship_list = [] - # places = [x.get_relationship_json(type(self)) for x in self.placesmediaevents_set.all()] - # if len(places) > 0: - # relationship_list.append({'key': 'Places', 'value': places}) - # resources = [x.get_relationship_json(type(self)) for x in self.resourcesmediaevents_set.all()] - # if len(resources) > 0: - # relationship_list.append({'key': 'Resources', 'value': resources}) - # citations = [x.get_relationship_json(type(self)) for x in self.mediacitationevents_set.all()] - # if len(citations) > 0: - # relationship_list.append({'key': 'Bibliographic Sources', 'value': citations}) - # activities = [x.get_relationship_json(type(self)) for x in self.resourceactivitymediaevents_set.all()] - # if len(activities) > 0: - # relationship_list.append({'key': 'Activities', 'value': activities}) - # placeresources = [x.get_relationship_json(type(self)) for x in self.placesresourcemediaevents_set.all()] - # if len(placeresources) > 0: - # relationship_list.append({'key': 'Place-Resources', 'value': placeresources}) - # return relationship_list - + # Ability to edit Media class Media(Reviewable, Queryable, Record, ModeratedModel): mediaid = models.AutoField(db_column='mediaid', primary_key=True)