Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Patch to get the timezone right in the settings.py on linux [RSS Feed]

#1 Nov. 20, 2005 14:16:25

Brett P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Patch to get the timezone right in the settings.py on linux


Hi all,

Attached is a patch against current svn (applies to 0.90 also), that
automatically sets TIME_ZONE and LANGUAGE_CODE according to the hosting
system.

Cheers,
--
Brett Parker
web:http://www.sommitrealweird.co.uk/email: Index: django/core/management.py
===================================================================
--- django/core/management.py (revision 1298)
+++ django/core/management.py (working copy)
@@ -2,7 +2,7 @@
# development-server initialization.

import django
-import os, re, sys
+import os, re, sys, locale

MODULE_TEMPLATE = ''' {%% if perms.%(app)s.%(addperm)s or
perms.%(app)s.%(changeperm)s %%}
<tr>
@@ -465,6 +465,12 @@
fp = open(main_settings_file, 'w')
secret_key = ''.join([choice('&*(-_=+)') for i in
range(50)])
settings_contents = re.sub(r"(?<=SECRET_KEY = ')'", secret_key + "'",
settings_contents)
+ if os.access('/etc/timezone', R_OK):
+ tz = open('/etc/timezone', 'r').read().strip()
+ settings_contents = re.sub(r"(?<=TIME_ZONE = ').*'", tz + "'",
settings_contents)
+ if local.getdefaultlocale() != None:
+ langcode = re.sub(r"_", "-", locale.getdefaultlocale())
+ settings_contents = re.sub(r"(?<=LANGUAGE_CODE = ').*'", langcode +
"'", settings_contents)
fp.write(settings_contents)
fp.close()
startproject.help_doc = "Creates a Django project directory structure for the
given project name in the current directory."signature.ascDescription:Digital signature

Attachments:
attachment signature.asc (189 bytes)

Offline

#2 Nov. 20, 2005 14:23:09

Tom T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Patch to get the timezone right in the settings.py on linux


On 11/20/05, Brett Parker <> wrote:
> Attached is a patch against current svn (applies to 0.90 also), that
> automatically sets TIME_ZONE and LANGUAGE_CODE according to the hosting
> system.

The best place for patches is Django's Trac:http://code.djangoproject.com/

Offline

#3 Nov. 21, 2005 11:15:04

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Patch to get the timezone right in the settings.py on linux


>Attached is a patch against current svn (applies to 0.90 also), that
>automatically sets TIME_ZONE and LANGUAGE_CODE according to the >hosting
>system.

Actually setting TIME_ZONE and LANGUAGE_CODE to the settings according
to the hosting system isn't "the right thing" in days where people buy
cheapest hosting all over the world. Don't think a west-coaster would
be happy with the timezone of the east coast ;-)

So this can only be something optional, because there are people who
most definitely want to change it on per-project basis. For example my
IRC logger runs with Django Central Time, as it should be in sync (in
it's listings) with the Django Trac timeline and SVN changelogs. But
the machine is still my own machine running Europe/Berlin and
LANGUAGE_CODE de.

bye, Georg

Offline

#4 Nov. 21, 2005 18:51:38

Brett P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Patch to get the timezone right in the settings.py on linux


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hugo <> wrote:
>
> >Attached is a patch against current svn (applies to 0.90 also), that
> >automatically sets TIME_ZONE and LANGUAGE_CODE according to the >hosting
> >system.
>
> Actually setting TIME_ZONE and LANGUAGE_CODE to the settings according
> to the hosting system isn't "the right thing" in days where people buy
> cheapest hosting all over the world. Don't think a west-coaster would
> be happy with the timezone of the east coast ;-)
>
> So this can only be something optional, because there are people who
> most definitely want to change it on per-project basis. For example my
> IRC logger runs with Django Central Time, as it should be in sync (in
> it's listings) with the Django Trac timeline and SVN changelogs. But
> the machine is still my own machine running Europe/Berlin and
> LANGUAGE_CODE de.

It's still entirely optional, it just gets set to the hosting defaults
when you use:
django-admin.py startproject blah

so that the settings.py file is (potentially) correct for most people,
it doesn't in any way, shape, or form change the ability to edit
settings.py.

Have you got a different suggestion for how this should be set? Maybe it
would be good to be able to give a whole metric full of options to the
django-admin.py utility?

Thoughts?

Cheers,
- --
Brett Parker
web:http://www.sommitrealweird.co.uk/email:
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDghd2Eh8oWxevnjQRArcDAJ0dIZE4S47gHP2ajhrvk0hNEjESqwCglRCH
+ZXdxAzsZ7MGMx3Zp/+WAEs=
=g3qo
-----END PGP SIGNATURE-----

Offline

#5 Nov. 21, 2005 18:58:08

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Patch to get the timezone right in the settings.py on linux


>It's still entirely optional, it just gets set to the hosting defaults
>when you use:
> django-admin.py startproject blah

Ok, I didn't look into the patch (google groups web interface doesn't
do that nicely), so if it is only the default on startproject, that's
fine with me.

bye, Georg

Offline

  • Root
  • » Django
  • » Patch to get the timezone right in the settings.py on linux [RSS Feed]

Board footer

Moderator control

Enjoy the 24th of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support