# Buggy code
def js_config(request):
    """
    Generates settings for javascript. Includes things like
    API keys for translaiton services or list of languages they
    support.
    """
    # Apertium support
    if settings.MT_APERTIUM_KEY is not None and settings.MT_APERTIUM_KEY != "":
        try:
            listpairs = urllib2.urlopen(
                "http://api.apertium.org/json/listPairs?key=%s"
                % settings.MT_APERTIUM_KEY
            )
            pairs = listpairs.read()
            parsed = json.loads(pairs)
            apertium_langs = [
                p["targetLanguage"]
                for p in parsed["responseData"]
                if p["sourceLanguage"] == "en"
            ]
        except Exception as e:
            logger.error(
                "failed to get supported languages from Apertium, using defaults (%s)",
                str(e),
            )
            apertium_langs = ["gl", "ca", "es", "eo"]
    else:
        apertium_langs = None

    # Microsoft translator support
    if settings.MT_MICROSOFT_KEY is not None and settings.MT_MICROSOFT_KEY != "":
        try:
            listpairs = urllib2.urlopen(
                "http://api.microsofttranslator.com/V2/Http.svc/GetLanguagesForTranslate?appID=%s"
                % settings.MT_MICROSOFT_KEY
            )
            data = listpairs.read()
            parsed = ElementTree.fromstring(data)
            microsoft_langs = [p.text for p in parsed.getchildren()]
        except Exception as e:
            logger.error(
                "failed to get supported languages from Microsoft, using defaults (%s)",
                str(e),
            )
            microsoft_langs = [
                "ar",
                "bg",
                "ca",
                "zh-CHS",
                "zh-CHT",
                "cs",
                "da",
                "nl",
                "en",
                "et",
                "fi",
                "fr",
                "de",
                "el",
                "ht",
                "he",
                "hi",
                "mww",
                "hu",
                "id",
                "it",
                "ja",
                "ko",
                "lv",
                "lt",
                "no",
                "fa",
                "pl",
                "pt",
                "ro",
                "ru",
                "sk",
                "sl",
                "es",
                "sv",
                "th",
                "tr",
                "uk",
                "vi",
            ]
    else:
        microsoft_langs = None

    return render_to_response(
        "js/config.js",
        RequestContext(
            request,
            {
                "apertium_langs": apertium_langs,
                "microsoft_langs": microsoft_langs,
            },
        ),
        mimetype="application/javascript",
    )


# Traceback (AttributeError)
Traceback (most recent call last):

File "/srv/weblate/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/srv/weblate/src/weblate/weblate/trans/views.py", line 1395, in translate
saved = unit.save_backend(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 2478, in save_backend
self.translation.update_lock(request)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1463, in update_lock
self.create_lock(request.user)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1434, in create_lock
self.update_lock_time(explicit, is_new)
File "/srv/weblate/src/weblate/weblate/trans/models.py", line 1443, in update_lock_time
seconds = settings.AUTO_LOCK_TIME
File "/srv/weblate/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'AUTO_LOCK_TIME'

# Fixed code
def js_config(request):
    """
    Generates settings for javascript. Includes things like
    API keys for translaiton services or list of languages they
    support.
    """
    # Apertium support
    if appsettings.MT_APERTIUM_KEY is not None and appsettings.MT_APERTIUM_KEY != "":
        try:
            listpairs = urllib2.urlopen(
                "http://api.apertium.org/json/listPairs?key=%s"
                % appsettings.MT_APERTIUM_KEY
            )
            pairs = listpairs.read()
            parsed = json.loads(pairs)
            apertium_langs = [
                p["targetLanguage"]
                for p in parsed["responseData"]
                if p["sourceLanguage"] == "en"
            ]
        except Exception as e:
            logger.error(
                "failed to get supported languages from Apertium, using defaults (%s)",
                str(e),
            )
            apertium_langs = ["gl", "ca", "es", "eo"]
    else:
        apertium_langs = None

    # Microsoft translator support
    if appsettings.MT_MICROSOFT_KEY is not None and appsettings.MT_MICROSOFT_KEY != "":
        try:
            listpairs = urllib2.urlopen(
                "http://api.microsofttranslator.com/V2/Http.svc/GetLanguagesForTranslate?appID=%s"
                % appsettings.MT_MICROSOFT_KEY
            )
            data = listpairs.read()
            parsed = ElementTree.fromstring(data)
            microsoft_langs = [p.text for p in parsed.getchildren()]
        except Exception as e:
            logger.error(
                "failed to get supported languages from Microsoft, using defaults (%s)",
                str(e),
            )
            microsoft_langs = [
                "ar",
                "bg",
                "ca",
                "zh-CHS",
                "zh-CHT",
                "cs",
                "da",
                "nl",
                "en",
                "et",
                "fi",
                "fr",
                "de",
                "el",
                "ht",
                "he",
                "hi",
                "mww",
                "hu",
                "id",
                "it",
                "ja",
                "ko",
                "lv",
                "lt",
                "no",
                "fa",
                "pl",
                "pt",
                "ro",
                "ru",
                "sk",
                "sl",
                "es",
                "sv",
                "th",
                "tr",
                "uk",
                "vi",
            ]
    else:
        microsoft_langs = None

    return render_to_response(
        "js/config.js",
        RequestContext(
            request,
            {
                "apertium_langs": apertium_langs,
                "microsoft_langs": microsoft_langs,
            },
        ),
        mimetype="application/javascript",
    )