diff --git a/events/admin.py b/events/admin.py index ce32236..7bd6586 100644 --- a/events/admin.py +++ b/events/admin.py @@ -6,7 +6,6 @@ from .models.locale import Language, Continent, Country, SPR, City from .models.profiles import UserProfile, Organization, Team, Member, Category, Topic from .models.search import Searchable from .models.events import Place, Event, EventPhoto, CommonEvent, Attendee -from .models.events import Place, Event, CommonEvent, Attendee admin.site.register(Language) admin.site.register(Continent) diff --git a/events/forms.py b/events/forms.py index 90010be..e5476b8 100644 --- a/events/forms.py +++ b/events/forms.py @@ -5,7 +5,7 @@ from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User from .models.profiles import Team, UserProfile -from .models.events import Event, Place, EventPhoto +from .models.events import Event, CommonEvent, Place, EventPhoto from datetime import time from time import strptime, strftime @@ -245,3 +245,33 @@ class SearchForm(forms.Form): widgets ={ 'city': Lookup(source='/api/cities/', label='name'), } + +class NewCommonEventForm(forms.ModelForm): + class Meta: + model = CommonEvent + fields = [ + 'name', + 'start_time', + 'end_time', + 'summary', + + 'country', + 'spr', + 'city', + 'place', + + 'web_url', + 'announce_url', + + 'category', + 'tags', + ] + widgets ={ + 'country': Lookup(source='/api/countries/', label='name'), + 'spr': Lookup(source='/api/spr/', label='name'), + 'city': Lookup(source='/api/cities/', label='name'), + 'place': Lookup(source='/api/places/', label='name'), + 'start_time': DateTimeWidget, + 'end_time': DateTimeWidget + } + diff --git a/events/migrations/0017_add_common_events.py b/events/migrations/0018_add_common_events.py similarity index 88% rename from events/migrations/0017_add_common_events.py rename to events/migrations/0018_add_common_events.py index 38c3818..1bd9bb4 100644 --- a/events/migrations/0017_add_common_events.py +++ b/events/migrations/0018_add_common_events.py @@ -1,14 +1,15 @@ -# Generated by Django 2.0 on 2018-03-12 18:57 +# Generated by Django 2.0 on 2018-03-21 01:13 import datetime from django.db import migrations, models import django.db.models.deletion +import imagekit.models.fields class Migration(migrations.Migration): dependencies = [ - ('events', '0016_make_searchable_uri_unique'), + ('events', '0017_add_event_images'), ] operations = [ @@ -34,6 +35,11 @@ class Migration(migrations.Migration): name='owner_profile', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='owned_orgs', to='events.UserProfile'), ), + migrations.AlterField( + model_name='eventphoto', + name='src', + field=models.ImageField(upload_to='event_photos', verbose_name='Photo'), + ), migrations.AlterField( model_name='team', name='organization', @@ -44,6 +50,11 @@ class Migration(migrations.Migration): name='owner_profile', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='owned_teams', to='events.UserProfile'), ), + migrations.AlterField( + model_name='userprofile', + name='avatar', + field=imagekit.models.fields.ProcessedImageField(blank=True, upload_to='avatars', verbose_name='Photo Image'), + ), migrations.AddField( model_name='commonevent', name='created_by', diff --git a/events/migrations/0019_add_org_slug.py b/events/migrations/0019_add_org_slug.py new file mode 100644 index 0000000..6502ddc --- /dev/null +++ b/events/migrations/0019_add_org_slug.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0 on 2018-03-22 03:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0018_add_common_events'), + ] + + operations = [ + migrations.AddField( + model_name='organization', + name='slug', + field=models.CharField(default='slug_required', max_length=256), + preserve_default=False, + ), + ] diff --git a/events/models/events.py b/events/models/events.py index 307a781..9ac8093 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -222,8 +222,17 @@ class CommonEvent(models.Model): topics = models.ManyToManyField('Topic', blank=True) tags = models.CharField(verbose_name=_("Keyword Tags"), blank=True, null=True, max_length=128) + def get_absolute_url(self): + return reverse('show-common-event', kwargs={'event_id': self.id, 'event_slug': self.slug}) + + def get_full_url(self): + site = self.organization.site + return "https://%s%s" % (site.domain, self.get_absolute_url()) + + @property + def slug(self): + return slugify(self.name) + def __str__(self): return self.name - ->>>>>>> Add CommonEvent model diff --git a/events/models/profiles.py b/events/models/profiles.py index 8a350a4..eac4f02 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -107,6 +107,18 @@ class UserProfile(models.Model): return True return False + def can_create_common_event(self, org): + try: + if self.user.is_superuser: + return True + except: + return False + if not self.user_id: + return False + if org.owner_profile == self: + return True + return False + def can_edit_team(self, team): try: if self.user.is_superuser: @@ -154,6 +166,7 @@ AnonymousUser.profile = property(_getAnonProfile) class Organization(models.Model): name = models.CharField(max_length=256, null=False, blank=False) + slug = models.CharField(max_length=256, null=False, blank=False) site = models.ForeignKey(Site, on_delete=models.CASCADE) owner_profile = models.ForeignKey(UserProfile, related_name='owned_orgs', blank=False, null=True, on_delete=models.SET_NULL) diff --git a/get_together/templates/get_together/base.html b/get_together/templates/get_together/base.html index 511d9e3..688bd1d 100644 --- a/get_together/templates/get_together/base.html +++ b/get_together/templates/get_together/base.html @@ -124,7 +124,7 @@ form { {% load flatpages %} {% get_flatpages as flatpages %} -