Improve organization display pages

This commit is contained in:
Michael Hall 2018-07-28 22:31:59 -04:00
parent 3ad259887a
commit 82a696261a
16 changed files with 308 additions and 93 deletions

View file

@ -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'),

View file

@ -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),
),
]

View file

@ -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'),
),
]

View file

@ -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)

View file

@ -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)

View file

@ -0,0 +1,3 @@
<table>
{{ org_form }}
</table>

View file

@ -31,6 +31,8 @@ $(document).ready(function(){
$("#id_end_time_0").datepicker();
$("#id_continent").selectmenu();
$("#country_select").lookup({
search: function(searchText, callback) {
if (searchText.length < 3) return callback(searchText, []);

View file

@ -0,0 +1,13 @@
{% extends "get_together/base.html" %}
{% load static %}
{% block content %}
<h2>Update {{org.name}}</h2>
<form action="{% url "edit-org" org.slug %}" enctype="multipart/form-data" method="post">
{% csrf_token %}
{% include "events/org_form.html" %}
<br />
<button type="submit" class="btn btn-primary">Save</button>
</form>
{% endblock %}

View file

@ -78,29 +78,45 @@
{% endif %}{% endblock %}
{% block content %}
<div class="fluid-container">
<div class="fluid-container container-primary">
<div class="row">
<div class="col-md-9">
<h2>{{ common_event.name }}
{% if can_edit_event %}
<a href="{% url 'edit-common-event' common_event.id %}" class="btn btn-secondary btn-sm">Edit</a>
{% endif %}
{% if can_edit_event %}
<a href="{% url 'edit-common-event' common_event.id %}" class="btn btn-secondary btn-sm">Edit</a>
{% endif %}
{% if common_event.organization.banner_img %}
<div class="team-banner mb-3">
<img class="card-img-top" src="{{ common_event.organization.banner_img.url }}" alt="{{common_event.organization.name}}'s cover image" height="200px" width="825px">
<h2 class="team-title">{{ common_event.name }}</h2>
</div>
{% else %}
<h2>{{ common_event.name }}</h2>
{% endif %}
<div class="mb-2">
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
<a href="https://twitter.com/intent/tweet?text=I'm+having+a+get+together!%0D{{common_event.name|urlencode}}&original_referer={{common_event.get_full_url|urlencode}}&url={{common_event.get_full_url|urlencode}}&hashtags=gettogether" data-size="large" class="btn btn-twitter btn-sm"><i class="fa fa-twitter"></i> Tweet</a>
{% endif %}
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}
<a href="#" onClick="shareFacebook();" class="btn btn-facebook btn-sm"><i class="fa fa-facebook-official"></i> Share</a>
{% endif %}
</h2><p class="text-muted">Organized by <a href="{% url "show-org" common_event.organization.slug %}">{{ common_event.organization.name }}</a></p><hr/>
</div>
<p>{{ common_event.summary|markdown }}</p>
<div class="container container-secondary mb-3">
<p class="text-muted">Organized by <a href="{% url "show-org" common_event.organization.slug %}">{{ common_event.organization.name }}</a></p>
{% if common_event.summary %}
<p>{{ common_event.summary|markdown }}</p>
{% endif %}
</div>
<div class="container container-secondary mb-3">
<table class="table">
<tr>
<td><b>Time:</b></td><td>{{ common_event.start_time }} - {{ common_event.end_time }}</td>
<td><b>Date:</b></td><td>{{ common_event.start_time }} - {{ common_event.end_time }}</td>
</tr>
<tr>
<td><b>Category:</b></td><td>{{ common_event.category.name }}</td>
<td><b>Location:</b></td><td>{{ common_event.location }}</td>
</tr>
{% if common_event.place %}
<tr>
@ -120,13 +136,14 @@
</tr>
{% endif %}
</table>
<br/>
<div class="container">
</div>
<div class="container container-secondary mb-3">
<div class="row">
<div class="col"><h4>Participating Teams</h4><hr/></div>
<div class="col"><h4>Participating Teams</h4></div>
</div>
<div class="row">
{% for event in common_event.participating_events.all %}
{% for event in participating_events %}
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<div class="card-banner">
@ -152,10 +169,9 @@
</div>
<div class="row">
<div class="col">
<br/><a href="{% url 'create-common-event-team-select' common_event.id %}" class="btn btn-success">Host an event</a>
<a href="{% url 'create-common-event-team-select' common_event.id %}" class="btn btn-success">Host an event</a>
</div>
</div>
<br />
</div>
</div>

View file

@ -18,25 +18,45 @@
{% endblock %}
{% block content %}
<div class="fluid-container">
<div class="fluid-container container-primary">
<div class="row">
<div class="col-sm-9">
<h2>Welcome to {{ org.name }}
</h2><hr/>
{% if can_edit_org %}
<div id="admin_buttons" class="mb-2">
<a href="{% url 'edit-org' org.slug %}" class="btn btn-secondary btn-sm"><i class="fa fa-pencil"></i> Edit Org</a>
<a href="#" class="btn btn-secondary btn-sm disabled"><i class="fa fa-users"></i> Manage Members</a>
</div>
{% endif %}
{% if org.banner_img %}
<div class="team-banner mb-3">
<img class="card-img-top" src="{{ org.banner_img.url }}" alt="{{org.name}}'s cover image" height="200px" width="825px">
<h2 class="team-title">Welcome to {{ org.name }}</h2>
</div>
{% else %}
<h2>Welcome to {{ org.name }}</h2>
{% endif %}
{% if org.description %}
<div class="container container-secondary mb-3">
<div class="row">
<div class="col-md-9"><p>{{ org.description|markdown }}</p></div>
</div>
</div>
{% endif %}
<div class="container container-secondary mb-3">
<h4>Upcoming Events</h4>
<div class="container">
{% for event in upcoming_events %}
<div class="row">
<div class="col"><a href="{{ event.get_absolute_url }}">{{event.name}}</a></div>
<div class="col">{{ event.place }}</div>
<div class="col">{{ event.location }}</div>
<div class="col">{{ event.start_time }}</div>
</div>
{% endfor %}
{% if can_create_event %}
<div class="row">
<div class="col">
<br/><a href="{% url 'create-common-event' org.slug %}" class="btn btn-primary">Plan a Get Together</a>
<br/><a href="{% url 'create-common-event' org.slug %}" class="btn btn-primary"><i class="fa fa-calendar-plus-o"></i> Create an Event</a>
</div>
</div>
{% endif %}
@ -44,12 +64,12 @@
<br/>
{% if recent_events %}
<div class="container container-secondary mb-3">
<h4>Recent Events</h4>
<div class="container">
{% for event in recent_events %}
<div class="row">
<div class="col"><a href="{{ event.get_absolute_url }}">{{event.name}}</a></div>
<div class="col">{{ event.place }}</div>
<div class="col">{{ event.location }}</div>
<div class="col">{{ event.start_time }}</div>
</div>
{% endfor %}
@ -59,8 +79,8 @@
</div>
<div class="col-sm-3">
<div class="container">
<h4>Members</h4><hr/>
<div class="container container-secondary">
<h4>Member Teams</h4><hr/>
{% for member in member_list %}
<div class="row mb-3">
<div class="col media gt-profile">

View file

@ -37,7 +37,7 @@
{% if can_create_event %}
<div class="row">
<div class="col">
<br/><a href="{% url 'create-event' team.id %}" class="btn btn-success"><i class="fa fa-calendar-plus-o"></i> Host a Get Together</a>
<br/><a href="{% url 'create-event' team.id %}" class="btn btn-primary"><i class="fa fa-calendar-plus-o"></i> Host a Get Together</a>
</div>
</div>
{% endif %}

View file

@ -100,6 +100,7 @@ urlpatterns = [
path('series/<int:series_id>/<str:series_slug>/', views.show_series, name='show-series'),
path('org/<str:org_slug>/', views.show_org, name='show-org'),
path('org/<str:org_slug>/+edit/', views.edit_org, name='edit-org'),
path('org/<str:org_slug>/+create-event/', views.create_common_event, name='create-common-event'),
path('common/<int:event_id>/+create-event/', views.create_common_event_team_select, name='create-common-event-team-select'),
path('common/<int:event_id>/<str:event_slug>/', views.show_common_event, name='show-common-event'),

View file

@ -24,6 +24,7 @@ import math
import traceback
from .teams import *
from .orgs import *
from .events import *
from .places import *
from .user import *

View file

@ -126,7 +126,7 @@ def create_event(request, team_id):
if request.method == 'GET':
if 'common' in request.GET and request.GET['common'] != '':
new_event.parent = CommonEvent.objects.get(id=request.GET['common'])
form = NewTeamEventForm(instance=new_event)
form = NewTeamEventForm(instance=new_event, initial={'name': new_event.parent.name, 'summary': new_event.parent.summary})
context = {
'event': new_event,
@ -832,54 +832,4 @@ def delete_series(request, series_id):
else:
return redirect('home')
def show_common_event(request, event_id, event_slug):
event = get_object_or_404(CommonEvent, id=event_id)
context = {
'org': event.organization,
'common_event': event,
'can_edit_event': False,
}
return render(request, 'get_together/orgs/show_common_event.html', context)
@login_required
def create_common_event(request, org_slug):
org = get_object_or_404(Organization, slug=org_slug)
if not request.user.profile.can_create_common_event(org):
messages.add_message(request, messages.WARNING, message=_('You can not create events for this org.'))
return redirect('show-org', org_id=org.pk)
new_event = CommonEvent(organization=org, created_by=request.user.profile)
if request.method == 'GET':
form = NewCommonEventForm(instance=new_event)
context = {
'org': org,
'event_form': form,
}
return render(request, 'get_together/orgs/create_common_event.html', context)
elif request.method == 'POST':
form = NewCommonEventForm(request.POST, instance=new_event)
if form.is_valid:
new_event = form.save()
return redirect('show-common-event', new_event.id, new_event.slug)
else:
context = {
'org': org,
'event_form': form,
}
return render(request, 'get_together/orgs/create_common_event.html', context)
else:
return redirect('home')
@login_required
def create_common_event_team_select(request, event_id):
teams = request.user.profile.moderating
if len(teams) == 1:
return redirect(reverse('create-event', kwargs={'team_id':teams[0].id}) + '?common=%s'%event_id)
context = {
'common_event_id': event_id,
'teams': teams
}
return render(request, 'get_together/orgs/create_common_event_team_select.html', context)

120
get_together/views/orgs.py Normal file
View file

@ -0,0 +1,120 @@
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from django.contrib.auth import logout as logout_user
from django.contrib.auth.decorators import login_required
from django.contrib.sites.models import Site
from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse, JsonResponse
from django.core.mail import send_mail
from django.template.loader import get_template, render_to_string
from django.conf import settings
from events.models.profiles import Organization, Team, UserProfile, Member
from events.models.events import Event, CommonEvent, Place, Attendee
from events.forms import OrganizationForm, NewCommonEventForm
from events import location
from events.utils import slugify
from accounts.models import EmailRecord
import datetime
import simplejson
# Create your views here.
def show_org(request, org_slug):
org = get_object_or_404(Organization, slug=org_slug)
upcoming_events = CommonEvent.objects.filter(organization=org, end_time__gt=datetime.datetime.now()).order_by('start_time')
recent_events = CommonEvent.objects.filter(organization=org, end_time__lte=datetime.datetime.now()).order_by('-start_time')[:5]
context = {
'org': org,
'upcoming_events': upcoming_events,
'recent_events': recent_events,
'member_list': Team.objects.filter(organization=org).order_by('name'),
'can_create_event': request.user.profile.can_create_common_event(org),
'can_edit_org': request.user.profile.can_edit_org(org),
}
return render(request, 'get_together/orgs/show_org.html', context)
@login_required
def edit_org(request, org_slug):
org = get_object_or_404(Organization, slug=org_slug)
if not request.user.profile.can_edit_org(org):
messages.add_message(request, messages.WARNING, message=_('You can not make changes to this organization.'))
return redirect('show-org', org_slug=org.slug)
if request.method == 'GET':
form = OrganizationForm(instance=org)
context = {
'org': org,
'org_form': form,
}
return render(request, 'get_together/orgs/edit_org.html', context)
elif request.method == 'POST':
form = OrganizationForm(request.POST, request.FILES, instance=org)
if form.is_valid():
form.save()
return redirect('show-org', org_slug=org.slug)
else:
context = {
'org': org,
'org_form': form,
}
return render(request, 'get_together/orgs/edit_org.html', context)
else:
return redirect('home')
def show_common_event(request, event_id, event_slug):
event = get_object_or_404(CommonEvent, id=event_id)
context = {
'org': event.organization,
'common_event': event,
'participating_events': event.participating_events.all().order_by('start_time'),
'can_edit_event': False,
}
return render(request, 'get_together/orgs/show_common_event.html', context)
@login_required
def create_common_event(request, org_slug):
org = get_object_or_404(Organization, slug=org_slug)
if not request.user.profile.can_create_common_event(org):
messages.add_message(request, messages.WARNING, message=_('You can not create events for this org.'))
return redirect('show-org', org_id=org.pk)
new_event = CommonEvent(organization=org, created_by=request.user.profile)
if request.method == 'GET':
form = NewCommonEventForm(instance=new_event)
context = {
'org': org,
'event_form': form,
}
return render(request, 'get_together/orgs/create_common_event.html', context)
elif request.method == 'POST':
form = NewCommonEventForm(request.POST, instance=new_event)
if form.is_valid:
new_event = form.save()
return redirect('show-common-event', new_event.id, new_event.slug)
else:
context = {
'org': org,
'event_form': form,
}
return render(request, 'get_together/orgs/create_common_event.html', context)
else:
return redirect('home')
@login_required
def create_common_event_team_select(request, event_id):
teams = request.user.profile.moderating
if len(teams) == 1:
return redirect(reverse('create-event', kwargs={'team_id':teams[0].id}) + '?common=%s'%event_id)
context = {
'common_event_id': event_id,
'teams': teams
}
return render(request, 'get_together/orgs/create_common_event_team_select.html', context)

View file

@ -335,17 +335,3 @@ def contact_member(member, body, sender):
ok=success
)
def show_org(request, org_slug):
org = get_object_or_404(Organization, slug=org_slug)
upcoming_events = CommonEvent.objects.filter(organization=org, end_time__gt=datetime.datetime.now()).order_by('start_time')
recent_events = CommonEvent.objects.filter(organization=org, end_time__lte=datetime.datetime.now()).order_by('-start_time')[:5]
context = {
'org': org,
'upcoming_events': upcoming_events,
'recent_events': recent_events,
'member_list': Team.objects.filter(organization=org).order_by('name'),
'can_create_event': request.user.profile.can_create_common_event(org),
}
return render(request, 'get_together/orgs/show_org.html', context)