Skip to content

Commit

Permalink
Added images to features.
Browse files Browse the repository at this point in the history
Using django-autocomplete-light.
  • Loading branch information
Eraldo committed Dec 22, 2014
1 parent a0aa679 commit dff2fbf
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions colegend/configuration/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
'markitup',
# usability
'keyboard',
'easy_thumbnails',
)
EXTRA_APPS = (
'django_extensions',
Expand Down
2 changes: 1 addition & 1 deletion colegend/configuration/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# django-autocomplet-light
url(r'^autocomplete/', include('autocomplete_light.urls')),

# robots.txt file for crawlers
# Added robots.txt file for crawlers (google/etc)
(r'^robots.txt$', lambda r: HttpResponse("User-agent: *\nDisallow: /", mimetype="text/plain")),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Expand Down
16 changes: 16 additions & 0 deletions colegend/features/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.contrib import admin
from django.conf import settings
from easy_thumbnails.fields import ThumbnailerField
from easy_thumbnails.widgets import ImageClearableFileInput
from features.models import Feature

__author__ = 'eraldo'
Expand All @@ -8,4 +11,17 @@ class FeatureAdmin(admin.ModelAdmin):
list_display = ['name', 'date_published', 'role']
list_filter = ['role']
search_fields = ['name']

# formfield_overrides = {
# ThumbnailerField: {'widget': ImageClearableFileInput},
# }

# def thumbnail(self, value):
# image = value.image
# if image:
# return '<img src="{}{}" />'.format(settings.MEDIA_URL, image)
# else:
# return ''
# thumbnail.allow_tags = True

admin.site.register(Feature, FeatureAdmin)
21 changes: 21 additions & 0 deletions colegend/features/migrations/0003_feature_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import easy_thumbnails.fields


class Migration(migrations.Migration):

dependencies = [
('features', '0002_feature_role'),
]

operations = [
migrations.AddField(
model_name='feature',
name='image',
field=easy_thumbnails.fields.ThumbnailerImageField(blank=True, upload_to='features', default=''),
preserve_default=False,
),
]
3 changes: 3 additions & 0 deletions colegend/features/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from django.utils import timezone
from easy_thumbnails.fields import ThumbnailerImageField

__author__ = 'eraldo'

Expand All @@ -25,6 +26,8 @@ class Feature(models.Model):
)
role = models.CharField(verbose_name="System Role", max_length=2, choices=ROLE_CHOICES, default=OPERATOR)

image = ThumbnailerImageField(upload_to='features', blank=True, resize_source=dict(size=(40, 40)))

objects = FeatureManager()

class Meta:
Expand Down
5 changes: 5 additions & 0 deletions colegend/features/templates/features/_feature.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<div class="feature well well-sm">
{% if feature.image %}
<div style="display: inline-block">
<img src="{{ MEDIA_URL }}{{ feature.image }}" alt="Feature Image">
</div>
{% endif %}
<b>{{ feature }}</b>
<div class="date-published-field inline"><small style="color: grey">&mdash; {{ feature.date_published }}</small></div>
<small class="pull-right"><span class="label label-default bg-{{ feature.get_role_display|lower }}"> {{ feature.get_role_display }}</span></small>
Expand Down
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ markdown-checklist==0.4.0

# Images
Pillow==2.5.3
easy-thumbnails==2.2

# For user registration, either via email or social
# Well-built with regular release cycles!
Expand Down

0 comments on commit dff2fbf

Please sign in to comment.