Skip to content

Instantly share code, notes, and snippets.

@musale
Created March 23, 2018 10:48
Show Gist options
  • Save musale/45c16c26088fa485f785297bf8e112dc to your computer and use it in GitHub Desktop.
Save musale/45c16c26088fa485f785297bf8e112dc to your computer and use it in GitHub Desktop.

Revisions

  1. musale created this gist Mar 23, 2018.
    6 changes: 6 additions & 0 deletions other_scripts.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # update the leave_duration function like this to return holidays and number_of_leave_days

    def leave_duration(date_from, date_to):
    with open('outfile', 'rb') as fp:
    holidays = pickle.load(fp)
    return number_of_holidays(holidays, date_from, date_to), holidays
    12 changes: 12 additions & 0 deletions template.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <-- All the other stuff !-->
    {% block content %}
    {% for holiday in holidays %}
    {{holiday.name}}
    // All the other properties here, styling etc
    {% empty %}
    <p> No holidays </p>
    {% endfor %}
    {% endblock %}
    <-- All the other stuff !-->
    // The part you are using obj is going to reference the model you've specified in the HolidayView class. You might want not
    // to do that if you're not interested in the model
    21 changes: 21 additions & 0 deletions views.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    class HolidayView(TemplateView):
    template_name = "weka jina"
    model = Holiday # Essentially, have the model here

    def get_context(self, **kwargs):
    context = super(HolidayView, self).get_context(**kwargs)

    # get the date_from and date_to from the request. depends with how you get the values. Bora zikuwe. If from request do this
    date_from = self.request.GET.get('date_from', None) # self.request.GET is the method loading this view. GET/POST
    date_to = self.request.GET.get('date_to', None)

    # get all the holidays and number of days
    number_of_leave_days, holidays = leave_duration(date_from, date_to)

    # inject holidays and number_of_leave_days into context
    context['number_of_leave_days'] = number_of_leave_days
    context['holidays'] = holidays

    # TODO: any other things you want in context add here
    return context