NDOJ/judge/jinja2/social.py

57 lines
1.6 KiB
Python
Raw Normal View History

2020-01-21 06:35:58 +00:00
from django.template.loader import get_template
from django.utils.safestring import mark_safe
2022-05-14 17:57:27 +00:00
from django_social_share.templatetags.social_share import (
post_to_facebook_url,
post_to_gplus_url,
post_to_twitter_url,
)
2020-01-21 06:35:58 +00:00
from . import registry
SHARES = [
2022-05-14 17:57:27 +00:00
(
"post_to_twitter",
"django_social_share/templatetags/post_to_twitter.html",
post_to_twitter_url,
),
(
"post_to_facebook",
"django_social_share/templatetags/post_to_facebook.html",
post_to_facebook_url,
),
(
"post_to_gplus",
"django_social_share/templatetags/post_to_gplus.html",
post_to_gplus_url,
),
2020-01-21 06:35:58 +00:00
# For future versions:
# ('post_to_linkedin', 'django_social_share/templatetags/post_to_linkedin.html', post_to_linkedin_url),
# ('post_to_reddit', 'django_social_share/templatetags/post_to_reddit.html', post_to_reddit_url),
]
def make_func(name, template, url_func):
def func(request, *args):
link_text = args[-1]
2022-05-14 17:57:27 +00:00
context = {"request": request, "link_text": mark_safe(link_text)}
2020-01-21 06:35:58 +00:00
context = url_func(context, *args[:-1])
return mark_safe(get_template(template).render(context))
func.__name__ = name
registry.function(name, func)
for name, template, url_func in SHARES:
make_func(name, template, url_func)
@registry.function
def recaptcha_init(language=None):
2022-05-14 17:57:27 +00:00
return get_template("snowpenguin/recaptcha/recaptcha_init.html").render(
2023-12-24 06:38:36 +00:00
{
"explicit": False,
"language": language,
"recaptcha_host": "https://google.com",
}
2022-05-14 17:57:27 +00:00
)