def items(self, obj): year = obj.h_year month = obj.h_month return models.timeline_histories( obj, None, None, None, None).filter(date__year=year, date__month=month).order_by("date")
def display_object_history(request, obj_type="-", obj_ref="-", obj_revi="-", timeline=False, template="history.html"): """ History view. This view displays a history of the selected object and its revisions. :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/history/` :url: :samp:`/user/{username}/history/` :url: :samp:`/group/{group_name}/history/` :url: :samp:`/timeline/` .. include:: views_params.txt **Template:** :file:`history.html` **Context:** ``RequestContext`` ``object_history`` list of :class:`.AbstractHistory` ``show_revisions`` True if the template should show the revision of each history row ``show_identifiers`` True if the template should show the type, reference and revision of each history row """ obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi) form_date = forms.HistoryDateForm(request.GET if request.GET else None) if form_date.is_valid(): date_begin = form_date.cleaned_data["date_history_begin"] number_days = form_date.cleaned_data["number_days"] done_by = form_date.cleaned_data["done_by"] else: done_by = "" if 'date_history_begin' in request.GET: if len(request.GET['date_history_begin']) == 10: date_begin = request.GET['date_history_begin'] date_begin = datetime.datetime(int(date_begin[:4]), int(date_begin[5:7]), int(date_begin[8:10])) else: date_begin = datetime.datetime.today() else: date_begin = datetime.datetime.today() number_days = 30 date_begin = from_current_timezone(date_begin) if date_begin > from_current_timezone(datetime.datetime.today()): date_begin = from_current_timezone(datetime.datetime.today()) date_end = date_begin - datetime.timedelta(days=int(number_days)) date_end = from_current_timezone(date_end) if timeline: # global timeline: shows objects owned by the company and readable objects ctx["timeline"] = True ctx['object_type'] = _("Timeline") form_object = forms.HistoryObjectForm( request.GET if request.GET else None) if form_object.is_valid(): display_part = form_object.cleaned_data["part"] display_document = form_object.cleaned_data["document"] display_group = form_object.cleaned_data["group"] else: display_part = True display_document = True display_group = True list_display = { "display_document": display_document, "display_part": display_part, "display_group": display_group } history = models.timeline_histories( obj, from_current_timezone(date_begin + datetime.timedelta(days=1)), date_end, done_by, list_display) ctx['form_object'] = form_object if display_document: display_document = 'on' if display_part: display_part = 'on' if display_group: display_group = 'on' ctx['display_document'] = display_document ctx['display_part'] = display_part ctx['display_group'] = display_group else: history = obj.histories history = history.filter( date__gte=date_end, date__lt=from_current_timezone(date_begin + datetime.timedelta(days=1))) if done_by != "": if models.User.objects.filter(username=done_by).exists(): history = history.filter(user__username=done_by) else: history = history.none() messages.error(request, "This user doesn't exist") elif hasattr(obj, "revision"): # display history of all revisions ctx["show_revisions"] = True else: ctx["show_revisions"] = False history = history.select_related("plmobject", "user__profile") date_after = from_current_timezone(date_begin + datetime.timedelta(days=1)) if date_after < from_current_timezone(datetime.datetime.today()): ctx['date_after'] = ( date_begin + datetime.timedelta(days=number_days + 1)).strftime('%Y-%m-%d') ctx.update({ 'date_before': (date_begin - datetime.timedelta(days=number_days + 1)).strftime('%Y-%m-%d'), 'form_date': form_date, 'date_begin_period': date_begin.strftime('%Y-%m-%d'), 'date_end_period': date_end.strftime('%Y-%m-%d'), "number_days": number_days, 'current_page': 'history', 'object_history': history, 'show_identifiers': timeline }) return r2r(template, ctx, request)
def items(self, obj): return timeline_histories(obj, None, None, None, None)[:10]
def items(self, obj): year = obj.h_year month = obj.h_month return models.timeline_histories(obj, None, None, None, None).filter(date__year=year, date__month=month).order_by("date")
def history_calendar(request, year=None, month=None, obj_type="-", obj_ref="-", obj_revi="-", timeline=False): """ Calendar view. This view displays a history of the selected object and its revisions. :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/history/calendar/[{year}/][{month}/]` :url: :samp:`/user/{username}/history/calendar/[{year}/][{month}/]`` :url: :samp:`/group/{group_name}/history/calendar/[{year}/][{month}/]`` :url: :samp:`/timeline/calendar/[{year}/][{month}/]`` .. include:: ../../modules/views_params.txt **Template:** :file:`calendar.html` **Context:** ``RequestContext`` ``calendar`` the HTML calendar ``year`` the given year (or the current year if not given) ``month`` the given month (or the current month if not given) ``current_month``, ``next_month``, ``previous_month`` :class:`.datetime.date` objects representing the current, next and previous months (may be None if the date is 1900/01 or 9999/12). ``ical_installed`` True if django-ical is installed and iCalendar file can be generated ``prefix_url`` a prefix to prepend to the url to go to the next and previous monthes. (can be ``""``, ``"../"`` or ``"../../"``). """ prefix = "" if year is not None: prefix = "../" if month is not None: prefix += "../" year, month = parse_date(year, month) obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi) if timeline: hcls = TimelineCalendar histories = models.timeline_histories(request.user, None, None, None, None) ctx['object_type'] = _("Timeline") elif hasattr(obj, "get_all_revisions"): # display history of all revisions histories = obj.histories hcls = RevisionHistoryCalendar else: histories = obj.histories hcls = HistoryCalendar histories = histories.filter(date__year=year, date__month=month).order_by("date") cal = hcls(histories).formatmonth(year, month) current_month = date(year=year, month=month, day=1) if month == 1: if year == MINYEAR: previous_month = None else: previous_month = date(year=year - 1, month=12, day=1) else: previous_month = date(year=year, month=month - 1, day=1) if month == 12: if year == MAXYEAR: next_month = None else: next_month = date(year=year + 1, month=1, day=1) elif month == 11 and year == MAXYEAR: next_month = None else: next_month = date(year=year, month=month + 1, day=1) ctx.update({ 'current_page' : 'history', 'calendar' : mark_safe(cal), 'year' : year, 'month' : month, 'current_month' : current_month, 'next_month' : next_month, 'previous_month' : previous_month, 'prefix_url' : prefix, 'ical_installed' : ICAL_INSTALLED, }) return r2r('calendar.html', ctx, request)
def history_calendar(request, year=None, month=None, obj_type="-", obj_ref="-", obj_revi="-", timeline=False): """ Calendar view. This view displays a history of the selected object and its revisions. :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/history/calendar/[{year}/][{month}/]` :url: :samp:`/user/{username}/history/calendar/[{year}/][{month}/]`` :url: :samp:`/group/{group_name}/history/calendar/[{year}/][{month}/]`` :url: :samp:`/timeline/calendar/[{year}/][{month}/]`` .. include:: ../../modules/views_params.txt **Template:** :file:`calendar.html` **Context:** ``RequestContext`` ``calendar`` the HTML calendar ``year`` the given year (or the current year if not given) ``month`` the given month (or the current month if not given) ``current_month``, ``next_month``, ``previous_month`` :class:`.datetime.date` objects representing the current, next and previous months (may be None if the date is 1900/01 or 9999/12). ``ical_installed`` True if django-ical is installed and iCalendar file can be generated ``prefix_url`` a prefix to prepend to the url to go to the next and previous monthes. (can be ``""``, ``"../"`` or ``"../../"``). """ prefix = "" if year is not None: prefix = "../" if month is not None: prefix += "../" year, month = parse_date(year, month) obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi) if timeline: hcls = TimelineCalendar histories = models.timeline_histories(request.user, None, None, None, None) ctx['object_type'] = _("Timeline") elif hasattr(obj, "get_all_revisions"): # display history of all revisions histories = obj.histories hcls = RevisionHistoryCalendar else: histories = obj.histories hcls = HistoryCalendar histories = histories.filter(date__year=year, date__month=month).order_by("date") cal = hcls(histories).formatmonth(year, month) current_month = date(year=year, month=month, day=1) if month == 1: if year == MINYEAR: previous_month = None else: previous_month = date(year=year - 1, month=12, day=1) else: previous_month = date(year=year, month=month - 1, day=1) if month == 12: if year == MAXYEAR: next_month = None else: next_month = date(year=year + 1, month=1, day=1) elif month == 11 and year == MAXYEAR: next_month = None else: next_month = date(year=year, month=month + 1, day=1) ctx.update({ 'current_page': 'history', 'calendar': mark_safe(cal), 'year': year, 'month': month, 'current_month': current_month, 'next_month': next_month, 'previous_month': previous_month, 'prefix_url': prefix, 'ical_installed': ICAL_INSTALLED, }) return r2r('calendar.html', ctx, request)
def display_object_history(request, obj_type="-", obj_ref="-", obj_revi="-", timeline=False, template="history.html"): """ History view. This view displays a history of the selected object and its revisions. :url: :samp:`/object/{obj_type}/{obj_ref}/{obj_revi}/history/` :url: :samp:`/user/{username}/history/` :url: :samp:`/group/{group_name}/history/` :url: :samp:`/timeline/` .. include:: views_params.txt **Template:** :file:`history.html` **Context:** ``RequestContext`` ``object_history`` list of :class:`.AbstractHistory` ``show_revisions`` True if the template should show the revision of each history row ``show_identifiers`` True if the template should show the type, reference and revision of each history row """ obj, ctx = get_generic_data(request, obj_type, obj_ref, obj_revi) form_date = forms.HistoryDateForm(request.GET if request.GET else None) if form_date.is_valid(): date_begin = form_date.cleaned_data["date_history_begin"] number_days = form_date.cleaned_data["number_days"] done_by = form_date.cleaned_data["done_by"] else: done_by = "" if 'date_history_begin' in request.GET: if len(request.GET['date_history_begin']) == 10 : date_begin = request.GET['date_history_begin'] date_begin = datetime.datetime(int(date_begin[:4]), int(date_begin[5:7]), int(date_begin[8:10])) else: date_begin = datetime.datetime.today() else : date_begin = datetime.datetime.today() number_days = 30 date_begin = from_current_timezone(date_begin) if date_begin > from_current_timezone(datetime.datetime.today()): date_begin = from_current_timezone(datetime.datetime.today()) date_end = date_begin - datetime.timedelta(days = int(number_days)) date_end = from_current_timezone(date_end) if timeline: # global timeline: shows objects owned by the company and readable objects ctx["timeline"] = True ctx['object_type'] = _("Timeline") form_object = forms.HistoryObjectForm(request.GET if request.GET else None) if form_object.is_valid(): display_part = form_object.cleaned_data["part"] display_document = form_object.cleaned_data["document"] display_group = form_object.cleaned_data["group"] else: display_part = True display_document = True display_group = True list_display = {"display_document": display_document, "display_part": display_part, "display_group" : display_group} history = models.timeline_histories(obj, from_current_timezone(date_begin + datetime.timedelta(days = 1)), date_end, done_by, list_display) ctx['form_object'] = form_object if display_document: display_document = 'on' if display_part: display_part = 'on' if display_group: display_group = 'on' ctx['display_document'] = display_document ctx['display_part'] = display_part ctx['display_group'] = display_group else: history = obj.histories history = history.filter(date__gte = date_end, date__lt = from_current_timezone(date_begin + datetime.timedelta(days = 1))) if done_by != "": if models.User.objects.filter(username= done_by).exists(): history = history.filter(user__username = done_by) else: history = history.none() messages.error(request, "This user doesn't exist") elif hasattr(obj, "revision"): # display history of all revisions ctx["show_revisions"] = True else: ctx["show_revisions"] = False history = history.select_related("plmobject", "user__profile") date_after = from_current_timezone(date_begin + datetime.timedelta(days = 1)) if date_after < from_current_timezone(datetime.datetime.today()): ctx['date_after'] = (date_begin + datetime.timedelta(days = number_days +1)).strftime('%Y-%m-%d') ctx.update({ 'date_before' : (date_begin - datetime.timedelta(days = number_days +1)).strftime('%Y-%m-%d'), 'form_date': form_date, 'date_begin_period' : date_begin.strftime('%Y-%m-%d'), 'date_end_period':date_end.strftime('%Y-%m-%d'), "number_days" : number_days, 'current_page' : 'history', 'object_history' : history, 'show_identifiers' : timeline }) return r2r(template, ctx, request)