Skip to content

Commit

Permalink
Merge pull request #747 from upconsulting/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jdamerow authored May 9, 2022
2 parents 72f5ad4 + 2295a1d commit 98dada3
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6-buster
FROM python:3.7-buster

ENV DJANGO_SETTINGS_MODULE=isiscb.production_settings

Expand Down
13 changes: 10 additions & 3 deletions isiscb/curation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def __init__(self, *args, **kwargs):
if instance and not self.is_bound:
self.fields['value'].initial = instance.pk
self.fields['citation_name'].initial = instance.value.title_for_display

def clean_value(self):
value = self.cleaned_data['value']

Expand Down Expand Up @@ -835,10 +835,16 @@ class SelectAuthorityCollectionForm(forms.Form):

class ExportCitationsForm(forms.Form):
export_name = forms.CharField(help_text='This tag will be added to the export filename')
export_format = forms.ChoiceField(choices=[('CSV', 'Comma-separated values (CSV)'), ('EBSCO_CSV', 'Comma-separated values (CSV) in EBSCO format (disregard column selection below)'), ('ITEM_COUNT', 'Export for Item Counts'), ('SWP_ANALYSIS', "Export for SPW Analysis")])
export_format = forms.ChoiceField(choices=[
('CSV', 'Comma-separated values (CSV)'),
('EBSCO_CSV', 'Comma-separated values (CSV) in EBSCO format (disregard column selection below)'),
('ITEM_COUNT', 'Export for Item Counts'),
('SWP_ANALYSIS', "Export for SPW Analysis"),
('SWP_PRESET', "Export for regular data backup (disregard column selection below).")])
export_linked_records = forms.BooleanField(label="Export linked records (make sure that the 'Link to Record' Field is selected in the field list)", required=False)
export_metadata = forms.BooleanField(label="Export metadata", required=False)
use_pipe_delimiter = forms.BooleanField(label='Use "||" to separate related authority and citation fields', required=False)
use_preset = forms.BooleanField(label='Export predefined fields only (disregard column selection below).', required=False)
fields = forms.MultipleChoiceField(choices=[(c.slug, c.label) for c in export.CITATION_COLUMNS], required=False)
filters = forms.CharField(widget=forms.widgets.HiddenInput())
# compress_output = forms.BooleanField(required=False, initial=True,
Expand All @@ -848,8 +854,9 @@ class ExportCitationsForm(forms.Form):
def clean_fields(self):
field_data = self.cleaned_data['fields']
export_type = self.cleaned_data['export_format']
use_preset = self.cleaned_data['use_preset']
if export_type == 'CSV':
if not field_data:
if not field_data and not use_preset:
raise forms.ValidationError("Please select fields to export.")

return field_data
Expand Down
9 changes: 9 additions & 0 deletions isiscb/curation/templates/curation/citations_export.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
$(".form-group input[type=checkbox]").prop( "disabled", true );
}
})
$("#id_use_preset").change(function() {
if ($("#id_use_preset").prop("checked") == true) {
$("#id_fields").prop('required',false);
$("#id_fields").prop('disabled', true);
} else {
$("#id_fields").prop('required',true);
$("#id_fields").prop('disabled', false);
}
})
})
</script>
<form class="form" action="?confirmed=true" method="POST">
Expand Down
9 changes: 7 additions & 2 deletions isiscb/curation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,7 @@ def export_citations(request):
export_linked_records = form.cleaned_data.get('export_linked_records')
export_metadata = form.cleaned_data.get('export_metadata', False)
use_pipe_delimiter = form.cleaned_data.get('use_pipe_delimiter')
use_preset = form.cleaned_data.get('use_preset', False)

# TODO: generalize this, so that we are not tied directly to S3.
_datestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
Expand All @@ -2474,7 +2475,8 @@ def export_citations(request):
# configuration for export
config = {
'authority_delimiter': " || " if use_pipe_delimiter else " ",
'export_metadata': export_metadata
'export_metadata': export_metadata,
'use_preset': use_preset
}

export_tasks = {
Expand All @@ -2486,12 +2488,15 @@ def export_citations(request):
# We create the AsyncTask object first, so that we can keep it
# updated while the task is running.
task = AsyncTask.objects.create()
export_task = export_tasks.get(form.cleaned_data.get('export_format', 'CSV'), None)
format = form.cleaned_data.get('export_format', 'CSV')
export_task = export_tasks.get(format, None)
if export_task:
result = export_task.delay(request.user.id, s3_path,
fields, filter_params_raw,
task.id, "Citation", export_linked_records, config)
else:
if format == 'SWP_PRESET':
config['use_preset'] = True
result = data_tasks.export_to_csv.delay(request.user.id, s3_path,
fields, filter_params_raw,
task.id, "Citation", export_linked_records, config)
Expand Down
2 changes: 2 additions & 0 deletions isiscb/isiscb/local_postgresql_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,5 @@
AWS_SECRET_ACCESS_KEY,
AWS_EXPORT_BUCKET_NAME)
UPLOAD_IMPORT_PATH = os.environ.get('UPLOAD_IMPORT_PATH', S3_IMPORT_PATH)

DATABASE_DEFAULT_LANGUAGE = os.environ.get('DATABASE_DEFAULT_LANGUAGE', 'English')
2 changes: 2 additions & 0 deletions isiscb/isiscb/production_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,5 @@
DATASET_ISISCB_NAME_DISPLAY = os.environ.get('DATASET_ISISCB_NAME_DISPLAY', 'Isis Bibliography of the History of Science')
DATASET_SHOT_NAME_PREFIX = os.environ.get('DATASET_SHOT_NAME_PREFIX', 'Technology & Culture Bibliography')
DATASET_SHOT_NAME_DISPLAY = os.environ.get('DATASET_SHOT_NAME_DISPLAY', 'Technology & Culture Bibliography')

DATABASE_DEFAULT_LANGUAGE = os.environ.get('DATABASE_DEFAULT_LANGUAGE', 'English')
2 changes: 2 additions & 0 deletions isiscb/isiscb/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,5 @@
AWS_SECRET_ACCESS_KEY,
AWS_EXPORT_BUCKET_NAME)
UPLOAD_IMPORT_PATH = os.environ.get('UPLOAD_IMPORT_PATH', S3_IMPORT_PATH)

DATABASE_DEFAULT_LANGUAGE = os.environ.get('DATABASE_DEFAULT_LANGUAGE', 'English')
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 3.1.13 on 2022-05-03 02:10

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('isisdata', '0095_auto_20210826_0119'),
]

operations = [
migrations.CreateModel(
name='FeaturedAuthority',
fields=[
('authority', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='isisdata.authority')),
('start_date', models.DateTimeField()),
('end_date', models.DateTimeField()),
],
),
migrations.CreateModel(
name='GoogleBooksData',
fields=[
('citation', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='isisdata.citation')),
('image_url', models.TextField()),
('image_size', models.CharField(blank=True, max_length=255)),
('last_modified', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='WikipediaData',
fields=[
('authority', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='isisdata.authority')),
('img_url', models.URLField(max_length=255)),
('intro', models.TextField(blank=True, null=True)),
('credit', models.URLField(max_length=255)),
('last_modified', models.DateTimeField(auto_now=True)),
],
),
]
48 changes: 48 additions & 0 deletions isiscb/isisdata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,21 @@ class CitationSubtype(models.Model):
def __str__(self):
return self.name if self.name else 'Subtype'

class GoogleBooksData(models.Model):
"""
Context data for a citation, including a featured image, sourced from Google Books.
"""

citation = models.OneToOneField(
Citation,
on_delete=models.CASCADE,
primary_key=True,
)

image_url = models.TextField()
image_size = models.CharField(max_length=255, blank=True)

last_modified = models.DateTimeField(auto_now=True)

class Authority(ReferencedEntity, CuratedMixin):
ID_PREFIX = 'CBA'
Expand Down Expand Up @@ -1492,7 +1507,40 @@ class Person(Authority):
personal_name_suffix = models.CharField(max_length=255, blank=True)
personal_name_preferred = models.CharField(max_length=255, blank=True)

class WikipediaData(models.Model):
"""
Context data for an authority, including a featured image and synopsis, sourced from Wikipedia.
"""

authority = models.OneToOneField(
Authority,
on_delete=models.CASCADE,
primary_key=True,
)

img_url = models.URLField(max_length=255)

intro = models.TextField(blank=True, null=True)

credit = models.URLField(max_length=255)

last_modified = models.DateTimeField(auto_now=True)

class FeaturedAuthority(models.Model):
"""
Contains the authorities that will be featured on the home page, the date they will start being featured and the date they will stop being featured.
"""

authority = models.OneToOneField(
Authority,
on_delete=models.CASCADE,
primary_key=True,
)

start_date = models.DateTimeField()
end_date = models.DateTimeField()

class ACRelation(ReferencedEntity, CuratedMixin):
"""
A relation between a :class:`.Authority` and a :class:`.Citaton`\.
Expand Down
Loading

0 comments on commit 98dada3

Please sign in to comment.