From e37a945220711864ae55ff618ae3e68044854d42 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Tue, 23 Jan 2018 11:12:46 -0500 Subject: [PATCH] Fix and simplify the new team form --- events/forms.py | 6 +- events/models/profiles.py | 18 ++++++ get_together/templates/get_together/base.html | 5 +- .../templates/get_together/create_team.html | 62 ++++++------------- get_together/views.py | 2 +- 5 files changed, 43 insertions(+), 50 deletions(-) diff --git a/events/forms.py b/events/forms.py index 8327f58..786f895 100644 --- a/events/forms.py +++ b/events/forms.py @@ -160,10 +160,10 @@ class TeamForm(ModelForm): class NewTeamForm(ModelForm): class Meta: model = Team - fields = ['name', 'country', 'spr', 'city', 'web_url', 'tz'] + fields = ['name', 'city', 'web_url', 'tz'] widgets = { - 'country': Lookup(source='/api/country/', label='name'), - 'spr': Lookup(source='/api/spr/', label='name'), + #'country': Lookup(source='/api/country/', label='name'), + #'spr': Lookup(source='/api/spr/', label='name'), 'city': Lookup(source='/api/cities/', label='name'), } raw_id_fields = ('country','spr','city') diff --git a/events/models/profiles.py b/events/models/profiles.py index 1a75156..80a8dd9 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -141,9 +141,27 @@ class Team(models.Model): members = models.ManyToManyField(UserProfile, through='Member', related_name="memberships", blank=True) + @property + def location_name(self): + if self.city: + return str(self.city) + elif self.spr: + return str(self.spr) + elif self.country: + return str(self.country) + else: + return '' + def __str__(self): return u'%s' % (self.name) + def save(self, *args, **kwargs): + if self.city is not None: + self.spr = self.city.spr + self.country = self.spr.country + super().save(*args, **kwargs) # Call the "real" save() method. + + class Member(models.Model): NORMAL=0 MODERATOR=1 diff --git a/get_together/templates/get_together/base.html b/get_together/templates/get_together/base.html index 9f114dc..d347319 100644 --- a/get_together/templates/get_together/base.html +++ b/get_together/templates/get_together/base.html @@ -86,9 +86,8 @@ form { - - + + - {% block javascript %}{% endblock %} diff --git a/get_together/templates/get_together/create_team.html b/get_together/templates/get_together/create_team.html index 5ed77d0..3d5e66a 100644 --- a/get_together/templates/get_together/create_team.html +++ b/get_together/templates/get_together/create_team.html @@ -13,53 +13,29 @@ {% block javascript %} + +}); + + + {% endblock %} diff --git a/get_together/views.py b/get_together/views.py index b4a26e0..8d88e1e 100644 --- a/get_together/views.py +++ b/get_together/views.py @@ -25,7 +25,7 @@ def home(request, *args, **kwards): return render(request, 'get_together/index.html') def events_list(request, *args, **kwargs): - events = Event.objects.order_by('start_time').all() + events = Event.objects.filter(end_time__gt=datetime.datetime.now()).order_by('start_time') context = { 'events_list': events, }