Commit e5c4a3be authored by Nicolas Noé's avatar Nicolas Noé
Browse files

Implement specimen pictures. Fixes #4.

parent 81e0a0d0
......@@ -2,7 +2,9 @@ Django==1.11.2
django-export-action==0.1.1
et-xmlfile==1.0.1
jdcal==1.3
olefile==0.44
openpyxl==2.4.8
Pillow==4.1.1
psycopg2==2.7.1
pytz==2017.2
six==1.10.0
from django.contrib import admin
from django import forms
from .models import Specimen, SpecimenLocation, Person, Fixation, Station, Expedition
from .models import Specimen, SpecimenLocation, Person, Fixation, Station, Expedition, SpecimenPicture
from .widgets import LatLongWidget
......@@ -16,6 +16,9 @@ class MyAdminForm(forms.ModelForm):
}
class SpecimenPictureInline(admin.TabularInline):
model = SpecimenPicture
@admin.register(Specimen)
class SpecimenAdmin(admin.ModelAdmin):
form = MyAdminForm
......@@ -25,6 +28,9 @@ class SpecimenAdmin(admin.ModelAdmin):
search_fields = ['scientific_name', 'specimen_id']
# TODO: document searchable fields in template? (https://stackoverflow.com/questions/11411622/add-help-text-for-search-field-in-admin-py)
inlines = [
SpecimenPictureInline,
]
@admin.register(SpecimenLocation)
class SpecimenLocationAdmin(admin.ModelAdmin):
......@@ -48,5 +54,8 @@ class StationAdmin(admin.ModelAdmin):
class ExpeditionAdmin(admin.ModelAdmin):
pass
@admin.register(SpecimenPicture)
class SpecimenPictureAdmin(admin.ModelAdmin):
pass
admin.site.site_header = 'Astapor administration'
\ No newline at end of file
......@@ -24,7 +24,7 @@ def get_or_create_station_and_expedition(station_name, expedition_name):
"""
if station_name == '':
station_name = UNKNOWN_STATION_NAME
try: # A station already exists for the correct expedition?
return Station.objects.get(name=station_name, expedition__name=expedition_name)
......@@ -61,13 +61,16 @@ class Command(BaseCommand):
self.stdout.write('Processing row #{i}...'.format(i=i), ending='')
specimen = Specimen()
specimen.specimen_id = row['Specimen_id'].strip()
self.stdout.write('Specimen ID is {id}...'.format(id=specimen.specimen_id), ending='')
specimen.station = get_or_create_station_and_expedition(row['Station'].strip(), row['Expedition'].strip())
# Identificators
# Identifiers
identified_by = row['Identified_by'].strip()
id_first_name, id_last_name = identified_by.split()
identificator, _ = Person.objects.get_or_create(first_name=id_first_name, last_name=id_last_name)
specimen.identified_by = identificator
identifier, _ = Person.objects.get_or_create(first_name=id_first_name, last_name=id_last_name)
specimen.identified_by = identifier
# Specimen locations
specimen_location, _ = SpecimenLocation.objects.get_or_create(name=row['Specimen_location'])
......@@ -84,7 +87,6 @@ class Command(BaseCommand):
if fixation:
specimen.fixation, _ = Fixation.objects.get_or_create(name=fixation)
specimen.comment = row['Comment']
depth = row['Depth'].strip()
......@@ -97,7 +99,6 @@ class Command(BaseCommand):
specimen.depth = NumericRange(float(d_min.replace(',','.')), float(d_max.replace(',','.')), bounds='[]')
specimen.scientific_name = row['Scientific_name']
specimen.specimen_id = row['Specimen_id']
specimen.save()
self.stdout.write(self.style.SUCCESS('OK'))
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-06-20 08:54
# Generated by Django 1.11.2 on 2017-06-21 07:43
from __future__ import unicode_literals
import django.contrib.gis.db.models.fields
......@@ -61,6 +61,15 @@ class Migration(migrations.Migration):
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='SpecimenPicture',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('image', models.ImageField(upload_to='specimen_pictures')),
('high_interest', models.BooleanField(verbose_name='High resolution/species representative')),
('specimen', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='specimens.Specimen')),
],
),
migrations.CreateModel(
name='Station',
fields=[
......
......@@ -69,4 +69,14 @@ class Specimen(models.Model):
return str
depth_str.short_description = 'Depth'
def __str__(self):
return "Specimen #{specimen_id} ({scientific_name})".format(specimen_id=self.specimen_id,
scientific_name=self.scientific_name)
class SpecimenPicture(models.Model):
image = models.ImageField(upload_to='specimen_pictures')
high_interest = models.BooleanField("High resolution/species representative")
specimen = models.ForeignKey(Specimen)
......@@ -11,4 +11,7 @@ DATABASES = {
'USER': 'mydatabaseuser',
'NAME': 'mydatabase',
},
}
\ No newline at end of file
}
MEDIA_ROOT = ''
MEDIA_URL = ''
\ No newline at end of file
......@@ -13,11 +13,13 @@ Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.conf.urls import url, include
from django.contrib import admin
from django.conf.urls import include
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^export_action/', include("export_action.urls", namespace="export_action")),
]
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment