diff --git a/.gitignore b/.gitignore index 47a13d61..7753c3c2 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ # static files /babybuddy/static /static +/media diff --git a/Pipfile b/Pipfile index 658b6b3a..37eba577 100644 --- a/Pipfile +++ b/Pipfile @@ -1,8 +1,11 @@ [[source]] + verify_ssl = true url = "https://pypi.python.org/simple" + [packages] + django = "*" djangorestframework = "*" django-filter = "*" @@ -13,9 +16,12 @@ faker = "*" dj-database-url = "*" gunicorn = "*" whitenoise = "*" -psycopg2 = "*" +"psycopg2" = "*" +easy-thumbnails = "*" + [dev-packages] + coveralls = "*" -flake8 = "*" +"flake8" = "*" ipaddress = "*" diff --git a/babybuddy/settings/base.py b/babybuddy/settings/base.py index fa6e3ac9..d902a812 100644 --- a/babybuddy/settings/base.py +++ b/babybuddy/settings/base.py @@ -28,6 +28,7 @@ INSTALLED_APPS = [ 'django_filters', 'rest_framework', 'widget_tweaks', + 'easy_thumbnails', 'django.contrib.admin', 'django.contrib.auth', @@ -122,8 +123,12 @@ STATICFILES_FINDERS = [ STATIC_URL = '/static/' +MEDIA_URL = '/media/' + STATIC_ROOT = os.path.join(BASE_DIR, 'static') +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + WHITENOISE_ROOT = os.path.join(BASE_DIR, 'static', 'root') diff --git a/babybuddy/urls.py b/babybuddy/urls.py index ae1b8542..f0cb11e0 100644 --- a/babybuddy/urls.py +++ b/babybuddy/urls.py @@ -2,6 +2,8 @@ from __future__ import unicode_literals from django.conf.urls import url, include +from django.conf.urls.static import static +from django.conf import settings from django.contrib import admin from django.contrib.auth import views as auth_views @@ -25,3 +27,6 @@ urlpatterns = [ url(r'', include('dashboard.urls')), url(r'', include('reports.urls', namespace='reports')), ] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/core/forms.py b/core/forms.py index 3520449e..4a1d9130 100644 --- a/core/forms.py +++ b/core/forms.py @@ -40,7 +40,7 @@ def set_default_duration(kwargs): class ChildForm(forms.ModelForm): class Meta: model = models.Child - fields = ['first_name', 'last_name', 'birth_date'] + fields = ['first_name', 'last_name', 'birth_date', 'picture'] widgets = { 'birth_date': forms.DateInput(attrs={ 'class': 'datepicker-input', diff --git a/core/migrations/0004_child_picture.py b/core/migrations/0004_child_picture.py new file mode 100644 index 00000000..65854250 --- /dev/null +++ b/core/migrations/0004_child_picture.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-11-18 09:00 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_weight'), + ] + + operations = [ + migrations.AddField( + model_name='child', + name='picture', + field=models.ImageField(blank=True, null=True, upload_to='child/picture/'), + ), + ] diff --git a/core/models.py b/core/models.py index 63bd1154..66f28676 100644 --- a/core/models.py +++ b/core/models.py @@ -75,6 +75,11 @@ class Child(models.Model): last_name = models.CharField(max_length=255) birth_date = models.DateField(blank=False, null=False) slug = models.SlugField(max_length=100, unique=True, editable=False) + picture = models.ImageField( + upload_to='child/picture/', + blank=True, + null=True + ) objects = models.Manager() diff --git a/core/templates/core/child_detail.html b/core/templates/core/child_detail.html index ef9aa657..68476bb2 100644 --- a/core/templates/core/child_detail.html +++ b/core/templates/core/child_detail.html @@ -1,5 +1,5 @@ {% extends 'babybuddy/page.html' %} -{% load static %} +{% load static thumbnail %} {% block title %}{{ object }}{% endblock %} @@ -12,7 +12,12 @@
- + {% if object.picture %} + {% thumbnail object.picture 150x150 upscale crop as thumb %} + + {% else %} + + {% endif %}
{{ object }}

Born {{ object.birth_date }}
@@ -58,4 +63,4 @@

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/core/templates/core/child_list.html b/core/templates/core/child_list.html index 5137a083..f1f72373 100644 --- a/core/templates/core/child_list.html +++ b/core/templates/core/child_list.html @@ -1,5 +1,5 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load widget_tweaks thumbnail %} {% block title %}Children{% endblock %} @@ -14,6 +14,7 @@ + @@ -23,10 +24,16 @@ {% for child in object_list %} - - - - + + + +
First Name Last Name Birth Date
{{ child.first_name }}{{ child.last_name }}{{ child.birth_date }} + + {% thumbnail child.picture 40x40 upscale crop as thumb %} + + + {{ child.first_name }} + {{ child.last_name }}{{ child.birth_date }}
{% if perms.core.change_child %} @@ -60,4 +67,4 @@ {% endif %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/gulpfile.js/tasks/manage.js b/gulpfile.js/tasks/manage.js index 59c7dbdc..9c0920d4 100644 --- a/gulpfile.js/tasks/manage.js +++ b/gulpfile.js/tasks/manage.js @@ -21,6 +21,12 @@ gulp.task('migrate', function(cb) { spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb); }); +gulp.task('makemigrations', function(cb) { + var command = ['run', 'python', 'manage.py', 'makemigrations']; + command = command.concat(process.argv.splice(3)); + spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb); +}); + gulp.task('reset', function(cb) { spawn( @@ -42,4 +48,4 @@ gulp.task('runserver', function(cb) { var command = ['run', 'python', 'manage.py', 'runserver']; command = command.concat(process.argv.splice(3)); spawn('pipenv', command, { stdio: 'inherit' }).on('exit', cb); -}); \ No newline at end of file +});