bug fix to language preferences for unlogged in users. Also JS fix to all language pref pages.
authorKeyserSosa <chris@reddit.com>
Wed Aug 12 11:28:05 2009 -0700 (2 years ago)
changeset 400fb69e8b57be8
parent 399 b3dd4d0b4e3c
child 401 efac9f63b4b8
bug fix to language preferences for unlogged in users. Also JS fix to all language pref pages.

committer: KeyserSosa <chris@reddit.com>
r2/r2/controllers/reddit_base.py
r2/r2/public/static/js/reddit.js
r2/r2/templates/utils.html
     1.1 --- a/r2/r2/controllers/reddit_base.py	Tue Aug 11 14:27:32 2009 -0700
     1.2 +++ b/r2/r2/controllers/reddit_base.py	Wed Aug 12 11:28:05 2009 -0700
     1.3 @@ -121,7 +121,8 @@
     1.4  
     1.5      def _commit(self):
     1.6          if self._dirty:
     1.7 -            self._t.update(self._dirties)
     1.8 +            for k, (oldv, newv) in self._dirties.iteritems():
     1.9 +                self._t[k] = newv
    1.10              self._to_cookie(self._t)
    1.11  
    1.12      def _load(self):
    1.13 @@ -488,8 +489,13 @@
    1.14              c.user_is_loggedin = True
    1.15          else:
    1.16              c.user = UnloggedUser(get_browser_langs())
    1.17 -            c.user._load()
    1.18 -
    1.19 +            # patch for fixing mangled language preferences
    1.20 +            if (not isinstance(c.user.pref_lang, basestring) or
    1.21 +                not all(isinstance(x, basestring)
    1.22 +                        for x in c.user.pref_content_langs)):
    1.23 +                c.user.pref_lang = g.lang
    1.24 +                c.user.pref_content_langs = [g.lang]
    1.25 +                c.user._commit()
    1.26          if c.user_is_loggedin:
    1.27              if not c.user._loaded:
    1.28                  c.user._load()
     2.1 --- a/r2/r2/public/static/js/reddit.js	Tue Aug 11 14:27:32 2009 -0700
     2.2 +++ b/r2/r2/public/static/js/reddit.js	Wed Aug 12 11:28:05 2009 -0700
     2.3 @@ -1036,6 +1036,14 @@
     2.4      };
     2.5  };
     2.6  
     2.7 +function clear_all_langs(elem) {
     2.8 +    $(elem).parents("form").find("input[type=checkbox]").attr("checked", false);
     2.9 +}
    2.10 +
    2.11 +function check_some_langs(elem) {
    2.12 +    $(elem).parents("form").find("#some-langs").attr("checked", true);
    2.13 +}
    2.14 +
    2.15  /* The ready method */
    2.16  $(function() {
    2.17          /* set function to be called on thing creation/replacement,
     3.1 --- a/r2/r2/templates/utils.html	Tue Aug 11 14:27:32 2009 -0700
     3.2 +++ b/r2/r2/templates/utils.html	Wed Aug 12 11:28:05 2009 -0700
     3.3 @@ -194,7 +194,7 @@
     3.4       all_checked, some_checked = some_checked, all_checked
     3.5  %>
     3.6  <input type="radio" name="all-langs" id="all-langs" value="all"
     3.7 -       onclick="clear_all(this)" ${all_checked}/>
     3.8 +       onclick="clear_all_langs(this)" ${all_checked}/>
     3.9  <label for="all-langs">${_("all languages")}</label>
    3.10  <br/>
    3.11  <input type="radio" name="all-langs" id="some-langs" value="some"
    3.12 @@ -217,7 +217,7 @@
    3.13           checked = ""
    3.14      %>
    3.15      <input type="checkbox" name="${idname}" id="${idname}"
    3.16 -           onclick="check_some()" ${checked}/>
    3.17 +           onclick="check_some_langs(this)" ${checked}/>
    3.18      <label for="${idname}">${g.lang_name[lang]}</label>
    3.19      </td>
    3.20    %endfor