Skip to content

Commit

Permalink
Merge pull request #141 from rice-crc/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
derekjkeller authored Aug 8, 2023
2 parents 51fd0c3 + c24c64c commit dc94912
Show file tree
Hide file tree
Showing 22 changed files with 998 additions and 331 deletions.
424 changes: 212 additions & 212 deletions api/blog/admin.py

Large diffs are not rendered by default.

35 changes: 30 additions & 5 deletions api/blog/author_options.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@
"label": "Photo",
"flatlabel": "Photo"
},
"institution": {
"type": "table",
"label": "institution",
"flatlabel": "institution"
},
"institution__id": {
"type": "<class 'rest_framework.fields.IntegerField'>",
"label": "ID",
"flatlabel": "institution : ID"
},
"institution__name": {
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Name",
"flatlabel": "institution : Name"
},
"institution__description": {
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Description",
"flatlabel": "institution : Description"
},
"institution__slug": {
"type": "<class 'rest_framework.fields.SlugField'>",
"label": "Slug",
"flatlabel": "institution : Slug"
},
"institution__image": {
"type": "<class 'rest_framework.fields.ImageField'>",
"label": "Image",
"flatlabel": "institution : Image"
},
"name": {
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Name",
Expand All @@ -108,10 +138,5 @@
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Role",
"flatlabel": "Role"
},
"institution": {
"type": "<class 'rest_framework.relations.PrimaryKeyRelatedField'>",
"label": "Institution",
"flatlabel": "Institution"
}
}
27 changes: 27 additions & 0 deletions api/blog/institution_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"id": {
"type": "<class 'rest_framework.fields.IntegerField'>",
"label": "ID",
"flatlabel": "ID"
},
"name": {
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Name",
"flatlabel": "Name"
},
"description": {
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Description",
"flatlabel": "Description"
},
"slug": {
"type": "<class 'rest_framework.fields.SlugField'>",
"label": "Slug",
"flatlabel": "Slug"
},
"image": {
"type": "<class 'rest_framework.fields.ImageField'>",
"label": "Image",
"flatlabel": "Image"
}
}
19 changes: 19 additions & 0 deletions api/blog/migrations/0005_alter_author_institution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.1 on 2023-08-08 19:11

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


class Migration(migrations.Migration):

dependencies = [
('blog', '0004_alter_author_photo'),
]

operations = [
migrations.AlterField(
model_name='author',
name='institution',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='institution_authors', to='blog.institution'),
),
]
3 changes: 1 addition & 2 deletions api/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Institution(models.Model):
description = models.CharField(max_length=600,null=True, blank=True)
slug = models.SlugField(max_length=200, unique=True)
image = models.ImageField(upload_to='images',null=True, blank=True)

def __str__(self):
return self.name

Expand All @@ -42,7 +41,7 @@ class Author(models.Model):
blank=True,
null=True
)
institution = models.ForeignKey(Institution, on_delete= models.CASCADE)
institution = models.ForeignKey(Institution, on_delete= models.CASCADE,related_name='institution_authors')

def __str__(self):
return self.name
Expand Down
35 changes: 30 additions & 5 deletions api/blog/post_options.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@
"label": "Photo",
"flatlabel": "author : Photo"
},
"authors__institution": {
"type": "table",
"label": "institution",
"flatlabel": "author : institution"
},
"authors__institution__id": {
"type": "<class 'rest_framework.fields.IntegerField'>",
"label": "ID",
"flatlabel": "author : institution : ID"
},
"authors__institution__name": {
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Name",
"flatlabel": "author : institution : Name"
},
"authors__institution__description": {
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Description",
"flatlabel": "author : institution : Description"
},
"authors__institution__slug": {
"type": "<class 'rest_framework.fields.SlugField'>",
"label": "Slug",
"flatlabel": "author : institution : Slug"
},
"authors__institution__image": {
"type": "<class 'rest_framework.fields.ImageField'>",
"label": "Image",
"flatlabel": "author : institution : Image"
},
"authors__name": {
"type": "<class 'rest_framework.fields.CharField'>",
"label": "Name",
Expand All @@ -39,11 +69,6 @@
"label": "Role",
"flatlabel": "author : Role"
},
"authors__institution": {
"type": "<class 'rest_framework.relations.PrimaryKeyRelatedField'>",
"label": "Institution",
"flatlabel": "author : Institution"
},
"tags": {
"type": "table",
"label": "tag",
Expand Down
13 changes: 13 additions & 0 deletions api/blog/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
# urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
#

class AuthorInstitutionSerializer(serializers.ModelSerializer):
class Meta:
model=Institution
fields='__all__'


class PostAuthorSerializer(serializers.ModelSerializer):
photo = serializers.SerializerMethodField('get_photo_url')
institution = AuthorInstitutionSerializer(many=False)
def get_photo_url(self, obj):
if obj.photo not in ["",None]:
return obj.photo.url
Expand Down Expand Up @@ -62,10 +68,17 @@ class Meta:
class AuthorSerializer(serializers.ModelSerializer):
posts = AuthorPostSerializer(many=True,read_only=True)
photo = serializers.SerializerMethodField('get_photo_url')
institution = AuthorInstitutionSerializer(many=False)
def get_photo_url(self, obj):
if obj.photo not in ["",None]:
return obj.photo.url
class Meta:
model=Author
fields='__all__'

class InstitutionSerializer(serializers.ModelSerializer):
institution_authors=AuthorSerializer(many=True)
class Meta:
model=Institution
fields='__all__'

1 change: 1 addition & 0 deletions api/blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
path('', views.PostList.as_view()),
path('autocomplete', views.PostTextFieldAutoComplete.as_view()),
path('author', views.AuthorList.as_view()),
path('institution', views.InstitutionList.as_view())
]


36 changes: 32 additions & 4 deletions api/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
except:
print("WARNING. BLANK POST OPTIONS.")
author_options={}

try:
institution_options=options_handler('blog/institution_options.json',hierarchical=False)
except:
print("WARNING. BLANK POST OPTIONS.")
author_options={}


class PostList(generics.GenericAPIView):
# serializer_class=VoyageSerializer
authentication_classes=[TokenAuthentication]
permission_classes=[IsAuthenticated]
def options(self,request):
Expand All @@ -52,7 +58,7 @@ class PostTextFieldAutoComplete(generics.GenericAPIView):
authentication_classes=[TokenAuthentication]
permission_classes=[IsAuthenticated]
def post(self,request):
print("+++++++\nusername:",request.auth.user)
print("POST LIST+++++++\nusername:",request.auth.user)
# try:
st=time.time()
params=dict(request.POST)
Expand Down Expand Up @@ -96,14 +102,13 @@ def post(self,request):
return JsonResponse(res,safe=False)

class AuthorList(generics.GenericAPIView):
# serializer_class=VoyageSerializer
authentication_classes=[TokenAuthentication]
permission_classes=[IsAuthenticated]
def options(self,request):
j=options_handler('blog/author_options.json',request)
return JsonResponse(j,safe=False)
def post(self,request):
print("VOYAGE LIST+++++++\nusername:",request.auth.user)
print("AUTHOR LIST+++++++\nusername:",request.auth.user)
queryset=Author.objects.all()
queryset,selected_fields,next_uri,prev_uri,results_count,error_messages=post_req(queryset,self,request,author_options,retrieve_all=False)
if len(error_messages)==0:
Expand All @@ -118,3 +123,26 @@ def post(self,request):
else:
print("failed\n+++++++")
return JsonResponse({'status':'false','message':' | '.join(error_messages)}, status=400)

class InstitutionList(generics.GenericAPIView):
authentication_classes=[TokenAuthentication]
permission_classes=[IsAuthenticated]
def options(self,request):
j=options_handler('blog/institution_options.json',request)
return JsonResponse(j,safe=False)
def post(self,request):
print("INSTITUTION LIST+++++++\nusername:",request.auth.user)
queryset=Institution.objects.all()
queryset,selected_fields,next_uri,prev_uri,results_count,error_messages=post_req(queryset,self,request,institution_options,retrieve_all=False)
if len(error_messages)==0:
st=time.time()
headers={"next_uri":next_uri,"prev_uri":prev_uri,"total_results_count":results_count}
read_serializer=InstitutionSerializer(queryset,many=True)
serialized=read_serializer.data
resp=JsonResponse(serialized,safe=False,headers=headers)
resp.headers['total_results_count']=headers['total_results_count']
print("Internal Response Time:",time.time()-st,"\n+++++++")
return resp
else:
print("failed\n+++++++")
return JsonResponse({'status':'false','message':' | '.join(error_messages)}, status=400)
5 changes: 5 additions & 0 deletions api/common/management/commands/rebuild_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def handle(self, *args, **options):
'serializer':PostSerializer,
'objectclass':Post
},
{
'output_filename':'blog/institution_options.json',
'serializer':InstitutionSerializer,
'objectclass':Institution
},
{
'output_filename':'blog/author_options.json',
'serializer':AuthorSerializer,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.1 on 2023-08-08 19:11

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('common', '0002_sparsedate'),
]

operations = [
migrations.AlterField(
model_name='sparsedate',
name='day',
field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(31)]),
),
migrations.AlterField(
model_name='sparsedate',
name='month',
field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(12)]),
),
migrations.AlterField(
model_name='sparsedate',
name='year',
field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(2000)]),
),
]
3 changes: 3 additions & 0 deletions api/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ class Meta:
class SparseDate(models.Model):
day = models.IntegerField(
null=True,
blank=True,
validators=[MinValueValidator(1),MaxValueValidator(31)]
)
month = models.IntegerField(
null=True,
blank=True,
validators=[MinValueValidator(1),MaxValueValidator(12)]
)
year = models.IntegerField(
null=True,
blank=True,
validators=[MinValueValidator(0),MaxValueValidator(2000)]
)

Expand Down
2 changes: 1 addition & 1 deletion api/document/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ZoteroSourceAdmin(admin.ModelAdmin):
ZoteroEnslaverConnectionInline,
ZoteroVoyageConnectionInline
]
search_fields=['zotero_title','zotero_date']
search_fields=['zotero_title','zotero_date','short_ref']
readonly_fields=['item_url','zotero_url','legacy_source']
list_display=('zotero_title','zotero_date')

Expand Down
Loading

0 comments on commit dc94912

Please sign in to comment.