Skip to content

Commit

Permalink
Merge pull request #7 from TNRIS/feature/csv-training
Browse files Browse the repository at this point in the history
Feature/csv training
  • Loading branch information
JasonKleinert authored Jul 19, 2019
2 parents 447b75b + f06105a commit 809fb78
Show file tree
Hide file tree
Showing 15 changed files with 514 additions and 10 deletions.
14 changes: 14 additions & 0 deletions database_management/tnris_org_local_time.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- this sql needs to be run to create the rest endpoint properly formatted date/time for training courses

select title, start_date_time, end_date_time,
to_char(start_date_time at time zone 'America/Chicago', 'DD-MON-YYYY HH12:MI'),
to_char(end_date_time at time zone 'America/Chicago', 'DD-MON-YYYY HH12:MI' )
from tnris_training

-- returns two new columns. one column example: 'Monday October 21 08:00'. second column example ' - 12:00 PM'.
-- mash these two columsn together to get proper formatted date/time for tnris.org front end
-- final example format: 'Monday October 21 08:00 - 12:00 PM'
select title, start_date_time, end_date_time,
to_char(start_date_time at time zone 'America/Chicago', 'DayMonthDD HH24:MI'),
to_char(end_date_time at time zone 'America/Chicago', '- HH24:MI PM' )
from tnris_forum_training
8 changes: 6 additions & 2 deletions src/data_hub/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def init_with_context(self, context):
'msd.models.MapSize',
'msd.models.PixelsPerInch',
'tnris_org.models.TnrisImage',
'tnris_org.models.TnrisDocument'),
'tnris_org.models.TnrisDocument',
'tnris_org.models.TnrisTraining',
'tnris_org.models.TnrisForumTraining'),
))

self.children.append(modules.AppList(
Expand Down Expand Up @@ -97,7 +99,9 @@ def init_with_context(self, context):
column=1,
css_classes=('grp-collapse grp-closed',),
models=('tnris_org.models.TnrisImage',
'tnris_org.models.TnrisDocument'),
'tnris_org.models.TnrisDocument',
'tnris_org.models.TnrisTraining',
'tnris_org.models.TnrisForumTraining'),
))

# append a recent actions module
Expand Down
4 changes: 3 additions & 1 deletion src/data_hub/lcd/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .views import resource_update_progress
import lore
import msd
import tnris_org


router = routers.DefaultRouter(trailing_slash=False)
Expand All @@ -36,5 +37,6 @@
path('data_hub-auth/?', include('rest_framework.urls', namespace='lcd_rest_framework')),
path('resource-update-progress/', resource_update_progress, name='resource-update-progress'),
path('historical/', include('lore.urls')),
path('map/', include('msd.urls'))
path('map/', include('msd.urls')),
path('tnris_org/', include('tnris_org.urls'))
]
29 changes: 27 additions & 2 deletions src/data_hub/tnris_org/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from django.contrib import admin

# Register your models here.
from .forms import ImageForm, DocumentForm
from .forms import (
ImageForm,
DocumentForm,
TnrisTrainingForm,
TnrisForumTrainingForm
)
from .models import (
TnrisImage,
TnrisDocument
TnrisDocument,
TnrisTraining,
TnrisForumTraining
)


Expand All @@ -24,3 +31,21 @@ class TnrisDocumentAdmin(admin.ModelAdmin):
ordering = ('document_name',)
list_display = ('document_name', 'document_url', 'created')
search_fields = ('document_name', 'document_url')


@admin.register(TnrisTraining)
class TnrisTrainingAdmin(admin.ModelAdmin):
model = TnrisTraining
form = TnrisTrainingForm
ordering = ('title',)
list_display = ('title', 'instructor', 'start_date_time', 'end_date_time')
search_fields = ('title', 'instructor')


@admin.register(TnrisForumTraining)
class TnrisForumTrainingAdmin(admin.ModelAdmin):
model = TnrisForumTraining
form = TnrisForumTrainingForm
ordering = ('title',)
list_display = ('title', 'instructor', 'start_date_time', 'end_date_time')
search_fields = ('title', 'instructor')
42 changes: 37 additions & 5 deletions src/data_hub/tnris_org/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@
from django.utils.safestring import mark_safe

from django.db.utils import ProgrammingError
from .models import (TnrisImage, TnrisDocument)
from .models import (TnrisImage, TnrisDocument, TnrisTraining, TnrisForumTraining)
import os
import boto3, uuid


class PictureWidget(forms.widgets.Widget):
def render(self, name, value, attrs=None):
html = Template("""<input type="file" name="$name" id="id_$name"><label for="img_$name">Current: <a href="$link" target="_blank">$link</a></label><img id="img_$name" src="$link"/>""")
if value is None:
html = Template("""<input type="file" name="$name" id="id_$name"><label for="img_$name">Current: <a href="$link" target="_blank">$link</a></label><img id="img_$name" src="$link"/>""")
else:
html = Template("""<input type="file" name="$name" id="id_$name" disabled><label for="img_$name">Current: <a href="$link" target="_blank">$link</a></label><img id="img_$name" src="$link"/>""")
return mark_safe(html.substitute(link=value,name=name))


class DocumentWidget(forms.widgets.Widget):
def render(self, name, value, attrs=None):
html = Template("""<input type="file" name="$name" id="id_$name"><label for="doc_$name">Current: <a href="$link">$link</a></label>""")
if value is None:
html = Template("""<input type="file" name="$name" id="id_$name"><label for="doc_$name">Current: <a href="$link">$link</a></label>""")
else:
html = Template("""<input type="file" name="$name" id="id_$name" disabled><label for="doc_$name">Current: <a href="$link">$link</a></label>""")
return mark_safe(html.substitute(link=value,name=name))


Expand Down Expand Up @@ -51,7 +57,7 @@ def handle_image(self, field, file):
return

# custom handling of images on save
def save(self, commit=True):
def clean(self, commit=True):
# check for files
files = self.files
for f in files:
Expand Down Expand Up @@ -98,7 +104,7 @@ def handle_doc(self, field, file):
return

# custom handling of documents on save
def save(self, commit=True):
def clean(self, commit=True):
# check for files
files = self.files
for f in files:
Expand All @@ -116,3 +122,29 @@ def save(self, commit=True):
self.handle_doc(f, files[f])

return super(DocumentForm, self).save(commit=commit)


class TnrisTrainingForm(forms.ModelForm):
class Meta:
model = TnrisTraining
fields = ('__all__')

start_date_time = forms.DateTimeField(help_text="Accepted date and time input formats: '10/25/06 14:30', '10/25/2006 14:30', '2006-10-25 14:30'")
end_date_time = forms.DateTimeField(help_text="Accepted date and time input formats: '10/25/06 14:30', '10/25/2006 14:30', '2006-10-25 14:30'")
cost = forms.DecimalField(help_text="Example of accepted formats for training cost: '50.00', '999', '99.99'. Max of 6 digits and 2 decimal places.")
registration_open = forms.BooleanField(required=False, help_text="Check the box to change registration to open. Default is unchecked.")
public = forms.BooleanField(required=False, help_text="Check the box to make this training record visible on the website. Default is unchecked.")
max_students = forms.IntegerField(required=False, help_text="Enter max number of students for class room.")


class TnrisForumTrainingForm(forms.ModelForm):
class Meta:
model = TnrisForumTraining
fields = ('__all__')

start_date_time = forms.DateTimeField(help_text="Accepted date and time input formats: '10/25/06 14:30', '10/25/2006 14:30', '2006-10-25 14:30'")
end_date_time = forms.DateTimeField(help_text="Accepted date and time input formats: '10/25/06 14:30', '10/25/2006 14:30', '2006-10-25 14:30'")
cost = forms.DecimalField(help_text="Example of accepted formats for training cost: '50.00', '999', '99.99'. Max of 6 digits and 2 decimal places.")
registration_open = forms.BooleanField(required=False, help_text="Check the box to change registration to open. Default is unchecked.")
public = forms.BooleanField(required=False, help_text="Check the box to make this training record visible on the website. Default is unchecked.")
max_students = forms.IntegerField(required=False, help_text="Enter max number of students for class room.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Generated by Django 2.0.13 on 2019-07-16 19:39

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [
('tnris_org', '0003_auto_20190711_1119'),
]

operations = [
migrations.CreateModel(
name='TnrisForumTraining',
fields=[
('training_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='Training ID')),
('training_day', models.PositiveSmallIntegerField(verbose_name='Forum Training Day')),
('title', models.CharField(max_length=255, verbose_name='Training Title')),
('start_date_time', models.DateTimeField(verbose_name='Training Start Date & Time')),
('end_date_time', models.DateTimeField(verbose_name='Training End Date & Time')),
('instructor', models.CharField(max_length=100, verbose_name='Training Instructor')),
('cost', models.DecimalField(decimal_places=2, max_digits=6, verbose_name='Training Cost')),
('registration_open', models.BooleanField(default=False, verbose_name='Registration Open')),
('location', models.CharField(max_length=255, verbose_name='Training Location')),
('room', models.CharField(max_length=255, verbose_name='Training Room')),
('max_students', models.PositiveSmallIntegerField(verbose_name='Max Student Amount')),
('instructor_bio', models.TextField(verbose_name='Training Instructor Bio')),
('description', models.TextField(verbose_name='Training Description')),
('teaser', models.TextField(verbose_name='Training Teaser')),
('created', models.DateTimeField(auto_now_add=True, verbose_name='Created')),
('last_modified', models.DateTimeField(auto_now=True, verbose_name='Last Modified')),
],
options={
'verbose_name': 'Tnris Forum Training',
'verbose_name_plural': 'Tnris Forum Trainings',
'db_table': 'tnris_forum_training',
},
),
migrations.CreateModel(
name='TnrisTraining',
fields=[
('training_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='Training ID')),
('start_date_time', models.DateTimeField(verbose_name='Training Start Date & Time')),
('end_date_time', models.DateTimeField(verbose_name='Training End Date & Time')),
('title', models.CharField(max_length=255, verbose_name='Training Title')),
('instructor', models.CharField(max_length=100, verbose_name='Training Instructor')),
('cost', models.DecimalField(decimal_places=2, max_digits=6, verbose_name='Training Cost')),
('registration_open', models.BooleanField(default=False, verbose_name='Registration Open')),
('instructor_bio', models.TextField(verbose_name='Training Instructor Bio')),
('description', models.TextField(verbose_name='Training Description')),
('created', models.DateTimeField(auto_now_add=True, verbose_name='Created')),
('last_modified', models.DateTimeField(auto_now=True, verbose_name='Last Modified')),
],
options={
'verbose_name': 'Tnris Training',
'verbose_name_plural': 'Tnris Trainings',
'db_table': 'tnris_training',
},
),
]
18 changes: 18 additions & 0 deletions src/data_hub/tnris_org/migrations/0005_auto_20190716_1531.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.13 on 2019-07-16 20:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tnris_org', '0004_tnrisforumtraining_tnristraining'),
]

operations = [
migrations.AlterField(
model_name='tnrisforumtraining',
name='instructor_bio',
field=models.TextField(blank=True, verbose_name='Training Instructor Bio'),
),
]
18 changes: 18 additions & 0 deletions src/data_hub/tnris_org/migrations/0006_auto_20190716_1532.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.13 on 2019-07-16 20:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tnris_org', '0005_auto_20190716_1531'),
]

operations = [
migrations.AlterField(
model_name='tnristraining',
name='instructor_bio',
field=models.TextField(blank=True, verbose_name='Training Instructor Bio'),
),
]
33 changes: 33 additions & 0 deletions src/data_hub/tnris_org/migrations/0007_auto_20190716_1543.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 2.0.13 on 2019-07-16 20:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tnris_org', '0006_auto_20190716_1532'),
]

operations = [
migrations.AddField(
model_name='tnrisforumtraining',
name='public',
field=models.BooleanField(default=False, verbose_name='Public'),
),
migrations.AddField(
model_name='tnristraining',
name='public',
field=models.BooleanField(default=False, verbose_name='Public'),
),
migrations.AlterField(
model_name='tnrisforumtraining',
name='max_students',
field=models.PositiveSmallIntegerField(blank=True, verbose_name='Max Student Amount'),
),
migrations.AlterField(
model_name='tnrisforumtraining',
name='teaser',
field=models.TextField(blank=True, verbose_name='Training Teaser'),
),
]
18 changes: 18 additions & 0 deletions src/data_hub/tnris_org/migrations/0008_auto_20190717_0733.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.13 on 2019-07-17 12:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tnris_org', '0007_auto_20190716_1543'),
]

operations = [
migrations.AlterField(
model_name='tnrisforumtraining',
name='room',
field=models.CharField(blank=True, max_length=255, verbose_name='Training Room'),
),
]
18 changes: 18 additions & 0 deletions src/data_hub/tnris_org/migrations/0009_auto_20190717_1453.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.13 on 2019-07-17 19:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tnris_org', '0008_auto_20190717_0733'),
]

operations = [
migrations.AlterField(
model_name='tnrisforumtraining',
name='max_students',
field=models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='Max Student Amount'),
),
]
Loading

0 comments on commit 809fb78

Please sign in to comment.