Commit c89d1760 authored by Robin Tissot's avatar Robin Tissot
Browse files

Merge branch 'develop'

parents e2146f06 ddcdb551
......@@ -102,11 +102,15 @@ class DocumentSerializer(serializers.ModelSerializer):
transcriptions = TranscriptionSerializer(many=True, read_only=True)
valid_block_types = BlockTypeSerializer(many=True, read_only=True)
valid_line_types = LineTypeSerializer(many=True, read_only=True)
parts_count = serializers.SerializerMethodField()
class Meta:
model = Document
fields = ('pk', 'name', 'transcriptions',
'valid_block_types', 'valid_line_types')
'valid_block_types', 'valid_line_types', 'parts_count')
def get_parts_count(self, document):
return document.parts.count()
class PartSerializer(serializers.ModelSerializer):
......@@ -127,6 +131,7 @@ class PartSerializer(serializers.ModelSerializer):
'image',
'bw_image',
'workflow',
'order',
'recoverable',
'transcription_progress'
)
......
......@@ -4,7 +4,9 @@ import logging
from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.db.models import Prefetch
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.urls import reverse
from rest_framework.decorators import action
from rest_framework.response import Response
......@@ -193,6 +195,22 @@ class PartViewSet(DocumentPermissionMixin, ModelViewSet):
else: # list & create
return PartSerializer
@action(detail=False, methods=['get'])
def byorder(self, request, document_pk=None):
try:
order = int(request.GET.get('order'))
except ValueError:
return Response({'error': 'invalid order.'})
if not order:
return Response({'error': 'pass order as an url parameter.'})
try:
part = self.get_queryset().get(order=order)
except DocumentPart.DoesNotExist:
return Response({'error': 'Out of bounds.'})
return HttpResponseRedirect(reverse('api:part-detail',
kwargs={'document_pk': self.kwargs.get('document_pk'),
'pk': part.pk}))
@action(detail=True, methods=['post'])
def move(self, request, document_pk=None, pk=None):
part = DocumentPart.objects.get(document=document_pk, pk=pk)
......
# Generated by Django 2.2.19 on 2021-03-24 10:16
from django.db import migrations, models
import django.db.models.deletion
def forward(apps, se):
# delete any unbound model
OcrModel = apps.get_model('core', 'OcrModel')
OcrModel.objects.filter(document__isnull=True).delete()
def backward(apps, se):
pass
class Migration(migrations.Migration):
dependencies = [
('core', '0042_auto_20201009_1015'),
]
operations = [
migrations.RunPython(forward, backward),
migrations.AlterField(
model_name='ocrmodel',
name='document',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='ocr_models', to='core.Document'),
),
]
......@@ -244,6 +244,13 @@ class Document(models.Model):
else:
return 'ltr'
@cached_property
def last_edited_part(self):
try:
return self.parts.order_by('-updated_at')[0]
except IndexError:
return None
@property
def training_model(self):
return self.ocr_models.filter(training=True).first()
......
......@@ -5,7 +5,6 @@ from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.contrib import messages
from django.utils.translation import ngettext
from users.models import User, ResearchField, Invitation, ContactUs, GroupOwner
......@@ -15,8 +14,11 @@ class MyUserChangeForm(UserChangeForm):
class MyUserCreationForm(UserCreationForm):
email = forms.EmailField()
class Meta(UserCreationForm.Meta):
model = User
fields = UserCreationForm.Meta.fields + ('email',)
def clean_username(self):
username = self.cleaned_data['username']
......@@ -24,7 +26,7 @@ class MyUserCreationForm(UserCreationForm):
User.objects.get(username=username)
except User.DoesNotExist:
return username
raise forms.ValidationError(self.error_messages['duplicate_username'])
raise forms.ValidationError('Duplicate username.')
class MyUserAdmin(UserAdmin):
......@@ -32,9 +34,13 @@ class MyUserAdmin(UserAdmin):
add_form = MyUserCreationForm
list_display = UserAdmin.list_display + ('last_login',)
fieldsets = UserAdmin.fieldsets + (
(None, {'fields': ('fields','onboarding')}), # second fields refers to research fields
(None, {'fields': ('fields', 'onboarding')}), # second fields refers to research fields
)
add_fieldsets = (
(None, {
'fields': ('username', 'email', 'password1', 'password2')}
),
)
class InvitationAdmin(admin.ModelAdmin):
date_hierarchy = 'created_at'
......
# Generated by Django 2.2.19 on 2021-03-24 10:07
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0013_auto_20210106_1305'),
]
operations = [
migrations.AlterModelOptions(
name='contactus',
options={'verbose_name': 'Contact message', 'verbose_name_plural': 'Contact messages'},
),
]
......@@ -5,3 +5,6 @@ def enable_cookie_consent(request):
return {'ENABLE_COOKIE_CONSENT': getattr(settings,
'ENABLE_COOKIE_CONSENT',
True)}
def custom_homepage(request):
return {'CUSTOM_HOME': getattr(settings, 'CUSTOM_HOME', False)}
......@@ -39,3 +39,8 @@ DEBUG_TOOLBAR_PANELS = [
]
# USE_CELERY = False
# CELERY_TASK_ALWAYS_EAGER = True
# LOGGING['loggers']['kraken']['level'] = 'DEBUG'
# CUSTOM_HOME = True
......@@ -41,6 +41,8 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', False)
CUSTOM_HOME = os.getenv('CUSTOM_HOME', False)
ALLOWED_HOSTS = ['*']
ASGI_APPLICATION = "escriptorium.routing.application"
......@@ -87,7 +89,8 @@ ROOT_URLCONF = 'escriptorium.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(PROJECT_ROOT, 'templates')],
'DIRS': [os.path.join(PROJECT_ROOT, 'templates'),
os.path.join(BASE_DIR, 'homepage')], # custom homepage dir (volume in docker)
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -95,7 +98,8 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'escriptorium.context_processors.enable_cookie_consent'
'escriptorium.context_processors.enable_cookie_consent',
'escriptorium.context_processors.custom_homepage'
],
},
},
......@@ -219,6 +223,7 @@ STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, 'static'),
os.path.join(BASE_DIR, 'homepage'), # custom homepage directory
FRONTEND_DIR
]
......
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