Add premium fields to Team objects, only show presentations for premium teams

This commit is contained in:
Michael Hall 2018-04-27 18:11:05 -04:00
parent 8e7c955928
commit f5ac0c2fdd
5 changed files with 65 additions and 1 deletions

View file

@ -55,11 +55,15 @@ admin.site.register(Organization, OrgAdmin)
class TeamAdmin(admin.ModelAdmin):
raw_id_fields = ('country', 'spr', 'city', 'owner_profile', 'admin_profiles', 'contact_profiles')
list_display = ('__str__', 'member_count', 'owner_profile', 'created_date')
list_display = ('__str__', 'active', 'member_count', 'event_count', 'owner_profile', 'created_date', 'is_premium', 'premium_expires')
list_filter = ('active', 'is_premium', 'organization', 'country',)
ordering = ('-created_date',)
def member_count(self, team):
return team.members.all().count()
member_count.short_description = 'Members'
def event_count(self, team):
return team.event_set.all().count()
event_count.short_description = 'Events'
admin.site.register(Team, TeamAdmin)
class SearchableAdmin(admin.ModelAdmin):

View file

@ -0,0 +1,49 @@
# Generated by Django 2.0 on 2018-04-27 21:59
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0028_add_speaker_models'),
]
operations = [
migrations.AddField(
model_name='team',
name='is_premium',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='team',
name='premium_by',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='premium_teams', to='events.UserProfile'),
),
migrations.AddField(
model_name='team',
name='premium_expires',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='team',
name='premium_started',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name='presentation',
name='talk',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='presentations', to='events.Talk'),
),
migrations.AlterField(
model_name='speaker',
name='bio',
field=models.TextField(blank=True, verbose_name='Biography'),
),
migrations.AlterField(
model_name='talk',
name='speaker',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='talks', to='events.Speaker', verbose_name='Speaker Bio'),
),
]

View file

@ -224,6 +224,11 @@ class Team(models.Model):
category = models.ForeignKey('Category', on_delete=models.SET_NULL, blank=False, null=True)
topics = models.ManyToManyField('Topic', blank=True)
is_premium = models.BooleanField(default=False)
premium_by = models.ForeignKey(UserProfile, related_name='premium_teams', null=True, on_delete=models.SET_NULL)
premium_started = models.DateTimeField(blank=True, null=True)
premium_expires = models.DateTimeField(blank=True, null=True)
@property
def location_name(self):
if self.city:

View file

@ -147,6 +147,7 @@
</tr>
{% endif %}
{% if event.team.is_premium %}
<tr>
<td width="120px"><b>Presentations:</b></td>
<td>
@ -156,6 +157,7 @@
<a class="btn btn-primary btn-sm" href="{% url 'propose-event-talk' event.id %}">Propose a talk</a>
</td>
</tr>
{% endif %}
</table>
<div class="container mt-3">

View file

@ -209,6 +209,10 @@ def delete_talk(request, talk_id):
@login_required
def propose_event_talk(request, event_id):
event = get_object_or_404(Event, id=event_id)
if not event.team.is_premium:
messages.add_message(request, messages.ERROR, message=_("You can not propose a talk to this team's events."))
return redirect(event.get_absolute_url())
if request.method == 'GET':
profile = request.user.profile
talks = list(Talk.objects.filter(speaker__user=profile))