Created
March 23, 2018 10:48
-
-
Save musale/45c16c26088fa485f785297bf8e112dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<-- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment