Skip to content

Commit

Permalink
Merge branch 'main' into i182_relationship_form
Browse files Browse the repository at this point in the history
  • Loading branch information
pollardld committed Nov 26, 2024
2 parents 0255c50 + ebd1539 commit 6ecea96
Show file tree
Hide file tree
Showing 18 changed files with 410 additions and 153 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/create-asana-attachment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
pull_request:
types: [opened, reopened]

jobs:
create-asana-attachment-job:
runs-on: ubuntu-latest
name: Create pull request attachments on Asana tasks
steps:
- name: Create pull request attachments
uses: Asana/create-app-attachment-github-action@latest
id: postAttachment
with:
asana-secret: ${{ secrets.ASANA_SECRET }}
- name: Log output status
run: echo "Status is ${{ steps.postAttachment.outputs.status }}"
50 changes: 32 additions & 18 deletions TEKDB/TEKDB/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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
Expand All @@ -21,11 +22,6 @@
from TEKDB.settings import BASE_DIR
from TEKDB.widgets import OpenLayers6Widget

################
#### SEARCH ####
################
class SearchSettingsAdmin(admin.ModelAdmin):
list_display = ('min_search_rank', 'min_search_similarity')

#############
### FORMS ###
Expand Down Expand Up @@ -444,26 +440,48 @@ 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

list_display = ('mediabulkname','mediabulkdate','modifiedbydate','enteredbydate',)

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,
mediadescription=obj.description,
medianame=obj.mediabulkname,
mediadescription=obj.mediabulkdescription,
mediafile=file,
)
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 = []
for media in obj.mediabulkupload.all():
Expand Down Expand Up @@ -522,17 +540,16 @@ 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': ('mediabulkname', 'mediabulkdescription', 'files', 'mediabulkdate', 'places', 'resources', 'citations', 'activities', 'placeresources', 'thumbnail_gallery')
}),
)

admin.site.register(MediaBulkUpload, MediaBulkUploadAdmin)


class MediaAdmin(RecordAdminProxy, RecordModelAdmin):
readonly_fields = ('medialink',
'enteredbyname', 'enteredbytribe','enteredbytitle','enteredbydate',
Expand Down Expand Up @@ -989,9 +1006,6 @@ class UsersAdmin(UserAdmin):
admin.site.register(Users, UsersAdmin)
admin.site.register(UserAccess)

### SEARCH
admin.site.register(SearchSettings)

###Cruft
admin.site.register(LookupAuthorType)
admin.site.register(LookupUserInfo)
Expand Down
55 changes: 39 additions & 16 deletions TEKDB/TEKDB/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
def search_settings(request):
from django.conf import settings
from .models import SearchSettings

def search_settings(request=None):
try:
# Get the search settings from the database
search_settings = SearchSettings.objects.first()
if search_settings:
return {
'MIN_SEARCH_RANK': search_settings.min_search_rank,
'MIN_SEARCH_SIMILARITY': search_settings.min_search_similarity,
}
from django.conf import settings
except Exception as e:
print(e)
pass
try:
from TEKDB import settings
except Exception as e:
print('Could not import settings from TEKDB')
print(e)
settings = False

try:
from configuration.models import Configuration
configs = Configuration.objects.all()[0]
except Exception as e:
configs = False

return {
'MIN_SEARCH_RANK': settings.MIN_SEARCH_RANK, # Default value
'MIN_SEARCH_SIMILARITY': settings.MIN_SEARCH_SIMILARITY, # Default value
search_config = {
'MIN_SEARCH_RANK': 0.01, # Default value
'MIN_SEARCH_SIMILARITY': 0.1, # Default
}

if settings:
try:
search_config = {
'MIN_SEARCH_RANK': settings.MIN_SEARCH_RANK,
'MIN_SEARCH_SIMILARITY': settings.MIN_SEARCH_SIMILARITY,
}
except Exception as e:
print('No MIN_SEARCH_RANK or MIN_SEARCH_SIMILARITY in settings')
pass

if configs:
try:
search_config = {
'MIN_SEARCH_RANK': configs.min_search_rank if configs.min_search_rank else search_config['MIN_SEARCH_RANK'],
'MIN_SEARCH_SIMILARITY': configs.min_search_similarity if configs.min_search_similarity else search_config['MIN_SEARCH_SIMILARITY'],
}
except Exception as e:
print('No min_search_rank or min_search_similarity in Configuration')
pass

return search_config


def add_map_default_context(request):
from django.conf import settings
Expand Down
15 changes: 8 additions & 7 deletions TEKDB/TEKDB/forms.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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):
allow_multiple_selected = True

class MultipleFileField(forms.FileField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", MultipleFileInput())
kwargs.setdefault("widget", ThumbnailFileInput)
super().__init__(*args, **kwargs)

def clean(self, data, initial=None):
Expand All @@ -18,13 +18,14 @@ 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)
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']
fields = ['mediabulkname', 'mediabulkdescription', 'mediabulkdate', 'files', 'mediabulkdate', 'places', 'resources', 'citations', 'activities', 'placeresources']
71 changes: 71 additions & 0 deletions TEKDB/TEKDB/migrations/0016_auto_20241016_1549.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
32 changes: 32 additions & 0 deletions TEKDB/TEKDB/migrations/0017_auto_20241016_1552.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
28 changes: 28 additions & 0 deletions TEKDB/TEKDB/migrations/0018_auto_20241022_1653.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.25 on 2024-10-22 23:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('TEKDB', '0017_auto_20241016_1552'),
]

operations = [
migrations.AlterField(
model_name='mediabulkupload',
name='mediabulkdate',
field=models.DateField(blank=True, default=None, null=True, verbose_name='date'),
),
migrations.AlterField(
model_name='mediabulkupload',
name='mediabulkdescription',
field=models.TextField(blank=True, null=True, verbose_name='description'),
),
migrations.AlterField(
model_name='mediabulkupload',
name='mediabulkname',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='name'),
),
]
16 changes: 16 additions & 0 deletions TEKDB/TEKDB/migrations/0018_delete_searchsettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.2.25 on 2024-10-25 20:19

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('TEKDB', '0017_auto_20241016_1552'),
]

operations = [
migrations.DeleteModel(
name='SearchSettings',
),
]
Loading

0 comments on commit 6ecea96

Please sign in to comment.