Beispiel #1
0
    def try_to_guess_url(url):

        url_adapter = g.get_url_adapter()

        try:
            # TODO: OZ by OZ: this try is because i don't understand how to check application/request context stack'
            if url is None:
                url_adapter = g.get_url_adapter()
                rules = url_adapter.map._rules_by_endpoint.get(
                    request.endpoint, ())
                url = '' if len(rules) < 1 else rules[0].rule
            else:

                from werkzeug.urls import url_parse

                parsed_url = url_parse(url)
                rules = url_adapter.match(parsed_url.path,
                                          method='GET',
                                          return_rule=True)
                url = rules[0].rule

        except Exception:
            url = ''

        return url
Beispiel #2
0
    def try_to_guess_url(url):

        url_adapter = g.get_url_adapter()

        if url is None:
            url_adapter = g.get_url_adapter()
            rules = url_adapter.map._rules_by_endpoint.get(request.endpoint, ())
            url = '' if len(rules) < 1 else rules[0].rule
        else:
            try:
                from werkzeug.urls import url_parse

                parsed_url = url_parse(url)
                rules = url_adapter.match(parsed_url.path, method='GET', return_rule=True)
                url = rules[0].rule
            except Exception:
                url = ''

        return url
Beispiel #3
0
    def try_to_guess_url(url):

        url_adapter = g.get_url_adapter()

        if url is None:
            url_adapter = g.get_url_adapter()
            rules = url_adapter.map._rules_by_endpoint.get(
                request.endpoint, ())
            url = '' if len(rules) < 1 else rules[0].rule
        else:
            try:
                from werkzeug.urls import url_parse

                parsed_url = url_parse(url)
                rules = url_adapter.match(parsed_url.path,
                                          method='GET',
                                          return_rule=True)
                url = rules[0].rule
            except Exception:
                url = ''

        return url
Beispiel #4
0
    def try_to_guess_url(url):

        url_adapter = g.get_url_adapter()

        try:
            # TODO: OZ by OZ: this try is because i don't understand how to check application/request context stack'
            if url is None:
                url_adapter = g.get_url_adapter()
                rules = url_adapter.map._rules_by_endpoint.get(request.endpoint, ())
                url = '' if len(rules) < 1 else rules[0].rule
            else:

                from werkzeug.urls import url_parse

                parsed_url = url_parse(url)
                rules = url_adapter.match(parsed_url.path, method='GET', return_rule=True)
                url = rules[0].rule

        except Exception:
            url = ''

        return url
Beispiel #5
0
    def getTranslate(template, phrase, url=None):
        url_adapter = g.get_url_adapter()

        if url is None:
            url_adapter = g.get_url_adapter()
            rules = url_adapter.map._rules_by_endpoint.get(request.endpoint, ())
            url = '' if len(rules) < 1 else rules[0].rule
        else:
            try:
                from werkzeug.urls import url_parse

                parsed_url = url_parse(url)
                rules = url_adapter.match(parsed_url.path, method='GET', return_rule=True)
                url = rules[0].rule
            except Exception:
                url = ''

        if phrase[:2] == '__':
            phrase = phrase[2:]
            template = '__GLOBAL'

        exist = db(TranslateTemplate, template=template, name=phrase).first()

        lang = TranslateTemplate.languages[0]
        if g.user_dict['lang'] in TranslateTemplate.languages:
            lang = g.user_dict['lang']

        if exist:
            if current_app.config['DEBUG']:
                # TODO: OZ by OZ change ac without changing md (md changed by trigger)
                exist.ac_tm = None
                exist.save()
        else:
            exist = TranslateTemplate(template=template, name=phrase,
                                      url=url, **{l: phrase for l in TranslateTemplate.languages}).save()

        return getattr(exist, lang)