diff --git a/events/admin.py b/events/admin.py index 0cbe79e..fd770e0 100644 --- a/events/admin.py +++ b/events/admin.py @@ -10,6 +10,7 @@ from .models.profiles import ( Member, Category, Topic, + Sponsor, ) from .models.search import Searchable from .models.events import ( @@ -54,8 +55,12 @@ class OrgAdmin(admin.ModelAdmin): list_display = ('name', 'site') admin.site.register(Organization, OrgAdmin) +class SponsorAdmin(admin.ModelAdmin): + list_display = ('name', 'web_url') +admin.site.register(Sponsor, SponsorAdmin) + class TeamAdmin(admin.ModelAdmin): - raw_id_fields = ('country', 'spr', 'city', 'owner_profile', 'admin_profiles', 'contact_profiles') + raw_id_fields = ('country', 'spr', 'city', 'owner_profile', 'admin_profiles', 'contact_profiles', 'sponsors') list_display = ('__str__', 'active', 'member_count', 'event_count', 'owner_profile', 'created_date', 'is_premium', 'premium_expires') list_filter = ('active', 'is_premium', 'organization', ('country',admin.RelatedOnlyFieldListFilter)) ordering = ('-created_date',) @@ -78,7 +83,7 @@ class PlaceAdmin(admin.ModelAdmin): admin.site.register(Place, PlaceAdmin) class EventAdmin(admin.ModelAdmin): - raw_id_fields = ('place', 'created_by') + raw_id_fields = ('place', 'created_by', 'sponsors') list_display = ('__str__', 'attendee_count', 'start_time', 'created_by', 'created_time') ordering = ('-start_time',) def attendee_count(self, event): diff --git a/events/forms.py b/events/forms.py index 9fb7def..caba46e 100644 --- a/events/forms.py +++ b/events/forms.py @@ -7,7 +7,7 @@ from django.utils import timezone from django.contrib.auth.models import User from .models.locale import Country, SPR, City -from .models.profiles import Team, UserProfile +from .models.profiles import Team, UserProfile, Sponsor from .models.events import ( Event, EventComment, @@ -291,6 +291,11 @@ class EventCommentForm(forms.ModelForm): model = EventComment fields = ['body'] +class SponsorForm(forms.ModelForm): + class Meta: + model = Sponsor + fields = ['name', 'web_url', 'logo'] + class NewPlaceForm(forms.ModelForm): class Meta: model = Place diff --git a/events/migrations/0031_add_sponsors.py b/events/migrations/0031_add_sponsors.py new file mode 100644 index 0000000..77aa341 --- /dev/null +++ b/events/migrations/0031_add_sponsors.py @@ -0,0 +1,34 @@ +# Generated by Django 2.0 on 2018-05-19 02:10 + +from django.db import migrations, models +import imagekit.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0030_add_attendee_actual_status'), + ] + + operations = [ + migrations.CreateModel( + name='Sponsor', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=256, verbose_name='Sponsor Name')), + ('description', models.TextField(blank=True, null=True)), + ('web_url', models.URLField(blank=True, null=True, verbose_name='Website')), + ('logo', imagekit.models.fields.ProcessedImageField(blank=True, help_text='Will be scaled and cropped to max 250x200 px.', upload_to='sponsors', verbose_name='Sponsor Logo')), + ], + ), + migrations.AddField( + model_name='event', + name='sponsors', + field=models.ManyToManyField(related_name='events', to='events.Sponsor'), + ), + migrations.AddField( + model_name='team', + name='sponsors', + field=models.ManyToManyField(related_name='teams', to='events.Sponsor'), + ), + ] diff --git a/events/models/events.py b/events/models/events.py index 3f2ff13..ae2a231 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -77,6 +77,8 @@ class Event(models.Model): attendees = models.ManyToManyField(UserProfile, through='Attendee', related_name="attending", blank=True) + sponsors = models.ManyToManyField('Sponsor', related_name='events') + @property def is_over(self): return self.end_time <= timezone.now() diff --git a/events/models/profiles.py b/events/models/profiles.py index 7751fbf..9cdefdc 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -6,7 +6,9 @@ from django.utils import timezone from django.conf import settings from imagekit.models import ProcessedImageField -from imagekit.processors import ResizeToFill +from imagekit.processors import ResizeToFill, ResizeToFit + +from rest_framework import serializers from .locale import * from .. import location @@ -195,6 +197,29 @@ class Organization(models.Model): def __str__(self): return u'%s' % (self.name) +class Sponsor(models.Model): + name = models.CharField(_("Sponsor Name"), max_length=256, null=False, blank=False) + description = models.TextField(blank=True, null=True) + web_url = models.URLField(_("Website"), null=True, blank=True) + logo = ProcessedImageField(verbose_name=_("Logo"), help_text=_("Will be scaled and cropped to max 250x200 px."), + upload_to='sponsors', + processors=[ResizeToFit(250, 200)], + format='PNG', + blank=True) + def __str__(self): + return self.name + +class SponsorSerializer(serializers.ModelSerializer): + display = serializers.CharField(source='__str__', read_only=True) + class Meta: + model = Sponsor + fields = ( + 'id', + 'name', + 'logo', + 'web_url', + ) + class Team(models.Model): name = models.CharField(_("Team Name"), max_length=256, null=False, blank=False) organization = models.ForeignKey(Organization, related_name='teams', null=True, blank=True, on_delete=models.CASCADE) @@ -224,6 +249,8 @@ class Team(models.Model): category = models.ForeignKey('Category', on_delete=models.SET_NULL, blank=False, null=True) topics = models.ManyToManyField('Topic', blank=True) + sponsors = models.ManyToManyField('Sponsor', related_name='teams') + is_premium = models.BooleanField(default=settings.EVENTS_TEAMS_DEFAULT_PREMIUM) premium_by = models.ForeignKey(UserProfile, related_name='premium_teams', null=True, on_delete=models.SET_NULL) premium_started = models.DateTimeField(blank=True, null=True) diff --git a/events/views.py b/events/views.py index 4e0995a..b3e2cee 100644 --- a/events/views.py +++ b/events/views.py @@ -9,7 +9,7 @@ from rest_framework.response import Response from .models.search import Searchable, SearchableSerializer from .models.events import Event, EventComment, Place, PlaceSerializer, Attendee from .models.locale import Country ,CountrySerializer, SPR, SPRSerializer, City, CitySerializer -from .models.profiles import Team, UserProfile, Member +from .models.profiles import Team, UserProfile, Member, Sponsor, SponsorSerializer from .forms import EventCommentForm import simplejson @@ -78,7 +78,7 @@ def city_list(request, *args, **kwargs): @api_view(['GET']) def find_city(request): cities = City.objects.all() - if "city" in request.GET: + if "name" in request.GET: cities = cities.filter(name=request.GET.get("city")) if "spr" in request.GET: cities = cities.filter(spr__name=request.GET.get("spr")) @@ -91,6 +91,19 @@ def find_city(request): except: return Response({}) + +@api_view(['GET']) +def sponsor_list(request): + if "q" in request.GET: + match = request.GET.get("q", "") + sponsors = Sponsor.objects.filter(name__icontains=match) + else: + sponsors = Sponsor.objects.all() + + serializer = SponsorSerializer(sponsors[:50], many=True) + return Response(serializer.data) + + def join_team(request, team_id): if request.user.is_anonymous: messages.add_message(request, messages.WARNING, message=_('You must be logged in to join a team.')) diff --git a/get_together/templates/get_together/events/manage_event_sponsors.html b/get_together/templates/get_together/events/manage_event_sponsors.html new file mode 100644 index 0000000..105f7be --- /dev/null +++ b/get_together/templates/get_together/events/manage_event_sponsors.html @@ -0,0 +1,116 @@ +{% extends "get_together/base.html" %} +{% load static markup tz %} + +{% block add_to_title %} | {{event.name}}{% endblock %} + +{% block styles %} + + +{% endblock %} + +{% block content %} +
+ Lookup sponsors: +