Python django.conf.settings.DATE_FORMAT Examples

The following are 12 code examples for showing how to use django.conf.settings.DATE_FORMAT(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .

Example 1
def format_as_response(self, *args):
        unknown = {'course_id': None, 'count': 0, 'date': None,
                   'country': {'alpha2': None, 'alpha3': None, 'name': country.UNKNOWN_COUNTRY_CODE}}

        for arg in args:
            if arg.country.name == country.UNKNOWN_COUNTRY_CODE:
                unknown['course_id'] = arg.course_id
                unknown['date'] = arg.date.strftime(settings.DATE_FORMAT)
                unknown['count'] += arg.count
                unknown['created'] = arg.created.strftime(settings.DATETIME_FORMAT)

        args = [arg for arg in args if arg.country != country.UNKNOWN_COUNTRY]
        args = sorted(args, key=lambda item: (item.date, item.course_id, item.country.alpha3))

        response = [unknown]
        response += [
            {'course_id': six.text_type(ce.course_id), 'count': ce.count,
             'date': ce.date.strftime(settings.DATE_FORMAT),
             'country': {'alpha2': ce.country.alpha2, 'alpha3': ce.country.alpha3, 'name': ce.country.name},
             'created': ce.created.strftime(settings.DATETIME_FORMAT)} for ce in args
        ]

        return response 
Example 2
Project: coursys   Author: sfu-fas   File: other.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _to_text(self, fieldsubmission=None, format=settings.DATE_FORMAT):
        if fieldsubmission.data['info']:
            d = datetime.datetime.strptime(fieldsubmission.data['info'], '%Y-%m-%d').date()
            return escape(defaultfilters.date(d, format))
        else:
            return 'not entered' 
Example 3
Project: GTDWeb   Author: lanbing510   File: defaultfilters.py    License: GNU General Public License v2.0 5 votes vote down vote up
def date(value, arg=None):
    """Formats a date according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = settings.DATE_FORMAT
    try:
        return formats.date_format(value, arg)
    except AttributeError:
        try:
            return format(value, arg)
        except AttributeError:
            return '' 
Example 4
Project: luscan-devel   Author: blackye   File: defaultfilters.py    License: GNU General Public License v2.0 5 votes vote down vote up
def date(value, arg=None):
    """Formats a date according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = settings.DATE_FORMAT
    try:
        return formats.date_format(value, arg)
    except AttributeError:
        try:
            return format(value, arg)
        except AttributeError:
            return '' 
Example 5
Project: openhgsenti   Author: drexly   File: defaultfilters.py    License: Apache License 2.0 5 votes vote down vote up
def date(value, arg=None):
    """Formats a date according to the given format."""
    if value in (None, ''):
        return ''
    if arg is None:
        arg = settings.DATE_FORMAT
    try:
        return formats.date_format(value, arg)
    except AttributeError:
        try:
            return format(value, arg)
        except AttributeError:
            return '' 
Example 6
def format_last_updated_date_and_time(d):
        return {'update_date': dateformat.format(d, settings.DATE_FORMAT),
                'update_time': dateformat.format(d, settings.TIME_FORMAT)} 
Example 7
def parse_date(self, date, timezone):
        if date:
            try:
                date = datetime.datetime.strptime(date, settings.DATETIME_FORMAT)
            except ValueError:
                date = datetime.datetime.strptime(date, settings.DATE_FORMAT)
            date = make_aware(date, timezone)
        return date 
Example 8
def assertIntervalFilteringWorks(self, expected_response, course_id, start_date, end_date):
        # If start date is after date of existing data, return a 404
        date = (start_date + datetime.timedelta(days=30)).strftime(settings.DATETIME_FORMAT)
        response = self.authenticated_get(
            '%scourses/%s%s?start_date=%s' % (self.api_root_path, course_id, self.path, date))
        self.assertEqual(response.status_code, 404)

        # If end date is before date of existing data, return a 404
        date = (start_date - datetime.timedelta(days=30)).strftime(settings.DATETIME_FORMAT)
        response = self.authenticated_get(
            '%scourses/%s%s?end_date=%s' % (self.api_root_path, course_id, self.path, date))
        self.assertEqual(response.status_code, 404)

        # If data falls in date range, data should be returned
        start = start_date.strftime(settings.DATETIME_FORMAT)
        end = end_date.strftime(settings.DATETIME_FORMAT)
        response = self.authenticated_get('%scourses/%s%s?start_date=%s&end_date=%s' % (
            self.api_root_path, course_id, self.path, start, end))
        self.assertEqual(response.status_code, 200)
        self.assertListEqual(response.data, expected_response)

        # Passing dates in DATE_FORMAT still works
        start = start_date.strftime(settings.DATE_FORMAT)
        end = end_date.strftime(settings.DATE_FORMAT)
        response = self.authenticated_get('%scourses/%s%s?start_date=%s&end_date=%s' % (
            self.api_root_path, course_id, self.path, start, end))
        self.assertEqual(response.status_code, 200)
        self.assertListEqual(response.data, expected_response)


# pylint: disable=abstract-method 
Example 9
def format_as_response(self, *args):
        return [
            {'course_id': six.text_type(ce.course_id), 'count': ce.count,
             'date': ce.date.strftime(settings.DATE_FORMAT), 'birth_year': ce.birth_year,
             'created': ce.created.strftime(settings.DATETIME_FORMAT)} for ce in args
        ] 
Example 10
def format_as_response(self, *args):
        return [
            {'course_id': six.text_type(ce.course_id), 'count': ce.count,
             'date': ce.date.strftime(settings.DATE_FORMAT), 'education_level': ce.education_level,
             'created': ce.created.strftime(settings.DATETIME_FORMAT)} for ce in args
        ] 
Example 11
def serialize_enrollment(self, enrollment):
        return {
            'created': enrollment.created.strftime(settings.DATETIME_FORMAT),
            'course_id': six.text_type(enrollment.course_id),
            'date': enrollment.date.strftime(settings.DATE_FORMAT),
            enrollment.cleaned_gender: enrollment.count
        } 
Example 12
def serialize_enrollment(self, enrollment):
        return {
            u'course_id': enrollment.course_id,
            u'date': enrollment.date.strftime(settings.DATE_FORMAT),
            u'created': enrollment.created.strftime(settings.DATETIME_FORMAT),
            enrollment.mode: enrollment.count
        }