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 @@
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 @@