Skip to content

Commit

Permalink
Feature/tnris org docs sgm notes (#68)
Browse files Browse the repository at this point in the history
* new sgm_note field added to TnrisDocument model - boolean

issue #62; serializers, viewsets, urls, models, forms edited; now available in api with endpoint - api/v1/tnris_org/sgm_note

* comments and additional helper text added

issue #62
  • Loading branch information
John Haney authored Jan 31, 2020
1 parent e1f7792 commit 81de6c5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/data_hub/tnris_org/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class Meta:
fields = ('__all__')

document_url = forms.FileField(required=False, widget=DocumentWidget, help_text="Choose a document file and 'Save' this form to upload & save it to the database. Attempting to overwrite with a new file will only create a new record. The best method to overwrite would be to delete the existing file and re-upload a new file with the same name.")
sgm_note = forms.BooleanField(required=False, label="GIS Solutions Group Notes", help_text="Check this box to identify this as a Solutions Group Notes document. This is required to view the document on tnris.org. Be sure to name the file correctly - 'YYYY-MM-DD-GIS-SG-Meeting-Notes.pdf'. The file name is important for the order these documents are presented on tnris.org.")

# boto3 s3 object
client = boto3.client('s3')
Expand Down
18 changes: 18 additions & 0 deletions src/data_hub/tnris_org/migrations/0024_tnrisdocument_sgm_note.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.13 on 2020-01-31 17:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tnris_org', '0023_tnrisgiocalendarevent_community_meeting_agenda_url'),
]

operations = [
migrations.AddField(
model_name='tnrisdocument',
name='sgm_note',
field=models.BooleanField(default=False, verbose_name='Solutions Group Note'),
),
]
5 changes: 5 additions & 0 deletions src/data_hub/tnris_org/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class Meta:
'Document URL',
max_length=255,
)
sgm_note = models.BooleanField(
'Solutions Group Note',
default=False,
null=False
)
created = models.DateTimeField(
'Created',
auto_now_add=True
Expand Down
14 changes: 13 additions & 1 deletion src/data_hub/tnris_org/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
TnrisForumTraining,
TnrisInstructorType,
CompleteForumTrainingView,
TnrisGioCalendarEvent
TnrisGioCalendarEvent,
TnrisDocument
)
from datetime import datetime

Expand Down Expand Up @@ -148,3 +149,14 @@ def get_pretty_time(self, obj):
pt = "%s-%s" % (st.strftime('%I:%M%p').lstrip("0"),
et.strftime('%I:%M%p').lstrip("0"))
return pt


class TnrisSGMDocumentSerializer(serializers.ModelSerializer):
class Meta:
model = TnrisDocument
fields = ('document_id',
'document_name',
'document_url',
'sgm_note',
'created',
'last_modified',)
2 changes: 2 additions & 0 deletions src/data_hub/tnris_org/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
TnrisInstructorTypeViewSet,
CompleteForumTrainingViewSet,
TnrisGioCalendarEventViewSet,
TnrisSGMDocumentViewSet,
)

router = routers.DefaultRouter(trailing_slash=False)
Expand All @@ -32,6 +33,7 @@
router.register(r'complete_forum_training/?', CompleteForumTrainingViewSet, base_name="CompleteForumTrainingView")
router.register(r'instructor_type/?', TnrisInstructorTypeViewSet, base_name="TnrisInstructorType")
router.register(r'gio_calendar/?', TnrisGioCalendarEventViewSet, base_name="TnrisGioCalendarEvent")
router.register(r'sgm_note/?', TnrisSGMDocumentViewSet, base_name="TnrisDocument")

schema_view = get_swagger_view(title='TNRIS.org API')

Expand Down
23 changes: 20 additions & 3 deletions src/data_hub/tnris_org/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
TnrisForumTraining,
TnrisInstructorType,
CompleteForumTrainingView,
TnrisGioCalendarEvent
TnrisGioCalendarEvent,
TnrisDocument
)
from .serializers import (
TnrisTrainingSerializer,
TnrisForumTrainingSerializer,
TnrisInstructorTypeSerializer,
CompleteForumTrainingViewSerializer,
TnrisGioCalendarEventSerializer
TnrisGioCalendarEventSerializer,
TnrisSGMDocumentSerializer
)


Expand Down Expand Up @@ -130,4 +132,19 @@ def get_queryset(self):
args[field] = value
# get records using query. order by chronological start
queryset = TnrisGioCalendarEvent.objects.filter(**args).order_by('start_date', 'start_time')
return queryset
return queryset


class TnrisSGMDocumentViewSet(viewsets.ReadOnlyModelViewSet):
"""
Retrieve all Solutions Group Meeting Documents for tnris.org frontend
"""
serializer_class = TnrisSGMDocumentSerializer
http_method_names = ['get']

def get_queryset(self):
# get records using query
args = {'sgm_note': True}
# order by document file name
queryset = TnrisDocument.objects.filter(**args).order_by('document_name')
return queryset

0 comments on commit 81de6c5

Please sign in to comment.