Skip to content

Commit

Permalink
fullCalendar's today should respect faked now.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhuang committed Jun 7, 2018
1 parent fb46ebf commit 1c6b4b3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
37 changes: 4 additions & 33 deletions course/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
import django.forms as forms

from relate.utils import (
StyledForm, as_local_time, format_datetime_local, string_concat, StyledModelForm)
StyledForm, as_local_time, format_datetime_local, string_concat,
StyledModelForm, ModalStyledFormMixin)

from course.views import get_now_or_fake_time
from course.constants import (
Expand All @@ -64,37 +65,6 @@
# }}}


class ModalStyledFormMixin(object):
ajax_modal_form_template = "modal-form.html"

@property
def form_title(self):
raise NotImplementedError()

@property
def modal_id(self):
raise NotImplementedError()

def get_ajax_form_helper(self):
# type: (...) -> FormHelper
return self.get_form_helper() # type: ignore

def render_ajax_modal_form_html(self, request, context=None):
# type: (http.HttpRequest, Optional[Dict]) -> Text

# remove possbily added buttons by non-AJAX form
self.helper.inputs = [] # type: ignore

from crispy_forms.utils import render_crispy_form
from django.template.context_processors import csrf
helper = self.get_ajax_form_helper()
helper.template = self.ajax_modal_form_template
if context is None:
context = {}
context.update(csrf(request))
return render_crispy_form(self, helper, context)


class ListTextWidget(forms.TextInput):
# Widget which allow free text and choices for CharField
def __init__(self, data_list, name, *args, **kwargs):
Expand Down Expand Up @@ -586,12 +556,13 @@ def view_calendar(pctx, mode=None):
raise PermissionDenied(_("may not edit calendar"))

now = get_now_or_fake_time(pctx.request)
default_date = now.date()
now_date = default_date = now.date()
if pctx.course.end_date is not None and default_date > pctx.course.end_date:
default_date = pctx.course.end_date

return render_course_page(pctx, "course/calendar.html", {
"is_edit_view": is_edit_view,
"now_date": now_date.isoformat(),
"default_date": default_date.isoformat(),

# Wrappers used by JavaScript template (tmpl) so as not to
Expand Down
1 change: 1 addition & 0 deletions course/templates/course/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ <h1>{{ course.number }} {% trans "Calendar" %}</h1>
},
contentHeight: "auto",
defaultDate: '{{ default_date }}',
now: '{{ now_date }}',
defaultView: $(window).width() < 765 ? 'listMonth': 'month',
timezone: "local",
nowIndicator: true,
Expand Down
12 changes: 10 additions & 2 deletions relate/templates/modal-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div class="modal fade" id="{{ form.modal_id}}" tabindex="-1" role="dialog"
aria-labelledby="{{ form.modal_id}}_label" aria-hidden="true">
<div class="modal-dialog modal-lg modal-sm"">
<div class="modal-dialog modal-lg modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
Expand All @@ -16,4 +16,12 @@ <h3 class="modal-title">{{ form.form_title}}</h3>
{% crispy form %}
</div>
</div>
</div>
</div>

{% if extra_js %}
<script>
(function() {
{{ extra_js |safe }}
})();
</script>
{% endif %}
31 changes: 31 additions & 0 deletions relate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,37 @@ class StyledModelForm(StyledFormMixin, forms.ModelForm):
pass


class ModalStyledFormMixin(object):
ajax_modal_form_template = "modal-form.html"

@property
def form_title(self):
raise NotImplementedError()

@property
def modal_id(self):
raise NotImplementedError()

def get_ajax_form_helper(self):
# type: (...) -> FormHelper
return self.get_form_helper() # type: ignore

def render_ajax_modal_form_html(self, request, context=None):
# type: (HttpRequest, Optional[Dict]) -> Text

# remove possbily added buttons by non-AJAX form
self.helper.inputs = [] # type: ignore

from crispy_forms.utils import render_crispy_form
from django.template.context_processors import csrf
helper = self.get_ajax_form_helper()
helper.template = self.ajax_modal_form_template
if context is None:
context = {}
context.update(csrf(request))
return render_crispy_form(self, helper, context)


# {{{ repo-ish types

class SubdirRepoWrapper(object):
Expand Down

0 comments on commit 1c6b4b3

Please sign in to comment.