diff --git a/events/admin.py b/events/admin.py index 17b9a56..a5d0ab4 100644 --- a/events/admin.py +++ b/events/admin.py @@ -1,8 +1,9 @@ from django.contrib import admin +from django.utils.safestring import mark_safe # Register your models here. from .models.locale import Language, Continent, Country, SPR, City -from .models.profiles import UserProfile, Organization, Team, Member +from .models.profiles import UserProfile, Organization, Team, Member, Category, Topic from .models.search import Searchable from .models.events import Place, Event, Attendee @@ -61,4 +62,13 @@ admin.site.register(Event, EventAdmin) admin.site.register(Member) admin.site.register(Attendee) +class CategoryAdmin(admin.ModelAdmin): + list_display = ('name', 'image') + def image(self, obj): + return (mark_safe('' % (obj.img_url, obj.name))) + image.short_description = 'Image' +admin.site.register(Category, CategoryAdmin) +class TopicAdmin(admin.ModelAdmin): + list_display = ('name', 'category') + list_filter = ('category',) diff --git a/events/forms.py b/events/forms.py index e4e867b..11fa813 100644 --- a/events/forms.py +++ b/events/forms.py @@ -150,7 +150,7 @@ class DateTimeWidget(forms.SplitDateTimeWidget): class TeamForm(forms.ModelForm): class Meta: model = Team - fields = ['name', 'description', 'city', 'web_url', 'tz'] + fields = ['name', 'description', 'category', 'city', 'web_url', 'tz'] widgets = { 'city': Lookup(source='/api/cities/', label='name'), } @@ -162,7 +162,7 @@ class TeamForm(forms.ModelForm): class NewTeamForm(forms.ModelForm): class Meta: model = Team - fields = ['name', 'description', 'city', 'web_url', 'tz'] + fields = ['name', 'description', 'category', 'city', 'web_url', 'tz'] widgets = { 'city': Lookup(source='/api/cities/', label='name'), } diff --git a/events/migrations/0009_auto_20180225_2202.py b/events/migrations/0011_auto_20180227_0210.py similarity index 71% rename from events/migrations/0009_auto_20180225_2202.py rename to events/migrations/0011_auto_20180227_0210.py index 76526d2..8b40bb6 100644 --- a/events/migrations/0009_auto_20180225_2202.py +++ b/events/migrations/0011_auto_20180227_0210.py @@ -1,4 +1,4 @@ -# Generated by Django 2.0 on 2018-02-25 22:02 +# Generated by Django 2.0 on 2018-02-27 02:10 from django.db import migrations, models import django.db.models.deletion @@ -7,7 +7,7 @@ import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - ('events', '0008_add-team-description'), + ('events', '0010_userprofile_send_notifications'), ] operations = [ @@ -17,7 +17,7 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=256)), ('description', models.TextField()), - ('img', models.URLField()), + ('img_url', models.URLField()), ], ), migrations.CreateModel( @@ -34,16 +34,6 @@ class Migration(migrations.Migration): name='tags', field=models.CharField(blank=True, help_text='Comma-separates list of tags', max_length=128, null=True, verbose_name='Keyword Tags'), ), - migrations.AlterField( - model_name='searchable', - name='venue_name', - field=models.CharField(blank=True, max_length=256), - ), - migrations.AlterField( - model_name='userprofile', - name='avatar', - field=models.URLField(blank=True, max_length=150, null=True, verbose_name='Photo Image'), - ), migrations.AddField( model_name='event', name='topics', @@ -51,8 +41,8 @@ class Migration(migrations.Migration): ), migrations.AddField( model_name='team', - name='categories', - field=models.ManyToManyField(blank=True, to='events.Category'), + name='category', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='events.Category'), ), migrations.AddField( model_name='team', diff --git a/events/migrations/0012_auto_20180227_0358.py b/events/migrations/0012_auto_20180227_0358.py new file mode 100644 index 0000000..e7525e9 --- /dev/null +++ b/events/migrations/0012_auto_20180227_0358.py @@ -0,0 +1,28 @@ +# Generated by Django 2.0 on 2018-02-27 03:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0011_auto_20180227_0210'), + ] + + operations = [ + migrations.RemoveField( + model_name='event', + name='topics', + ), + migrations.AddField( + model_name='searchable', + name='img_url', + field=models.URLField(default='https://gettogether.community/static/img/team_placeholder.png'), + preserve_default=False, + ), + migrations.AlterField( + model_name='event', + name='tags', + field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Keyword Tags'), + ), + ] diff --git a/events/models/events.py b/events/models/events.py index bccd3fd..d085f82 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -64,14 +64,12 @@ class Event(models.Model): created_by = models.ForeignKey(UserProfile, on_delete=models.CASCADE) created_time = models.DateTimeField(help_text=_('the date and time when the event was created'), default=datetime.datetime.now, db_index=True) - tags = models.CharField(verbose_name=_("Keyword Tags"), help_text=_('Comma-separates list of tags'), blank=True, null=True, max_length=128) + tags = models.CharField(verbose_name=_("Keyword Tags"), blank=True, null=True, max_length=128) #image #replies attendees = models.ManyToManyField(UserProfile, through='Attendee', related_name="attending", blank=True) - topics = models.ManyToManyField('Topic', blank=True) - def get_absolute_url(self): return reverse('show-event', kwargs={'event_id': self.id, 'event_slug': self.slug}) @@ -102,6 +100,10 @@ def update_event_searchable(event): searchable.federation_node = origin_url searchable.federation_time = datetime.datetime.now() + 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.event_title = event.name searchable.group_name = event.team.name searchable.start_time = event.start_time diff --git a/events/models/profiles.py b/events/models/profiles.py index a69ed10..7e0867d 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -157,7 +157,7 @@ class Team(models.Model): members = models.ManyToManyField(UserProfile, through='Member', related_name="memberships", blank=True) - categories = models.ManyToManyField('Category', blank=True) + category = models.ForeignKey('Category', on_delete=models.SET_NULL, blank=False, null=True) topics = models.ManyToManyField('Topic', blank=True) @property @@ -205,9 +205,17 @@ class Member(models.Model): class Category(models.Model): name = models.CharField(max_length=256) description = models.TextField() - img = models.URLField(blank=False, null=False) + img_url = models.URLField(blank=False, null=False) + + def __str__(self): + return self.name class Topic(models.Model): category = models.ForeignKey(Category, on_delete=models.CASCADE, null=False, blank=False) name = models.CharField(max_length=256) description = models.TextField() + + def __str__(self): + return self.name + + diff --git a/events/models/search.py b/events/models/search.py index fbee732..d21edc6 100644 --- a/events/models/search.py +++ b/events/models/search.py @@ -8,6 +8,7 @@ import datetime class Searchable(models.Model): event_url = models.URLField(primary_key=True, null=False, blank=False) event_title = models.CharField(max_length=256, null=False, blank=False) + img_url = models.URLField(null=False, blank=False) location_name = models.CharField(max_length=256, null=False, blank=False) group_name = models.CharField(max_length=256, null=False, blank=False) venue_name = models.CharField(max_length=256, null=False, blank=True) diff --git a/get_together/static/img/categories/activism.png b/get_together/static/img/categories/activism.png new file mode 100644 index 0000000..2c8f0c8 Binary files /dev/null and b/get_together/static/img/categories/activism.png differ diff --git a/get_together/static/img/categories/dining.png b/get_together/static/img/categories/dining.png new file mode 100644 index 0000000..e61f444 Binary files /dev/null and b/get_together/static/img/categories/dining.png differ diff --git a/get_together/static/img/categories/music.png b/get_together/static/img/categories/music.png new file mode 100644 index 0000000..f0fab61 Binary files /dev/null and b/get_together/static/img/categories/music.png differ diff --git a/get_together/static/img/categories/outdoor.png b/get_together/static/img/categories/outdoor.png new file mode 100644 index 0000000..be41121 Binary files /dev/null and b/get_together/static/img/categories/outdoor.png differ diff --git a/get_together/static/img/categories/tech.png b/get_together/static/img/categories/tech.png new file mode 100644 index 0000000..870866f Binary files /dev/null and b/get_together/static/img/categories/tech.png differ diff --git a/get_together/templates/get_together/events/list_events.html b/get_together/templates/get_together/events/list_events.html index 626bf24..ca39220 100644 --- a/get_together/templates/get_together/events/list_events.html +++ b/get_together/templates/get_together/events/list_events.html @@ -14,7 +14,11 @@
+ {% if event.team.category %} + {{event.name}} + {% else %} {{event.name}} + {% endif %}

{{event.team.name}}

diff --git a/get_together/templates/get_together/index.html b/get_together/templates/get_together/index.html index 79a4650..f41ec2a 100644 --- a/get_together/templates/get_together/index.html +++ b/get_together/templates/get_together/index.html @@ -25,7 +25,11 @@
+ {% if event.team.category %} + {{event.event_title}} + {% else %} {{event.event_title}} + {% endif %}

{{event.group_name}}

@@ -57,7 +61,11 @@
+ {% if team.category %} + {{team.name}} + {% else %} {{team.name}} + {% endif %}

{{team.name}}

diff --git a/get_together/templates/get_together/teams/create_team.html b/get_together/templates/get_together/teams/create_team.html index ae99682..cfb6819 100644 --- a/get_together/templates/get_together/teams/create_team.html +++ b/get_together/templates/get_together/teams/create_team.html @@ -30,6 +30,7 @@ $(document).ready(function(){ }); } }) + $("#id_category").selectmenu(); $("#id_tz").selectmenu(); }); diff --git a/get_together/templates/get_together/teams/edit_team.html b/get_together/templates/get_together/teams/edit_team.html index 9b3b273..716b984 100644 --- a/get_together/templates/get_together/teams/edit_team.html +++ b/get_together/templates/get_together/teams/edit_team.html @@ -29,6 +29,7 @@ $(document).ready(function(){ }); } }) + $("#id_category").selectmenu(); $("#id_tz").selectmenu(); }); diff --git a/get_together/templates/get_together/teams/list_teams.html b/get_together/templates/get_together/teams/list_teams.html index 6cc77d5..1dadca7 100644 --- a/get_together/templates/get_together/teams/list_teams.html +++ b/get_together/templates/get_together/teams/list_teams.html @@ -1,4 +1,9 @@ {% extends "get_together/base.html" %} +{% load static %} + +{% block styles %} + +{% endblock %} {% block content %} {% if my_teams %} @@ -7,14 +12,41 @@
{% endif %} -

All Teams

-{% include "events/team_list.html" with teams_list=all_teams%} - {% if request.user.is_authenticated %}
{% endif %} + +

All Teams

+
+
+ {% for team in all_teams %} +
+
+
+ {% if team.category %} + {{team.name}} + {% else %} + {{team.name}} + {% endif %} +

{{team.name}}

+
+
+

{{team.city}}

+
+ {{ team.members.count }} members +
+ View +
+
+
+
+
+ {% endfor %} +
+
+ {% endblock %}