-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display Ongoing Events on the Events Page #2167
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -93,6 +93,16 @@ def for_datetime(self, dt=None): | |||||||||||||
dt = convert_dt_to_aware(dt) | ||||||||||||||
return self.filter(Q(occurring_rule__dt_start__gt=dt) | Q(recurring_rules__finish__gt=dt)) | ||||||||||||||
|
||||||||||||||
def ongoing_datetime(self, dt=None): | ||||||||||||||
if dt is None: | ||||||||||||||
dt = timezone.now() | ||||||||||||||
else: | ||||||||||||||
dt = convert_dt_to_aware(dt) | ||||||||||||||
return self.filter( | ||||||||||||||
(Q(occurring_rule__dt_start__lt=dt) & Q(occurring_rule__dt_end__gt=dt)) | ||||||||||||||
| (Q(recurring_rules__begin__lt=dt) & Q(recurring_rules__finish__gt=dt)) | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
def until_datetime(self, dt=None): | ||||||||||||||
if dt is None: | ||||||||||||||
dt = timezone.now() | ||||||||||||||
|
@@ -181,6 +191,39 @@ def next_time(self): | |||||||||||||
except IndexError: | ||||||||||||||
return None | ||||||||||||||
|
||||||||||||||
@property | ||||||||||||||
def present_time(self): | ||||||||||||||
""" | ||||||||||||||
Return the OccurringRule or RecurringRule that are ongoing now. | ||||||||||||||
""" | ||||||||||||||
now = timezone.now() | ||||||||||||||
recurring_start = occurring_start = None | ||||||||||||||
|
||||||||||||||
try: | ||||||||||||||
occurring_rule = self.occurring_rule | ||||||||||||||
except OccurringRule.DoesNotExist: | ||||||||||||||
pass | ||||||||||||||
else: | ||||||||||||||
if occurring_rule and occurring_rule.dt_start < now and occurring_rule.dt_end > now: | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
occurring_start = (occurring_rule.dt_start, occurring_rule) | ||||||||||||||
|
||||||||||||||
rrules = self.recurring_rules.filter(begin__lt=now, finish__gt=now) | ||||||||||||||
recurring_starts = [(rule.dt_start, rule) for rule in rrules if rule.dt_start is not None] | ||||||||||||||
recurring_starts.sort(key=itemgetter(0)) | ||||||||||||||
|
||||||||||||||
try: | ||||||||||||||
recurring_start = recurring_starts[0] | ||||||||||||||
except IndexError: | ||||||||||||||
pass | ||||||||||||||
Comment on lines
+214
to
+217
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
starts = [i for i in (recurring_start, occurring_start) if i is not None] | ||||||||||||||
starts.sort(key=itemgetter(0)) | ||||||||||||||
|
||||||||||||||
try: | ||||||||||||||
return starts[0][1] | ||||||||||||||
except IndexError: | ||||||||||||||
return None | ||||||||||||||
|
||||||||||||||
@property | ||||||||||||||
def previous_time(self): | ||||||||||||||
now = timezone.now() | ||||||||||||||
|
@@ -216,7 +259,7 @@ def next_or_previous_time(self): | |||||||||||||
|
||||||||||||||
@property | ||||||||||||||
def is_past(self): | ||||||||||||||
return self.next_time is None | ||||||||||||||
return self.next_time is None and self.present_time is None | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class RuleMixin: | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -57,6 +57,26 @@ <h3 class="event-title"><a href="{{ object.get_absolute_url }}">{{ object.title| | |||||
</ul> | ||||||
</div> | ||||||
|
||||||
{% if events_ongoing %} | ||||||
<h3 class="widget-title">Ongoing Events</h3> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I feel like this is "cooler" but just a nit :) |
||||||
<ul class="list-recent-events menu"> | ||||||
{% for object in events_ongoing %} | ||||||
<li> | ||||||
<h3 class="event-title"><a href="{{ object.get_absolute_url }}">{{ object.title|striptags }}</a></h3> | ||||||
<p> | ||||||
{% with object.current_time as next_time %} | ||||||
{% include "events/includes/time_tag.html" %} | ||||||
{% endwith %} | ||||||
|
||||||
{% if object.venue %} | ||||||
<span class="event-location">{% if object.venue.url %}<a href="{{ object.venue.url }}">{% endif %}{{ object.venue.name }}{% if object.venue.url %}</a>{% endif %}{% if object.venue.address %}, {{ object.venue.address }}{% endif %}</span> | ||||||
{% endif %} | ||||||
</p> | ||||||
</li> | ||||||
{% endfor %} | ||||||
</ul> | ||||||
{% endif %} | ||||||
|
||||||
{% if events_today %} | ||||||
<h3 class="widget-title just-missed">You just missed...</h3> | ||||||
<ul class="list-recent-events menu"> | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.