diff --git a/events/admin.py b/events/admin.py index 2cdada2..f97ff2d 100644 --- a/events/admin.py +++ b/events/admin.py @@ -68,9 +68,10 @@ admin.site.register(Sponsor, SponsorAdmin) class TeamAdmin(admin.ModelAdmin): 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)) + list_display = ('__str__', 'active', 'member_count', 'event_count', 'owner_profile', 'created_date', 'access', 'is_premium') + list_filter = ('active', 'access', 'is_premium', 'organization', ('country',admin.RelatedOnlyFieldListFilter)) ordering = ('-created_date',) + def member_count(self, team): return team.members.all().count() member_count.short_description = 'Members' diff --git a/events/forms.py b/events/forms.py index f4b5fee..0ce9d33 100644 --- a/events/forms.py +++ b/events/forms.py @@ -270,6 +270,41 @@ class NewTeamEventForm(forms.ModelForm): cleaned_data['end_time'] = pytz.utc.localize(timezone.make_naive(event_tz.localize(timezone.make_naive(cleaned_data['end_time'])))) return cleaned_data + +class NewEventForm(forms.ModelForm): + + class Meta: + model = Event + fields = ['name', 'start_time', 'end_time'] + widgets = { + 'start_time': DateTimeWidget, + 'end_time': DateTimeWidget + } + + def __init__(self, *args, **kargs): + super().__init__(*args, **kargs) + event_tz = pytz.timezone(self.instance.tz) + if self.instance.local_start_time: self.initial['start_time'] = self.instance.local_start_time + if self.instance.local_end_time: self.initial['end_time'] = self.instance.local_end_time + print("Initial: %s" % self.initial) + + def clean(self): + cleaned_data = super().clean() + event_tz = pytz.timezone(self.instance.tz) + print("Clean: %s" % cleaned_data) + cleaned_data['start_time'] = pytz.utc.localize(timezone.make_naive(event_tz.localize(timezone.make_naive(cleaned_data['start_time'])))) + cleaned_data['end_time'] = pytz.utc.localize(timezone.make_naive(event_tz.localize(timezone.make_naive(cleaned_data['end_time'])))) + return cleaned_data + + +class NewEventDetailsForm(forms.ModelForm): + recurrences = recurrence.forms.RecurrenceField(label="Repeat", required=False) + + class Meta: + model = Event + fields = ['summary', 'recurrences', 'web_url', 'announce_url'] + + class DeleteEventForm(forms.Form): confirm = forms.BooleanField(label="Yes, delete event", required=True) diff --git a/events/migrations/0041_add_private_personal_team_types.py b/events/migrations/0041_add_private_personal_team_types.py new file mode 100644 index 0000000..0aafec4 --- /dev/null +++ b/events/migrations/0041_add_private_personal_team_types.py @@ -0,0 +1,24 @@ +# Generated by Django 2.0 on 2018-08-11 17:08 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0040_add_org_membership_requests'), + ] + + operations = [ + migrations.AddField( + model_name='team', + name='access', + field=models.SmallIntegerField(choices=[(0, 'Public'), (1, 'Personal'), (2, 'Private')], default=0, verbose_name='Access'), + ), + migrations.AlterField( + model_name='orgteamrequest', + name='requested_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='requested_org_memberships', to='events.UserProfile'), + ), + ] diff --git a/events/models/profiles.py b/events/models/profiles.py index d57b407..f2e87d8 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -57,6 +57,14 @@ class UserProfile(models.Model): except: return "Unknown Profile" + @property + def personal_team(self): + teams = Team.objects.filter(access=Team.PERSONAL, owner_profile=self) + if teams.count() > 0: + return teams[0] + else: + return Team.objects.create(name=str(self), access=Team.PERSONAL, owner_profile=self, city=self.city) + def avatar_url(self): try: if self.avatar is None or self.avatar.name is None: @@ -86,19 +94,19 @@ class UserProfile(models.Model): @property def is_a_team_admin(self): - return Member.objects.filter(user=self, role=Member.ADMIN).count() > 0 + return Member.objects.filter(user=self, role=Member.ADMIN, team__access__in=(Team.PUBLIC, Team.PRIVATE)).count() > 0 @property def administering(self): - return [member.team for member in Member.objects.filter(user=self, role=Member.ADMIN).order_by('team__name')] + return [member.team for member in Member.objects.filter(user=self, role=Member.ADMIN, team__access__in=(Team.PUBLIC, Team.PRIVATE)).order_by('team__name')] @property def is_a_team_moderator(self): - return Member.objects.filter(user=self, role__in=(Member.ADMIN, Member.MODERATOR)).count() > 0 + return Member.objects.filter(user=self, role__in=(Member.ADMIN, Member.MODERATOR), team__access__in=(Team.PUBLIC, Team.PRIVATE)).count() > 0 @property def moderating(self): - return [member.team for member in Member.objects.filter(user=self, role__in=(Member.ADMIN, Member.MODERATOR)).order_by('team__name')] + return [member.team for member in Member.objects.filter(user=self, role__in=(Member.ADMIN, Member.MODERATOR), team__access__in=(Team.PUBLIC, Team.PRIVATE)).order_by('team__name')] def can_create_event(self, team): try: @@ -299,10 +307,24 @@ class SponsorSerializer(serializers.ModelSerializer): 'web_url', ) + +class PublicTeamsManager(models.Manager): + def get_queryset(self): + return super().get_queryset().filter(access=Team.PUBLIC) + class Team(models.Model): + PUBLIC=0 + PERSONAL=1 + PRIVATE=2 + TYPES = [ + (PUBLIC, _("Public")), + (PERSONAL, _("Personal")), + (PRIVATE, _("Private")), + ] name = models.CharField(_("Team Name"), max_length=256, null=False, blank=False) 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) + access = models.SmallIntegerField(verbose_name=_("Access"), choices=TYPES, default=PUBLIC) cover_img = models.ImageField(verbose_name=_('Cover Image'), upload_to='team_covers', null=True, blank=True) tile_img = ImageSpecField(source='cover_img', @@ -352,6 +374,9 @@ class Team(models.Model): premium_started = models.DateTimeField(blank=True, null=True) premium_expires = models.DateTimeField(blank=True, null=True) + objects = models.Manager() + public_objects = PublicTeamsManager() + @property def card_img_url(self): if self.tile_img is not None and self.tile_img.name is not None: diff --git a/get_together/templates/get_together/base.html b/get_together/templates/get_together/base.html index 9f41928..4426aee 100644 --- a/get_together/templates/get_together/base.html +++ b/get_together/templates/get_together/base.html @@ -69,7 +69,7 @@