Clean up events handling - clearly it wasn't even remotely ready.

This commit is contained in:
Magnus Hagander
2010-01-14 21:38:10 +01:00
parent f3bdf383e0
commit f1fd62c0c8
8 changed files with 86 additions and 23 deletions

View File

@ -2,6 +2,10 @@ from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponse, Http404
from django.template import TemplateDoesNotExist, loader, Context
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from django.db import connection
from datetime import date
from pgweb.util.decorators import ssl_required
from pgweb.util.contexts import NavContext
@ -22,16 +26,24 @@ from forms import OrganisationForm
# Front page view
def home(request):
news = NewsArticle.objects.filter(approved=True)[:3]
events = Event.objects.select_related('country').filter(approved=True).filter(training=False)[:3]
news = NewsArticle.objects.filter(approved=True)[:5]
events = Event.objects.select_related('country').filter(approved=True, training=False, enddate__gt=date.today).order_by('startdate')[:3]
quote = Quote.objects.filter(approved=True).order_by('?')[0]
versions = Version.objects.all()
planet = ImportedRSSItem.objects.filter(feed__internalname="planet").order_by("-posttime")[:5]
traininginfo = Event.objects.filter(approved=True, training=True).extra(where=("startdate <= (CURRENT_DATE + '6 Months'::interval) AND enddate >= CURRENT_DATE",)).aggregate(Count('id'), Count('country', distinct=True))
# can't figure out how to make django do this
curs = connection.cursor()
curs.execute("SELECT * FROM (SELECT DISTINCT(org) FROM events_event WHERE startdate <= (CURRENT_DATE + '6 Months'::interval) AND enddate >= CURRENT_DATE AND approved AND training AND org IS NOT NULL AND NOT org='') x ORDER BY random() LIMIT 3")
trainingcompanies = [r[0] for r in curs.fetchall()]
return render_to_response('index.html', {
'title': 'The world\'s most advanced open source database',
'news': news,
'events': events,
'traininginfo': traininginfo,
'trainingcompanies': trainingcompanies,
'quote': quote,
'versions': versions,
'planet': planet,

View File

@ -1,4 +1,11 @@
from util.admin import register_markdown
from django.contrib import admin
from util.admin import register_markdown, MarkdownPreviewAdmin
from models import *
register_markdown(Event)
class EventAdmin(MarkdownPreviewAdmin):
list_display = ('title', 'org', 'startdate', 'training', 'approved',)
list_filter = ('approved','training',)
search_fields = ('org', 'summary', 'details', 'title', )
admin.site.register(Event, EventAdmin)

View File

@ -23,11 +23,17 @@ class Event(models.Model, PgModel):
details = models.TextField(blank=False, null=False)
send_notification = True
markdown_fields = ('summary', 'details', )
markdown_fields = ('details', )
def __unicode__(self):
return "%s: %s" % (self.startdate, self.title)
@property
def has_submitter(self):
# If submitter is 0 it means migrated, so have no submitter
if self.submitter_id == 0: return False
return True
@property
def displaydate(self):
if self.startdate == self.enddate:
@ -41,5 +47,5 @@ class Event(models.Model, PgModel):
return "%s, %s" % (self.city, self.country)
class Meta:
ordering = ('startdate',)
ordering = ('-startdate','-enddate',)

View File

@ -13,9 +13,13 @@ from models import Event
from forms import EventForm
def archive(request, paging=None):
event = Event.objects.filter(approved=True).filter(enddate__gt=date.today)
events = Event.objects.select_related('country').filter(approved=True).filter(training=False, enddate__gt=date.today).order_by('startdate', 'enddate',)
training = Event.objects.select_related('country').filter(approved=True).filter(training=True, enddate__gt=date.today).order_by('startdate', 'enddate',)
return render_to_response('events/archive.html', {
'events': event,
'eventblocks': (
{ 'name': 'Events', 'events': events, },
{ 'name': 'Training', 'events': training, },
),
}, NavContext(request, 'about'))
def item(request, itemid, throwaway=None):

View File

@ -1,11 +1,24 @@
{%extends "base/page.html"%}
{%block title%}Event archive{%endblock%}
{%block contents%}
<h1>Event archive</h1>
{%for obj in events %}
<h2><a href="/about/event/{{obj.id}}/">{{obj.title}}</a></h2>
{%include "events/inc_event.html"%}
{%for eventblock in eventblocks%}
<h1><a name="{{eventblock.name}}">{{eventblock.name}}</a></h1>
<p>
<i><b>Note:</b> The PostgreSQL Global Development Group does not endorse any
events run by third parties. No guarantee of the quality of events is offered
whatsoever.</i>
</p>
{%for event in eventblock.events %}
<div><a href="/about/event/{{event.id}}/">{{event.title}}</a></div>
<div>Date: <b>{{event.displaydate|safe}}</b></div>
<div>Location: <b>{{event.locationstring}}</b></div>
<p>
{{event.summary}}
</p>
{%endfor%}
{%endfor%}
<p><a href="/account/events/new/">Submit event</a></p>
{%endblock%}

View File

@ -1,6 +0,0 @@
{%load markup%}
<div class="eventdate">Posted on <b>{{obj.date}}</b></div>
<p>
{{obj.content|markdown:"safe"}}
</p>

View File

@ -1,6 +1,21 @@
{%extends "base/page.html"%}
{%load markup%}
{%block contents%}
<h1>{{obj.title}}</h1>
{%include "events/inc_event.html"%}
<div class="eventdate">Posted on <b>{{obj.displaydate|safe}}</b></div>
<div>Location: {{obj.locationstring}}</div>
<p>
{{obj.details|markdown:"safe"}}
</p>
{%if obj.has_submitter%}
<p>Posted by {{obj.submitter.email}}.</p>
{%else%}
<p><i>This event has been migrated from a previous version of the PostgreSQL
website. We apologise for any formatting issues caused by the migration.</i></p>
{%endif%}
<p>
<i><b>Note:</b> The PostgreSQL Global Development Group does not endorse any
events run by third parties. No guarantee of the quality of events is offered
whatsoever.</i>
</p>
{%endblock%}

View File

@ -155,9 +155,21 @@
</a>
<div class="pgNewsEventsWrap">
<div id="pgFrontTrainingSummary">
Include Dave's magic training blurb here later!
<!-- INCLUDE about/training-summary.html -->
</div>
{%if traininginfo.id__count %}
There are {{traininginfo.id__count}} training events in {{traininginfo.country__count}} countries
scheduled over the next six months from
{%if trainingcompanies|length_is:"1"%}{{trainingcompanies|first}}.
{%else%}
{%if trainingcompanies|length_is:"2"%}{{trainingcompanies|join:" and "}}.
{%else%}
{{trainingcompanies|slice:":2"|join:", "}} and others.
{%endif%}
{%endif%}
<p>Take a look at our <a href="/about/eventarchive/#Training">schedule</a> to find the training that you want.</p>
{%else%}
There are no training events currently scheduled.
{%endif%}
</div>
<div>
<img class="pgArrowImage" src="/layout/images/blt_blu_arrow.png" width="6" height="5" alt="" />
<ul class="pgRSSBottomList">