Ticket #16906: 16906.patch

File 16906.patch, 7.4 KB (added by Aymeric Augustin, 13 years ago)
  • django/db/models/fields/__init__.py

     
    1616from django.utils.text import capfirst
    1717from django.utils.translation import ugettext_lazy as _
    1818from django.utils.encoding import smart_unicode, force_unicode, smart_str
    19 from django.utils import datetime_safe
    2019from django.utils.ipv6 import clean_ipv6_address
    2120
    2221class NOT_PROVIDED:
     
    669668        if val is None:
    670669            data = ''
    671670        else:
    672             data = datetime_safe.new_date(val).strftime("%Y-%m-%d")
     671            data = str(val)
    673672        return data
    674673
    675674    def formfield(self, **kwargs):
     
    743742        if val is None:
    744743            data = ''
    745744        else:
    746             d = datetime_safe.new_datetime(val)
    747             data = d.strftime('%Y-%m-%d %H:%M:%S')
     745            data = str(val.replace(microsecond=0, tzinfo=None))
    748746        return data
    749747
    750748    def formfield(self, **kwargs):
  • django/db/backends/sqlite3/base.py

     
    320320            dt = dt - delta
    321321    except (ValueError, TypeError):
    322322        return None
     323    # typecast_timestamp returns a date or a datetime without timezone.
     324    # It will be formatted as "%Y-%m-%d" or "%Y-%m-%d %H:%M:%S[.%f]"
     325    return str(dt)
    323326
    324     if isinstance(dt, datetime.datetime):
    325         rv = dt.strftime("%Y-%m-%d %H:%M:%S")
    326         if dt.microsecond:
    327             rv = "%s.%0.6d" % (rv, dt.microsecond)
    328     else:
    329         rv = dt.strftime("%Y-%m-%d")
    330     return rv
    331 
    332327def _sqlite_regexp(re_pattern, re_string):
    333328    try:
    334329        return bool(re.search(re_pattern, re_string))
  • django/db/backends/__init__.py

     
    99from django.db import DEFAULT_DB_ALIAS
    1010from django.db.backends import util
    1111from django.db.transaction import TransactionManagementError
    12 from django.utils import datetime_safe
    1312from django.utils.importlib import import_module
    1413
    1514
     
    718717        """
    719718        if value is None:
    720719            return None
    721         return datetime_safe.new_date(value).strftime('%Y-%m-%d')
     720        return unicode(value)
    722721
    723722    def value_to_db_datetime(self, value):
    724723        """
     
    731730
    732731    def value_to_db_time(self, value):
    733732        """
    734         Transform a datetime value to an object compatible with what is expected
     733        Transform a time value to an object compatible with what is expected
    735734        by the backend driver for time columns.
    736735        """
    737736        if value is None:
  • django/contrib/sitemaps/tests/basic.py

     
    6767<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    6868<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
    6969</urlset>
    70 """ % (self.base_url, date.today().strftime('%Y-%m-%d')))
     70""" % (self.base_url, date.today()))
    7171
    7272    def test_simple_custom_sitemap(self):
    7373        "A simple sitemap can be rendered with a custom template"
     
    7979<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    8080<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
    8181</urlset>
    82 """ % (self.base_url, date.today().strftime('%Y-%m-%d')))
     82""" % (self.base_url, date.today()))
    8383
    8484    @skipUnless(settings.USE_I18N, "Internationalization is not enabled")
    8585    def test_localized_priority(self):
     
    9393        # haven't been rendered in localized format
    9494        response = self.client.get('/simple/sitemap.xml')
    9595        self.assertContains(response, '<priority>0.5</priority>')
    96         self.assertContains(response, '<lastmod>%s</lastmod>' % date.today().strftime('%Y-%m-%d'))
     96        self.assertContains(response, '<lastmod>%s</lastmod>' % date.today())
    9797        deactivate()
    9898
    9999    def test_generic_sitemap(self):
     
    152152<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    153153<url><loc>http://testserver/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
    154154</urlset>
    155 """ % date.today().strftime('%Y-%m-%d'))
     155""" % date.today())
    156156
    157157    @skipUnless("django.contrib.sites" in settings.INSTALLED_APPS, "django.contrib.sites app not installed.")
    158158    def test_sitemap_get_urls_no_site_1(self):
  • django/contrib/admin/filters.py

     
    281281
    282282        today = datetime.date.today()
    283283        one_week_ago = today - datetime.timedelta(days=7)
    284         today_str = (isinstance(self.field, models.DateTimeField)
    285                         and today.strftime('%Y-%m-%d 23:59:59')
    286                         or today.strftime('%Y-%m-%d'))
     284        today_str = str(today)
     285        if isinstance(self.field, models.DateTimeField):
     286            today_str += ' 23:59:59'
    287287
    288288        self.lookup_kwarg_year = '%s__year' % self.field_path
    289289        self.lookup_kwarg_month = '%s__month' % self.field_path
     
    299299                self.lookup_kwarg_day: str(today.day),
    300300            }),
    301301            (_('Past 7 days'), {
    302                 self.lookup_kwarg_past_7_days_gte: one_week_ago.strftime('%Y-%m-%d'),
     302                self.lookup_kwarg_past_7_days_gte: str(one_week_ago),
    303303                self.lookup_kwarg_past_7_days_lte: today_str,
    304304            }),
    305305            (_('This month'), {
  • tests/regressiontests/admin_filters/tests.py

     
    186186        self.assertEqual(choice['query_string'], '?date_registered__year=%s'
    187187                                                % (self.today.year))
    188188
    189         request = self.request_factory.get('/', {'date_registered__gte': self.one_week_ago.strftime('%Y-%m-%d'),
    190                                                  'date_registered__lte': self.today.strftime('%Y-%m-%d')})
     189        request = self.request_factory.get('/', {'date_registered__gte': str(self.one_week_ago),
     190                                                 'date_registered__lte': str(self.today)})
    191191        changelist = self.get_changelist(request, Book, modeladmin)
    192192
    193193        # Make sure the correct queryset is returned
     
    201201        self.assertEqual(choice['selected'], True)
    202202        self.assertEqual(choice['query_string'], '?date_registered__gte=%s'
    203203                                                 '&date_registered__lte=%s'
    204                                                 % (self.one_week_ago.strftime('%Y-%m-%d'), self.today.strftime('%Y-%m-%d')))
     204                                                % (str(self.one_week_ago), str(self.today)))
    205205
    206206    def test_allvaluesfieldlistfilter(self):
    207207        modeladmin = BookAdmin(Book, site)
Back to Top