Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
pURLs to Occurrences are now supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Turner committed Nov 9, 2011
1 parent a66e89a commit cba491a
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 39 deletions.
9 changes: 6 additions & 3 deletions eventtools/models/occurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ def status_message(self):
return "This session is fully booked."

return None

def get_absolute_url(self):
return reverse('events:occurrence', kwargs={'event_slug': self.event.slug, 'occurrence_pk': self.pk })


# ical is coming back soon.
# def get_absolute_url(self):
# return self.event.get_absolute_url()
#
#
# def _resolve_attr(self, attr):
# v = getattr(self, attr, None)
# if v is not None:
Expand Down
59 changes: 37 additions & 22 deletions eventtools/static/eventtools/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@
// make calendars scrollable
var $el = $(".calendarlist .scrollable")
$el.scrollable();

// if the current month is in the list of scrollable items, scroll to it.

var api = $el.data("scrollable");
var today = new Date()
function pad(n){return n<10 ? '0'+n : n}
var month_str = today.getUTCFullYear()+'-'
+ pad(today.getUTCMonth()+1);

var offset = 0;
api.getItems().each(function() {
var $this = $(this);
if ($this.attr("data") == month_str) {
api.move(offset, 0)
return false
}
offset += 1;
});

var month_str;
// if there is a selected day, scroll to it
var date = $(".calendar td.highlight.selected").attr('data');
if (date) {
month_str = date.substr(0, 7);
} else {
// elif the current month is in the list of scrollable items, scroll to it.
var today = new Date()
function pad(n){return n<10 ? '0'+n : n}
month_str = today.getUTCFullYear()+'-'
+ pad(today.getUTCMonth()+1);
}

if (month_str) {
var offset = 0;
api.getItems().each(function() {
var $this = $(this);
if ($this.attr("data") == month_str) {
api.move(offset, 0);
return false;
}
offset += 1;
});
};

var days_count = $("#sessions dt").size();

Expand All @@ -34,9 +44,8 @@

// Make highlighted dates look clickable
$(".calendar td.highlight").css("cursor", "pointer");

// Show session data when we click on a date
$(".calendar td.highlight").click(function() {

var highlight_click = function(event) {
var $this = $(this);
$(".calendar td.highlight").removeClass("clicked");
$this.addClass("clicked");
Expand All @@ -45,9 +54,15 @@
$("#sessions dd").hide();
// show only the sessions with the data
$("#sessions [data=\""+$this.attr('data')+"\"]").fadeIn(400);

});
} // endif

};
// Show session data when we click on a date
$(".calendar td.highlight").click(highlight_click);

// By default, highlight the initially selected date
$(".calendar td.highlight.selected").each(highlight_click);

} // endif
});

})(jQuery);
2 changes: 1 addition & 1 deletion eventtools/templates/eventtools/_occurrence_in_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<p class="status">{{ occurrence.status_message }}</p>
{% endif %}
{% endif %}
<h3><a href="{{ event.get_absolute_url }}" class="summary">{{ event.title }}</a></h3>
<h3><a href="{{ occurrence.get_absolute_url }}" class="summary">{{ event.title }}</a></h3>
</span>
{% endwith %}
10 changes: 9 additions & 1 deletion eventtools/templates/eventtools/_occurrences_in_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
{% for day in day_list %}
<dt data="{{ day.grouper|date:"Y-m-d" }}" class="hide">{{ day.grouper|date:"l, j F Y" }}</dt>
{% for occurrence in day.list %}
<dd data="{{ day.grouper|date:"Y-m-d" }}" class="hide">{{ occurrence.html_time_description }}{% if occurrence.event != event %}: <a href="{{ occurrence.event.get_absolute_url }}">{{ occurrence.event }}</a>{% endif %} {% if occurrence.status_message %}&ndash; {{ occurrence.status_message }}{% endif %}</dd>
<dd data="{{ day.grouper|date:"Y-m-d" }}" class="hide">
<a href="{{ occurrence.get_absolute_url }}">{{ occurrence.html_time_description }}</a>:
{% if occurrence.event != event %}
<a href="{{ occurrence.event.get_absolute_url }}">{{ occurrence.event }}</a>
{% else %}
{{ occurrence.event }}
{% endif %}

{% if occurrence.status_message %}({{ occurrence.status_message }}){% endif %}</dd>
{% endfor %}
{% endfor %}
</dl>
20 changes: 13 additions & 7 deletions eventtools/templates/eventtools/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
{% with listed_under=event.listed_under %}
<h1>{{ event.title }}</h1>
{% if perms.events.can_change_event %}<p><a href="{% url admin:events_event_change event.pk %}">edit</a></p>{% endif %}

{% if occurrence %}
<p class="status">{{ occurrence.start_date|date:"l, j F Y" }}, {{ occurrence.html_time_description }}{% if occurrence.status_message %} ({{ occurrence.status_message }}){% endif %} - <a href="{{ occurrence.event.get_absolute_url }}">view all sessions</a> </p>
{% else %}
{% if listed_under.unavailable_status_message %}
<p class="status">
{{ listed_under.unavailable_status_message }}
</p>
{% endif %}
{% endif %}

{% if listed_under != event %}
<p><cite>{{ event.title }}</cite> {% if event.is_finished %}was{% else %}is{% endif %} one of the <a href="{{ listed_under.get_absolute_url }}">{{ listed_under.title }}</a> sessions.</p>
{% endif %}

{% if event.sessions %}<p class="season">When: {{ event.sessions|linebreaksbr }}<p>{% endif %}

<h2>Sessions</h2>
<h2>{% if occurrence %}Other sessions{% else %}Sessions{% endif %}</h2>

{% if listed_under.unavailable_status_message %}
<p class="status">
{{ listed_under.unavailable_status_message }}
</p>
{% endif %}

{% nav_calendars event.occurrences_in_listing %}
{% nav_calendars event.occurrences_in_listing occurrence %}

{% with event.occurrences_in_listing.all as occurrences %}
{% if occurrences %}
Expand Down
10 changes: 7 additions & 3 deletions eventtools/templatetags/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def nav_calendar(
)

def nav_calendars(
context, occurrence_qs=[],
context, occurrence_qs=[], selected_occurrence=None,
date_href_fn=None,
date_class_fn=None,
):
Expand All @@ -219,8 +219,12 @@ def nav_calendars(
#TODO: allow dates, not just occurrence_qs
if date_class_fn is None and occurrence_qs:
occurrence_days = [o.start.date() for o in occurrence_qs]
date_class_fn = DATE_CLASS_HIGHLIGHT_FACTORY(occurrence_days, None)

if selected_occurrence:
date_class_fn = DATE_CLASS_HIGHLIGHT_FACTORY(occurrence_days, selected_occurrence.start.date())
else:
date_class_fn = DATE_CLASS_HIGHLIGHT_FACTORY(occurrence_days, None)


calendars = []
if occurrence_qs.count() > 0:
first_date = occurrence_qs[0].start.date()
Expand Down
22 changes: 20 additions & 2 deletions eventtools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def urls(self):
url(r'^$', self.index, name='index'),
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', self.on_date, name='on_date'),
url(r'^(?P<event_slug>[-\w]+)/$', self.event, name='event'),

url(r'^(?P<event_slug>[-\w]+)/(?P<occurrence_pk>[\d]+)/$', self.occurrence, name='occurrence'),

#ical - needs rethinking
# url(r'^ical\.ics$', self.occurrence_list_ical, name='occurrence_list_ical'),
# url(r'^(?P<event_slug>[-\w]+)/ical\.ics$', self.event_ical, name='event_ical'),
Expand All @@ -56,7 +57,24 @@ def event(self, request, event_slug):
context['event'] = event

return render_to_response('eventtools/event.html', context)


def occurrence(self, request, event_slug, occurrence_pk):
"""
Returns a page similar to eventtools/event.html, but for a specific occurrence.
event_slug is ignored, since occurrences may move from event to sub-event, and
it would be nice if URLs continued to work.
"""

occurrence = get_object_or_404(self.occurrence_qs, pk=occurrence_pk)
event = occurrence.event
context = RequestContext(request)
context['occurrence'] = occurrence
context['event'] = event

return render_to_response('eventtools/event.html', context)


# def event_ical(self, request, event_slug):
# event_context = self._event_context(request, event_slug)
# return response_as_ical(request, event_context['occurrence_pool'])
Expand Down

0 comments on commit cba491a

Please sign in to comment.