From a366fa951b553529695122b25a7e4d2a68a6ea0e Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sun, 10 Jun 2018 13:06:46 -0400 Subject: [PATCH] Finish up Bheesham's work on adding team images for card covers and banners, fixes #25 --- events/forms.py | 17 +++++++-- .../0033_remove_unused_team_cover_img.py | 18 ++++++++++ .../0034_add_imagekit_team_cover_img.py | 19 ++++++++++ events/models/events.py | 36 +++++++++++++------ events/models/profiles.py | 30 ++++++++++++++-- events/templates/events/new_team_form.html | 4 +++ get_together/static/css/get_together.css | 15 ++++++++ .../get_together/events/list_events.html | 8 ++--- .../get_together/events/show_event.html | 10 ++++-- .../templates/get_together/index.html | 6 +--- .../get_together/teams/create_team.html | 2 +- .../get_together/teams/edit_team.html | 2 +- .../get_together/teams/list_teams.html | 6 +--- .../get_together/teams/show_team.html | 31 +++++++++------- get_together/views/teams.py | 4 +-- 15 files changed, 160 insertions(+), 48 deletions(-) create mode 100644 events/migrations/0033_remove_unused_team_cover_img.py create mode 100644 events/migrations/0034_add_imagekit_team_cover_img.py diff --git a/events/forms.py b/events/forms.py index caba46e..70536c5 100644 --- a/events/forms.py +++ b/events/forms.py @@ -155,7 +155,15 @@ class DateTimeWidget(forms.SplitDateTimeWidget): class TeamForm(forms.ModelForm): class Meta: model = Team - fields = ['name', 'description', 'category', 'city', 'web_url', 'tz'] + fields = [ + 'name', + 'description', + 'category', + 'city', + 'web_url', + 'tz', + 'cover_img', + ] widgets = { 'city': Lookup(source=City), } @@ -167,7 +175,12 @@ class TeamForm(forms.ModelForm): class NewTeamForm(forms.ModelForm): class Meta: model = Team - fields = ['name', 'city', 'tz'] + fields = [ + 'name', + 'city', + 'tz', + 'cover_img', + ] widgets = { 'city': Lookup(source=City), } diff --git a/events/migrations/0033_remove_unused_team_cover_img.py b/events/migrations/0033_remove_unused_team_cover_img.py new file mode 100644 index 0000000..bd054d6 --- /dev/null +++ b/events/migrations/0033_remove_unused_team_cover_img.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0 on 2018-06-10 15:31 + +from django.db import migrations, models +import imagekit.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0032_add_team_slug'), + ] + + operations = [ + migrations.RemoveField( + model_name='team', + name='cover_img', + ), + ] diff --git a/events/migrations/0034_add_imagekit_team_cover_img.py b/events/migrations/0034_add_imagekit_team_cover_img.py new file mode 100644 index 0000000..b0577d9 --- /dev/null +++ b/events/migrations/0034_add_imagekit_team_cover_img.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0 on 2018-06-10 15:34 + +from django.db import migrations, models +import imagekit.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0033_remove_unused_team_cover_img'), + ] + + operations = [ + migrations.AddField( + model_name='team', + name='cover_img', + field=models.ImageField(blank=True, null=True, upload_to='team_covers', verbose_name='Cover Image'), + ), + ] diff --git a/events/models/events.py b/events/models/events.py index ae2a231..0da4f92 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -4,6 +4,7 @@ from django.contrib.auth.models import User, Group from django.utils.translation import ugettext_lazy as _ from django.shortcuts import reverse from django.utils import timezone +from django.conf import settings from rest_framework import serializers from mptt.models import MPTTModel, TreeForeignKey @@ -132,8 +133,13 @@ class Event(models.Model): def update_event_searchable(event): site = Site.objects.get(id=1) - event_url = "https://%s%s" % (site.domain, event.get_absolute_url()) - origin_url = "https://%s%s" % (site.domain, reverse('searchables')) + if settings.DEBUG: + schema = 'http' + else: + schema = 'https' + + event_url = "%s://%s%s" % (schema, site.domain, event.get_absolute_url()) + origin_url = "%s://%s%s" % (schema, site.domain, reverse('searchables')) md5 = hashlib.md5() federation_url = event_url.split('/') @@ -152,10 +158,8 @@ def update_event_searchable(event): searchable.event_url = event_url - if event.team.category: - searchable.img_url = event.team.category.img_url - else: - searchable.img_url = "https://%s%s" % (site.domain, '/static/img/team_placeholder.png') + searchable.img_url = "%s://%s%s" % (schema, site.domain, event.team.card_img_url) + searchable.event_title = event.name searchable.group_name = event.team.name searchable.start_time = event.start_time @@ -179,8 +183,12 @@ def update_event_searchable(event): def delete_event_searchable(event): site = Site.objects.get(id=1) - event_url = "https://%s%s" % (site.domain, event.get_absolute_url()) - origin_url = "https://%s%s" % (site.domain, reverse('searchables')) + if settings.DEBUG: + schema = 'http' + else: + schema = 'https' + event_url = "%s://%s%s" % (schema, site.domain, event.get_absolute_url()) + origin_url = "%s://%s%s" % (schema, site.domain, reverse('searchables')) md5 = hashlib.md5() federation_url = event_url.split('/') @@ -295,7 +303,11 @@ class CommonEvent(models.Model): def get_full_url(self): site = self.organization.site - return "https://%s%s" % (site.domain, self.get_absolute_url()) + if settings.DEBUG: + schema = 'http' + else: + schema = 'https' + return "%s://%s%s" % (schema, site.domain, self.get_absolute_url()) @property def slug(self): @@ -370,7 +382,11 @@ class EventSeries(models.Model): def get_full_url(self): site = Site.objects.get(id=1) - return "https://%s%s" % (site.domain, self.get_absolute_url()) + if settings.DEBUG: + schema = 'http' + else: + schema = 'https' + return "%s://%s%s" % (schema, site.domain, self.get_absolute_url()) @property def slug(self): diff --git a/events/models/profiles.py b/events/models/profiles.py index 674b792..81c73d6 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -1,12 +1,13 @@ from django.db import models from django.contrib.sites.models import Site from django.contrib.auth.models import User, Group, AnonymousUser +from django.contrib.staticfiles.templatetags.staticfiles import static from django.utils.translation import ugettext_lazy as _ from django.utils import timezone from django.conf import settings -from imagekit.models import ProcessedImageField -from imagekit.processors import ResizeToFill, ResizeToFit +from imagekit.models import ProcessedImageField, ImageSpecField +from imagekit.processors import ResizeToFill, ResizeToFit, Adjust, ColorOverlay from rest_framework import serializers @@ -225,6 +226,21 @@ class Team(models.Model): slug = models.CharField(max_length=256, null=False, blank=False, unique=True) organization = models.ForeignKey(Organization, related_name='teams', null=True, blank=True, on_delete=models.CASCADE) + cover_img = models.ImageField(verbose_name=_('Cover Image'), upload_to='team_covers', null=True, blank=True) + tile_img = ImageSpecField(source='cover_img', + processors=[ + Adjust(contrast=0.8, color=1), + ResizeToFill(338, 200), + ], + format='PNG') + + banner_img = ImageSpecField(source='cover_img', + processors=[ + Adjust(contrast=0.8, color=1), + ResizeToFill(825, 200), + ], + format='PNG') + description = models.TextField(blank=True, null=True) country = models.ForeignKey(Country, on_delete=models.CASCADE) @@ -240,7 +256,6 @@ class Team(models.Model): admin_profiles = models.ManyToManyField(UserProfile, related_name='admins', blank=True) contact_profiles = models.ManyToManyField(UserProfile, related_name='contacts', blank=True) - cover_img = models.URLField(_("Team Photo"), null=True, blank=True) languages = models.ManyToManyField(Language, blank=True) active = models.BooleanField(_("Active Team"), default=True) tz = models.CharField(max_length=32, verbose_name=_('Default Timezone'), default='UTC', choices=location.TimezoneChoices(), blank=False, null=False, help_text=_('The most commonly used timezone for this Team.')) @@ -257,6 +272,15 @@ class Team(models.Model): premium_started = models.DateTimeField(blank=True, null=True) premium_expires = models.DateTimeField(blank=True, null=True) + @property + def card_img_url(self): + if self.tile_img is not None and self.tile_img.name is not None: + return self.tile_img.url + elif self.category is not None: + return self.category.img_url + else: + return static('img/team_placeholder.png') + @property def location_name(self): if self.city: diff --git a/events/templates/events/new_team_form.html b/events/templates/events/new_team_form.html index 2bab003..1869fe8 100644 --- a/events/templates/events/new_team_form.html +++ b/events/templates/events/new_team_form.html @@ -12,4 +12,8 @@ {{ team_form.tz }} + + + {{ team_form.cover_img }} + diff --git a/get_together/static/css/get_together.css b/get_together/static/css/get_together.css index a0b86b6..00d511a 100644 --- a/get_together/static/css/get_together.css +++ b/get_together/static/css/get_together.css @@ -95,3 +95,18 @@ ul.errorlist li { border-color: #ebcccc; color: #a94442; } + +.team-banner { + position: relative; + margin-bottom: 3px; +} + +.team-banner .team-title { + position: absolute; + bottom: 0px; + left: 6px; + color: #FFF; + font-size: 2em; + font-weight: bold; + text-shadow: 2px 2px #444; +} \ No newline at end of file diff --git a/get_together/templates/get_together/events/list_events.html b/get_together/templates/get_together/events/list_events.html index ae5bd1d..030d311 100644 --- a/get_together/templates/get_together/events/list_events.html +++ b/get_together/templates/get_together/events/list_events.html @@ -19,12 +19,10 @@
- {% if event.team.category %} - {{event.name}} - {% else %} - {{event.name}} - {% endif %} + + {{event.name}}

{{event.team.name}}

+

{{event.name}}

diff --git a/get_together/templates/get_together/events/show_event.html b/get_together/templates/get_together/events/show_event.html index 7a8a0a4..653c63f 100644 --- a/get_together/templates/get_together/events/show_event.html +++ b/get_together/templates/get_together/events/show_event.html @@ -99,8 +99,14 @@
-

{{ event.name }} -

+ {% if team.banner_img %} +
+ {{team.name}}'s cover image +

{{ event.name }}

+
+ {% else %} +

{{ event.name }}

+ {% endif %}

Hosted by {{ team.name }}

{% if settings.SOCIAL_AUTH_TWITTER_KEY %} Tweet diff --git a/get_together/templates/get_together/index.html b/get_together/templates/get_together/index.html index 6d20e6e..034a5c8 100644 --- a/get_together/templates/get_together/index.html +++ b/get_together/templates/get_together/index.html @@ -69,11 +69,7 @@
diff --git a/get_together/templates/get_together/teams/create_team.html b/get_together/templates/get_together/teams/create_team.html index d3281de..aade6f5 100644 --- a/get_together/templates/get_together/teams/create_team.html +++ b/get_together/templates/get_together/teams/create_team.html @@ -3,7 +3,7 @@ {% block content %}

Get Together with friends

-
+ {% csrf_token %} {% include "events/team_form.html" %} diff --git a/get_together/templates/get_together/teams/edit_team.html b/get_together/templates/get_together/teams/edit_team.html index 23dce40..ab2039c 100644 --- a/get_together/templates/get_together/teams/edit_team.html +++ b/get_together/templates/get_together/teams/edit_team.html @@ -2,7 +2,7 @@ {% load static %} {% block content %}

Update {{team.name}}

- + {% csrf_token %} {% include "events/team_form.html" %}
diff --git a/get_together/templates/get_together/teams/list_teams.html b/get_together/templates/get_together/teams/list_teams.html index 490b278..93ee427 100644 --- a/get_together/templates/get_together/teams/list_teams.html +++ b/get_together/templates/get_together/teams/list_teams.html @@ -21,11 +21,7 @@
diff --git a/get_together/templates/get_together/teams/show_team.html b/get_together/templates/get_together/teams/show_team.html index 0ba4fe3..a60ace1 100644 --- a/get_together/templates/get_together/teams/show_team.html +++ b/get_together/templates/get_together/teams/show_team.html @@ -1,5 +1,5 @@ {% extends "get_together/base.html" %} -{% load markup tz %} +{% load static markup tz %} {% block add_to_title %} | {{team.name}}{% endblock %} @@ -21,17 +21,24 @@
-

Welcome to {{ team.name }} -

- {% if can_edit_team %} - Edit Team - Manage Members - {% endif %} - {% if is_member %} - {% if not team.owner_profile == request.user.profile %}Leave Team{% endif %} - {% else %} - Join Team - {% endif %} + {% if team.banner_img %} +
+ {{team.name}}'s cover image +

Welcome to {{ team.name }}

+
+ {% else %} +

Welcome to {{ team.name }}

+ {% endif %} + + {% if can_edit_team %} + Edit Team + Manage Members + {% endif %} + {% if is_member %} + {% if not team.owner_profile == request.user.profile %}Leave Team{% endif %} + {% else %} + Join Team + {% endif %}
diff --git a/get_together/views/teams.py b/get_together/views/teams.py index 23e0228..9f596cf 100644 --- a/get_together/views/teams.py +++ b/get_together/views/teams.py @@ -80,7 +80,7 @@ def create_team(request, *args, **kwargs): } return render(request, 'get_together/teams/create_team.html', context) elif request.method == 'POST': - form = NewTeamForm(request.POST) + form = NewTeamForm(request.POST, request.FILES) if form.is_valid(): new_team = form.save() new_team.owner_profile = request.user.profile @@ -111,7 +111,7 @@ def edit_team(request, team_id): } return render(request, 'get_together/teams/edit_team.html', context) elif request.method == 'POST': - form = TeamForm(request.POST, instance=team) + form = TeamForm(request.POST, request.FILES, instance=team) if form.is_valid(): new_team = form.save() new_team.owner_profile = request.user.profile