diff --git a/events/forms.py b/events/forms.py index 736abfd..fcd3405 100644 --- a/events/forms.py +++ b/events/forms.py @@ -371,6 +371,15 @@ class SearchForm(forms.Form): 'city': Lookup(source=City, label='name'), } +class OrganizationForm(forms.ModelForm): + class Meta: + model = Team + fields = [ + 'name', + 'description', + 'cover_img', + ] + class NewCommonEventForm(forms.ModelForm): class Meta: model = CommonEvent @@ -380,6 +389,7 @@ class NewCommonEventForm(forms.ModelForm): 'end_time', 'summary', + 'continent', 'country', 'spr', 'city', @@ -388,8 +398,6 @@ class NewCommonEventForm(forms.ModelForm): 'web_url', 'announce_url', - 'category', - 'tags', ] widgets ={ 'country': Lookup(source=Country, label='name'), diff --git a/events/migrations/0037_add_org_details.py b/events/migrations/0037_add_org_details.py new file mode 100644 index 0000000..73c96e9 --- /dev/null +++ b/events/migrations/0037_add_org_details.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0 on 2018-07-29 01:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0036_auto_20180701_2148'), + ] + + operations = [ + migrations.AddField( + model_name='organization', + name='cover_img', + field=models.ImageField(blank=True, null=True, upload_to='org_covers', verbose_name='Cover Image'), + ), + migrations.AddField( + model_name='organization', + name='description', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/events/migrations/0038_add_common_event_continent.py b/events/migrations/0038_add_common_event_continent.py new file mode 100644 index 0000000..328530f --- /dev/null +++ b/events/migrations/0038_add_common_event_continent.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0 on 2018-07-29 01:48 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0037_add_org_details'), + ] + + operations = [ + migrations.AddField( + model_name='commonevent', + name='continent', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='events.Continent'), + ), + ] diff --git a/events/models/events.py b/events/models/events.py index 7f9e98b..b0a6223 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -313,6 +313,7 @@ class CommonEvent(models.Model): end_time = models.DateTimeField(help_text=_('Date and time that the event ends'), verbose_name=_('End Time'), db_index=True) summary = models.TextField(help_text=_('Summary of the Event'), blank=True, null=True) + continent = models.ForeignKey(Continent, null=True, blank=True, on_delete=models.SET_NULL) country = models.ForeignKey(Country, null=True, blank=True, on_delete=models.SET_NULL) spr = models.ForeignKey(SPR, null=True, blank=True, on_delete=models.SET_NULL) city = models.ForeignKey(City, null=True, blank=True, on_delete=models.SET_NULL) @@ -339,6 +340,17 @@ class CommonEvent(models.Model): schema = 'https' return "%s://%s%s" % (schema, site.domain, self.get_absolute_url()) + def location(self): + if not self.continent: + return _('Global') + elif not self.country: + return self.continent + elif not self.spr: + return self.country + elif not self.city: + return self.spr + else: + return self.city @property def slug(self): return slugify(self.name) diff --git a/events/models/profiles.py b/events/models/profiles.py index a17dfd5..b7e5e76 100644 --- a/events/models/profiles.py +++ b/events/models/profiles.py @@ -132,6 +132,18 @@ class UserProfile(models.Model): return True return False + def can_edit_org(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_create_common_event(self, org): try: if self.user.is_superuser: @@ -196,6 +208,35 @@ class Organization(models.Model): owner_profile = models.ForeignKey(UserProfile, related_name='owned_orgs', blank=False, null=True, on_delete=models.SET_NULL) + cover_img = models.ImageField(verbose_name=_('Cover Image'), upload_to='org_covers', null=True, blank=True) + tile_img = ImageSpecField(source='cover_img', + processors=[ + Adjust(contrast=0.8, color=1), + ResizeToFill(338, 200), + ], + format='PNG') + + banner_img = ImageSpecField(source='cover_img', + processors=[ + Adjust(contrast=0.8, color=1), + ResizeToFill(825, 200), + ], + format='PNG') + + description = models.TextField(blank=True, null=True) + + def save(self, *args, **kwargs): + new_slug = slugify(self.name) + slug_matches = list(Organization.objects.filter(slug=new_slug)) + if len(slug_matches) == 0 or (len(slug_matches) == 1 and slug_matches[0].id == self.id): + self.slug = new_slug + else: + self.slug = '%s-%s' % (new_slug, self.id) + super().save(*args, **kwargs) # Call the "real" save() method. + + def get_absolute_url(self): + return reverse('show-org', kwargs={'org_slug': self.slug}) + def __str__(self): return u'%s' % (self.name) diff --git a/events/templates/events/org_form.html b/events/templates/events/org_form.html new file mode 100644 index 0000000..50dc771 --- /dev/null +++ b/events/templates/events/org_form.html @@ -0,0 +1,3 @@ +
Organized by {{ common_event.organization.name }}
{{ common_event.summary|markdown }}
+Organized by {{ common_event.organization.name }}
+ {% if common_event.summary %} +{{ common_event.summary|markdown }}
+ {% endif %} +Time: | {{ common_event.start_time }} - {{ common_event.end_time }} | +Date: | {{ common_event.start_time }} - {{ common_event.end_time }} |
Category: | {{ common_event.category.name }} | +Location: | {{ common_event.location }} |
{{ org.description|markdown }}