Skip to content

Commit

Permalink
Fix download request in the taxon management (#4110)
Browse files Browse the repository at this point in the history
* Fix download request in the taxon management
  • Loading branch information
dimasciput authored Jul 25, 2024
1 parent 722baac commit f77cf86
Show file tree
Hide file tree
Showing 24 changed files with 94 additions and 291 deletions.
20 changes: 20 additions & 0 deletions bims/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,26 @@ class SearchProcessAdmin(admin.ModelAdmin):
'category',
'finished')

def delete_model(self, request, obj):
if obj.locked:
self.message_user(
request,
"This record is locked and cannot be deleted.",
level='warning')
else:
super().delete_model(request, obj)

def delete_queryset(self, request, queryset):
for obj in queryset:
if obj.locked:
self.message_user(
request,
f"Record with ID {obj.id} is locked and cannot be deleted.",
level='warning')
queryset = queryset.filter(locked=False)
if queryset:
super().delete_queryset(request, queryset)


class PageviewAdmin(admin.ModelAdmin):
date_hierarchy = 'view_time'
Expand Down
3 changes: 1 addition & 2 deletions bims/api_views/location_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def get(self, request):

search_process, created = get_or_create_search_process(
SITES_SUMMARY,
query=search_uri,
requester=self.request.user
query=search_uri
)

if not use_cached:
Expand Down
3 changes: 1 addition & 2 deletions bims/api_views/location_site_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ def get(self, request):

search_process, created = get_or_create_search_process(
search_type=SITES_SUMMARY,
query=search_uri,
site=Site.objects.get_current()
query=search_uri
)
results = search_process.get_file_if_exits()
if results:
Expand Down
1 change: 0 additions & 1 deletion bims/api_views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def get(self, request):
search_process, created = get_or_create_search_process(
search_type=SEARCH_RESULTS,
query=search_uri,
requester=request.user
)

if self.is_cached():
Expand Down
3 changes: 2 additions & 1 deletion bims/download/collection_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def download_collection_records(
path_file,
request,
send_email=False,
user_id=None
user_id=None,
process_id=None
):
from django.contrib.auth import get_user_model
from bims.serializers.bio_collection_serializer import (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.11 on 2024-07-25 12:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bims', '0428_remove_biologicalcollectionrecord_accuracy_of_identification_and_more'),
]

operations = [
migrations.AddField(
model_name='searchprocess',
name='locked',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='taxonomy',
name='rank',
field=models.CharField(blank=True, choices=[('DOMAIN', 'Domain'), ('KINGDOM', 'Kingdom'), ('PHYLUM', 'Phylum'), ('SUBPHYLUM', 'SubPhylum'), ('CLASS', 'Class'), ('SUBCLASS', 'Sub Class'), ('ORDER', 'Order'), ('SUBORDER', 'Sub Order'), ('INFRAORDER', 'Infra Order'), ('SUPERFAMILY', 'Super Family'), ('FAMILY', 'Family'), ('SUBFAMILY', 'Sub Family'), ('TRIBE', 'Tribe'), ('SUBTRIBE', 'Sub Tribe'), ('GENUS', 'Genus'), ('SUBGENUS', 'Sub Genus'), ('SPECIES', 'Species'), ('SUBSPECIES', 'Sub Species'), ('VARIETY', 'Variety'), ('FORMA', 'Forma')], max_length=50, verbose_name='Taxonomic Rank'),
),
migrations.AlterField(
model_name='taxonomyupdateproposal',
name='rank',
field=models.CharField(blank=True, choices=[('DOMAIN', 'Domain'), ('KINGDOM', 'Kingdom'), ('PHYLUM', 'Phylum'), ('SUBPHYLUM', 'SubPhylum'), ('CLASS', 'Class'), ('SUBCLASS', 'Sub Class'), ('ORDER', 'Order'), ('SUBORDER', 'Sub Order'), ('INFRAORDER', 'Infra Order'), ('SUPERFAMILY', 'Super Family'), ('FAMILY', 'Family'), ('SUBFAMILY', 'Sub Family'), ('TRIBE', 'Tribe'), ('SUBTRIBE', 'Sub Tribe'), ('GENUS', 'Genus'), ('SUBGENUS', 'Sub Genus'), ('SPECIES', 'Species'), ('SUBSPECIES', 'Sub Species'), ('VARIETY', 'Variety'), ('FORMA', 'Forma')], max_length=50, verbose_name='Taxonomic Rank'),
),
]
27 changes: 27 additions & 0 deletions bims/models/search_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Search process model definition.
"""
import logging
import os
import json
import errno
Expand All @@ -24,6 +25,8 @@
SEARCH_FINISHED = 'finished'
SEARCH_FAILED = 'failed'

logger = logging.getLogger(__name__)


def format_search_result_raw_query(raw_query):
if not raw_query:
Expand All @@ -50,6 +53,20 @@ def format_search_result_raw_query(raw_query):
return query_string


class SearchProcessQuerySet(models.QuerySet):
def delete(self, *args, **kwargs):
locked_objects = self.filter(locked=True)
if locked_objects.exists():
for obj in locked_objects:
logger.warning(f"Attempted to delete locked SearchProcess with ID {obj.id}")
unlocked_objects = self.filter(locked=False)
return super(SearchProcessQuerySet, unlocked_objects).delete(*args, **kwargs)

class SearchProcessManager(models.Manager):
def get_queryset(self):
return SearchProcessQuerySet(self.model, using=self._db)


class SearchProcess(models.Model):
"""Search process model
"""
Expand All @@ -59,6 +76,7 @@ class SearchProcess(models.Model):
(SITES_SUMMARY, 'Site Summary'),
(TAXON_SUMMARY, 'Taxon Summary'),
)
objects = SearchProcessManager()

file_path = models.CharField(
blank=True,
Expand All @@ -84,6 +102,9 @@ class SearchProcess(models.Model):
null=True,
blank=True
)
locked = models.BooleanField(
default=False
)
site = models.ForeignKey(
Site,
on_delete=models.CASCADE,
Expand All @@ -100,6 +121,12 @@ class SearchProcess(models.Model):
null=True,
)

def delete(self, *args, **kwargs):
if self.locked:
logger.warning(f"Attempted to delete locked SearchProcess with ID {self.id}")
else:
super(SearchProcess, self).delete(*args, **kwargs)

def save(self, *args, **kwargs):
super(SearchProcess, self).save(*args, **kwargs)

Expand Down
8 changes: 6 additions & 2 deletions bims/static/js/non_requirejs/download_request_popup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
function isInt(value) {
return !isNaN(value) && (function(x) { return (x | 0) === x; })(parseFloat(value))
}

function showDownloadPopup(resource_type, resource_name, callback, auto_approved = true, on_hidden = null) {
const $downloadPopup = $('#download-popup');
if(resource_type === 'CSV'){
Expand All @@ -19,8 +23,8 @@ function showDownloadPopup(resource_type, resource_name, callback, auto_approved
const url = '/api/download-request/';

let urlParams = new URLSearchParams(window.location.href.replace('/taxon', '/&taxon'))
let taxon_id = urlParams.get('taxon');
let site_id = urlParams.get('siteId');
let taxon_id = isInt(urlParams.get('taxon')) ? urlParams.get('taxon') : null;
let site_id = isInt(urlParams.get('siteId')) ? urlParams.get('siteId') : null;
let survey_id = urlParams.get('survey');

$submitDownloadPopup.on('click', function () {
Expand Down
13 changes: 9 additions & 4 deletions bims/utils/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

logging.basicConfig(level=logging.INFO)


def before_send(event, hint):
logging.info(f"Processing event: {event}")
logging.info(f'hint: {hint}')
logging.info(f'Hint: {hint}')

if 'exc_info' in hint:
exc_type, exc_value, tb = hint['exc_info']
logging.info(f"exc_type: {str(exc_value)}")
if 'easyaudit.signals.model_signals.pre_save' in str(exc_value):
logging.info("Ignoring easyaudit.signals.model_signals.pre_save error")
logging.info(f"Exception type: {exc_type}")
logging.info(f"Exception value: {exc_value}")

if 'easyaudit.signals.model_signals' in str(exc_value):
logging.info("Ignoring easyaudit.signals.model_signals error")
return None

return event
10 changes: 0 additions & 10 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
re_path(r'^bibliography/',
include(('td_biblio.urls', 'bibliography'),
namespace = 'td_biblio')),
re_path(r'^', include('example.urls')),

# prometheus monitoring
# re_path(r'', include('django_prometheus.urls')),
Expand All @@ -49,15 +48,6 @@
name='home'),
]

# for geonode_pattern in geonode_urlpatterns:
# try:
# if 'admin' in geonode_pattern.app_dict:
# geonode_urlpatterns.remove(geonode_pattern)
# except AttributeError:
# continue
#
# urlpatterns += geonode_urlpatterns

urlpatterns += [
re_path('^admin/', admin.site.urls),
]
Expand Down
Empty file removed example/__init__.py
Empty file.
10 changes: 0 additions & 10 deletions example/admin.py

This file was deleted.

24 changes: 0 additions & 24 deletions example/migrations/0001_initial.py

This file was deleted.

17 changes: 0 additions & 17 deletions example/migrations/0002_auto_20180417_1146.py

This file was deleted.

31 changes: 0 additions & 31 deletions example/migrations/0003_auto_20180419_0954.py

This file was deleted.

Empty file removed example/migrations/__init__.py
Empty file.
2 changes: 0 additions & 2 deletions example/models/__init__.py

This file was deleted.

30 changes: 0 additions & 30 deletions example/models/example_collection_record.py

This file was deleted.

23 changes: 0 additions & 23 deletions example/models/rock_collection_record.py

This file was deleted.

Loading

0 comments on commit f77cf86

Please sign in to comment.