Example #1
0
def _return_to_editindex(request):
    # If the user has set the 'popup' preference, then close the popup
    # and reload the page that opened the popup. Otherwise just redirect to
    # the index.

    prefs = edit_prefs.get_preferences(request.session)
    # (nb: the pref is stored as 'true'/'false', not a python bool!)
    if prefs['popups'] == 'true':
        # Use a really, really dirty way to emulate the original functionality
        # and close the popped up window: return a hard-coded page that
        # contains javascript to close the open window and reload the source
        # page.
        return HttpResponse("<!DOCTYPE html><html>"
                            "<head><title>-</title></head>"
                            "<body onload='"
                            # Close if in a popup window:
                            "try{self.close();}catch(e){}"
                            # Close if in a fancybox:
                            "try{parent.$.fancybox.close();}catch(e){}"
                            # If there's an opener, make it reload to show
                            # edits:
                            "try{opener.location.reload(true);}catch(e){}"
                            "'>Ok</body>"
                            "</html>")
    else:
        # Redirect to edit index
        return HttpResponseRedirect(reverse("default-edit"))
Example #2
0
def _return_to_editindex(request):
    # If the user has set the 'popup' preference, then close the popup
    # and reload the page that opened the popup. Otherwise just redirect to
    # the index.

    prefs = edit_prefs.get_preferences(request.session)
    # (nb: the pref is stored as 'true'/'false', not a python bool!)
    if prefs['popups'] == 'true':
        # Use a really, really dirty way to emulate the original functionality
        # and close the popped up window: return a hard-coded page that
        # contains javascript to close the open window and reload the source
        # page.
        return HttpResponse(
            "<!DOCTYPE html><html>"
            "<head><title>-</title></head>"
            "<body onload='"
            # Close if in a popup window:
            "try{self.close();}catch(e){}"
            # Close if in a fancybox:
            "try{parent.$.fancybox.close();}catch(e){}"
            # If there's an opener, make it reload to show
            # edits:
            "try{opener.location.reload(true);}catch(e){}"
            "'>Ok</body>"
            "</html>")
    else:
        # Redirect to edit index
        return HttpResponseRedirect(reverse("default-edit"))
Example #3
0
def set_edit_preferences(request):
    # Store user preferences as specified in the request's GET variables,
    # and return a JSON object containing all current user preferences

    # Store updated prefs
    edit_prefs.set_preferences(request.session, request.GET)
    # Retrieve and return prefs:
    prefs = edit_prefs.get_preferences(request.session)
    return HttpResponse(json.dumps(prefs), mimetype="application/json")
Example #4
0
def set_edit_preferences(request):
    # Store user preferences as specified in the request's GET variables,
    # and return a JSON object containing all current user preferences

    # Store updated prefs
    edit_prefs.set_preferences(request.session, request.GET)
    # Retrieve and return prefs:
    prefs = edit_prefs.get_preferences(request.session)
    return HttpResponse(json.dumps(prefs), content_type="application/json")
Example #5
0
def edit_diary_list(request, year=None, day=None, month=None):
    # Basic "edit" list view. Logic about processing of year/month/day
    # parameters is basically the same as for the public diary view.
    #
    # The logic is a bit twisty, from the requirement to show list all dates
    # and 'ideas' fields in the range, even if they don't have any events in
    # them, yet.

    context = {}
    # Sort out date range to display

    # If the query contained the number of days ahead to show then retrieve it
    # and store it as the default for this session (so coming back to the page
    # will look the same)
    query_days_ahead = request.GET.get('daysahead', None)

    if query_days_ahead:
        edit_prefs.set_preference(request.session, 'daysahead',
                                  query_days_ahead)
        default_days_ahead = query_days_ahead
    else:
        default_days_ahead = int(
            edit_prefs.get_preference(request.session, 'daysahead'))

    # utility function, shared with public diary view
    startdatetime, days_ahead = get_date_range(
        year, month, day, query_days_ahead, default_days_ahead)
    startdate = startdatetime.date()
    if startdatetime is None:
        raise Http404(days_ahead)

    # Don't allow viewing of dates before today, to avoid editing of the past:
    local_now = timezone.localtime(timezone.now())
    if startdate < local_now.date():
        # Redirect to page with today as the start date:
        new_url = u"{0}?daysahead={1}".format(
            reverse(
                'day-edit',
                kwargs={
                    'year': local_now.year,
                    'month': local_now.month,
                    'day': local_now.day
                }), days_ahead)
        return HttpResponseRedirect(new_url)

    enddatetime = startdatetime + datetime.timedelta(days=days_ahead)

    # Get all showings in the date range
    showings = (Showing.objects.start_in_range(
        startdatetime, enddatetime).order_by('start').select_related())
    # Build two dicts, to hold the showings and the ideas. These dicts are
    # initially empty, and get filled in if there are actually showings or
    # ideas for those dates.
    # This is done so that if dates don't have ideas/showings they still get
    # shown in the list
    dates = OrderedDict()
    ideas = {startdate: ''}  # Actually, I lied: start of visible list is not
    # neccesarily the 1st of the month, so make sure
    # that it gets an 'IDEAS' link shown
    for days in xrange(days_ahead):
        # Iterate through every date in the visible range, creating a dict
        # entry for each
        day_in_range = startdatetime + datetime.timedelta(days=days)
        dates[day_in_range.date()] = []
        # If it's the 1st of the month, make sure there's an ideas entry
        if day_in_range.day == 1:
            ideas[day_in_range.date()] = ''
    # Now insert all the showings into the 'dates' dict
    for showing in showings:
        dates[showing.start.date()].append(showing)
    # Dates without a showing will still be in the dates dict, so will still
    # be shown

    # Now get all 'ideas' in date range. Fiddle the date range to be from the
    # start of the month in startdate, so the idea for that month gets
    # included:
    idea_startdate = datetime.date(
        day=1, month=startdate.month, year=startdate.year)
    idea_list = (DiaryIdea.objects.filter(
        month__range=[idea_startdate, enddatetime]).order_by('month').
                 select_related())
    # Assemble into the idea dict, with keys that will match the keys in the
    # showings dict
    for idea in idea_list:
        ideas[idea.month] = idea.ideas
    # Fiddle so that the idea for the first month is displayed, even if
    # startdate is after the first day of the month:
    if (idea_startdate not in showings and len(idea_list) > 0
            and idea_list[0].month.month == startdate.month):
        ideas[startdate] = idea_list[0].ideas

    context['ideas'] = ideas
    context['dates'] = dates
    # Page title:
    context['event_list_name'] = u"Diary for {0} to {1}".format(
        startdatetime.strftime("%d-%m-%Y"), enddatetime.strftime("%d-%m-%Y"))
    context['start'] = startdatetime
    context['end'] = enddatetime
    context['edit_prefs'] = edit_prefs.get_preferences(request.session)
    return render(request, 'edit_event_index.html', context)
Example #6
0
def edit_diary_list(request, year=None, day=None, month=None):
    # Basic "edit" list view. Logic about processing of year/month/day
    # parameters is basically the same as for the public diary view.
    #
    # The logic is a bit twisty, from the requirement to show list all dates
    # and 'ideas' fields in the range, even if they don't have any events in
    # them, yet.

    context = {}
    # Sort out date range to display

    # If the query contained the number of days ahead to show then retrieve it
    # and store it as the default for this session (so coming back to the page
    # will look the same)
    query_days_ahead = request.GET.get('daysahead', None)

    if query_days_ahead:
        edit_prefs.set_preference(request.session, 'daysahead',
                                  query_days_ahead)
        default_days_ahead = query_days_ahead
    else:
        default_days_ahead = int(
            edit_prefs.get_preference(request.session, 'daysahead'))

    # utility function, shared with public diary view
    startdatetime, days_ahead = get_date_range(year, month, day,
                                               query_days_ahead,
                                               default_days_ahead)
    startdate = startdatetime.date()
    if startdatetime is None:
        raise Http404(days_ahead)

    # Don't allow viewing of dates before today, to avoid editing of the past:
    local_now = timezone.localtime(timezone.now())
    if startdate < local_now.date():
        # Redirect to page with today as the start date:
        new_url = u"{0}?daysahead={1}".format(
            reverse('day-edit',
                    kwargs={
                        'year': local_now.year,
                        'month': local_now.month,
                        'day': local_now.day
                    }), days_ahead)
        return HttpResponseRedirect(new_url)

    enddatetime = startdatetime + datetime.timedelta(days=days_ahead)

    # Get all showings in the date range
    showings = (Showing.objects.start_in_range(
        startdatetime, enddatetime).order_by('start').select_related())
    # Build two dicts, to hold the showings and the ideas. These dicts are
    # initially empty, and get filled in if there are actually showings or
    # ideas for those dates.
    # This is done so that if dates don't have ideas/showings they still get
    # shown in the list
    dates = OrderedDict()
    # Actually, I lied: start of visible list is not necessarily the 1st of the
    # month, so make sure that it gets an 'IDEAS' link shown:
    ideas = {startdate: ''}
    for days in six.moves.range(days_ahead):
        # Iterate through every date in the visible range, creating a dict
        # entry for each
        day_in_range = startdatetime + datetime.timedelta(days=days)
        dates[day_in_range.date()] = []
        # If it's the 1st of the month, make sure there's an ideas entry
        if day_in_range.day == 1:
            ideas[day_in_range.date()] = ''
    # Now insert all the showings into the 'dates' dict
    for showing in showings:
        dates[timezone.localtime(showing.start).date()].append(showing)
    # Dates without a showing will still be in the dates dict, so will still
    # be shown

    # Now get all 'ideas' in date range. Fiddle the date range to be from the
    # start of the month in startdate, so the idea for that month gets
    # included:
    idea_startdate = datetime.date(day=1,
                                   month=startdate.month,
                                   year=startdate.year)
    idea_list = (DiaryIdea.objects.filter(
        month__range=[idea_startdate, enddatetime]).order_by(
            'month').select_related())
    # Assemble into the idea dict, with keys that will match the keys in the
    # showings dict
    for idea in idea_list:
        ideas[idea.month] = idea.ideas
    # Fiddle so that the idea for the first month is displayed, even if
    # startdate is after the first day of the month:
    if (idea_startdate not in showings and len(idea_list) > 0
            and idea_list[0].month.month == startdate.month):
        ideas[startdate] = idea_list[0].ideas

    context['ideas'] = ideas
    context['dates'] = dates
    # Page title:
    context['event_list_name'] = u"Diary for {0} to {1}".format(
        startdatetime.strftime("%d-%m-%Y"), enddatetime.strftime("%d-%m-%Y"))
    context['start'] = startdatetime
    context['end'] = enddatetime
    context['edit_prefs'] = edit_prefs.get_preferences(request.session)
    context['rooms'] = ([None] + list(Room.objects.all())
                        if settings.MULTIROOM_ENABLED else [None])
    context['multiroom_enabled'] = settings.MULTIROOM_ENABLED
    return render(request, 'edit_event_index.html', context)