Ticket #10890: week_pagination2.diff
File week_pagination2.diff, 2.2 KB (added by , 14 years ago) |
---|
-
django/views/generic/date_based.py
183 183 Context: 184 184 week: 185 185 (date) this week 186 next_week: 187 (dict) with three keys: 188 'date' (date): the first day of the next week 189 'year' (int): the year of first day of the next week 190 'week' (int): the week number of the first day of the next week 191 or None if the next week is in the future 192 previous_week: 193 (dict) with three keys: 194 'date' (date): the first day of the previous week 195 'year' (int): the year of first day of the previous week 196 'week' (int): the week number of the first day of the previous week 186 197 object_list: 187 198 list of objects published in the given week 188 199 """ … … 208 219 if last_day >= now.date() and not allow_future: 209 220 lookup_kwargs['%s__lte' % date_field] = now 210 221 object_list = queryset.filter(**lookup_kwargs) 222 223 # Calculate the next week, if applicable. 224 if allow_future: 225 next_week = { 226 'year': last_day.year, 227 'week': last_day.strftime('%U'), 228 'date': last_day 229 } 230 elif last_day < datetime.date.today(): 231 next_week = { 232 'year': last_day.year, 233 'week': last_day.strftime('%U'), 234 'date': last_day 235 } 236 else: 237 next_week = None 238 239 # Calculate the previous week 240 previous_week_dt = first_day - datetime.timedelta(days=7) 241 previous_week = { 242 'year': previous_week_dt.year, 243 'week': previous_week_dt.strftime('%U'), 244 'date': previous_week_dt 245 } 246 211 247 if not object_list and not allow_empty: 212 248 raise Http404 213 249 if not template_name: … … 216 252 c = RequestContext(request, { 217 253 '%s_list' % template_object_name: object_list, 218 254 'week': date, 255 'previous_week': previous_week, 256 'next_week': next_week, 219 257 }) 220 258 for key, value in extra_context.items(): 221 259 if callable(value):