def render_appointments_table(appointments): rows = [(_("Date"), _("Day"), _("Time"), _("Duration"))] current_timezone = timezone.get_current_timezone() for appointment in appointments: localized_start_date = current_timezone.normalize(appointment.start_date.astimezone(current_timezone)) rows.append( ( _date(localized_start_date, "SHORT_DATE_FORMAT"), _date(localized_start_date, "l"), _time(localized_start_date, "TIME_FORMAT"), str(appointment.duration) + " " + _("min."), ) ) return { "title": mark_safe('<span class="glyphicon glyphicon-calendar"></span> ' + _("Appointments")), "summary": _("Training appointment detail"), "singular": _("appointment"), "plural": _("appointments"), "headers": rows.pop(0), "rows": rows, "count": len(rows), }
def get_serialized_comment(comment): """ Get a dict of comment instance. :param comment: Comment instance. :return: a dict representation of a comment. """ return { 'pk': comment.pk, 'text': comment.text, 'author': comment.user.username, 'publication_date': _date(comment.publication_date), 'publication_time': _time(comment.publication_date), 'last_update_date': _date(comment.last_update), 'last_update_time': _time(comment.last_update), 'update_url': comment.update_url }
def get_historical_date_display(historical_date, precision): """ Formats a given date according to precision. :param historical_date: (datetime) historical date to format :param precision: (str) precision from DATETIME_PRECISION_CHOICES :return: (str) formatted date """ date_str = _date(historical_date, 'Y') if precision != DATETIME_PRECISION_YEAR: date_str = _date(historical_date, 'F').lower() + ' ' + date_str if precision != DATETIME_PRECISION_YEAR and precision != DATETIME_PRECISION_MONTH: date_str = _date(historical_date, 'j') + ' de ' + date_str if precision == DATETIME_PRECISION_HOUR: date_str = date_str + ', ' + _time(historical_date, 'g a') if precision == DATETIME_PRECISION_MINUTE: date_str = date_str + ', ' + _time(historical_date, 'g:i a') return date_str
def appointments(request: HttpRequest, event_id) -> JsonResponse: event = Event.objects.get(id__exact=event_id) apps = list(event.appointments.all()) apps_per_slot = defaultdict(list) for app in apps: apps_per_slot[_time(app.start_time)].append(app) return JsonResponse({ 'event': event, 'appointments': apps_per_slot }, encoder=EventAppointmentsEncoder, safe=False)
def timezone_update(request): """Update the timezone of request.user.""" user = request.user if request.method == 'POST': tz = request.POST.get('tz') user.profile.timezone = tz user.profile.save() now = timezone.now().astimezone(pytz.timezone(tz)) now = _date(now) + ' ' + _time(now) return HttpResponse(now) else: form = TimezoneForm(instance=user.profile) context = {'user': user, 'form': form} template = loader.get_template('league/timezone_update.html') return HttpResponse(template.render(context, request))
def latest_activity(self, obj): latest = obj.get_latest_comment() return "%s %s - %s" % (_date(latest.date), _time( latest.date), latest.author)
def latest_activity(self, obj): latest = obj.get_latest_comment() return "%s %s - %s" % (_date(latest.date), _time(latest.date), latest.author)