コード例 #1
0
from django.conf import settings
from django_jinja import library

from taiga import domains

URLS = {
    "home": "/",
    "backlog": "/#/project/{0}/backlog/",
    "taskboard": "/#/project/{0}/taskboard/{1}",
    "userstory": "/#/project/{0}/user-story/{1}",
    "task": "/#/project/{0}/tasks/{1}",
    "issue": "/#/project/{0}/issues/{1}",
    "project-admin": "/#/project/{0}/admin",
    "change-password": "******",
    "invitation": "/#/invitation/{0}",
    "wiki": "/#/project/{0}/wiki/{1}"
}

lib = library.Library()


@lib.global_function(name="resolve_front_url")
def resolve(type, *args):
    domain = domains.get_active_domain()
    url_tmpl = "{scheme}//{domain}{url}"

    scheme = domain.scheme and "{0}:".format(domain.scheme) or ""
    url = URLS[type].format(*args)
    return url_tmpl.format(scheme=scheme, domain=domain.domain, url=url)
コード例 #2
0
ファイル: functions.py プロジェクト: shadown/taiga-back
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from django.utils.translation import ugettext_lazy as _

from django_jinja import library

register = library.Library()

EXTRA_FIELD_VERBOSE_NAMES = {
    "description_diff": _("description"),
    "content_diff": _("content"),
    "blocked_note_diff": _("blocked note")
}


@register.global_function
def verbose_name(obj: object, field_name: str) -> str:
    if field_name in EXTRA_FIELD_VERBOSE_NAMES:
        return EXTRA_FIELD_VERBOSE_NAMES[field_name]

    try:
        return obj._meta.get_field(field_name).verbose_name