def process_response(self, request, response):
if 'Content-Language' not in response:
response['Content-Language'] = translation.get_language()
translation.deactivate()
return response
python类deactivate()的实例源码
def process_response(self, request, response):
patch_vary_headers(response, ("Accept-Language",))
response["Content-Language"] = translation.get_language()
translation.deactivate()
return response
def process_response(self, request, response):
patch_vary_headers(response, ("Accept-Language",))
response["Content-Language"] = translation.get_language()
translation.deactivate()
return response
def process_response(self, request, response):
translation.deactivate()
return response
def location(self, title):
translation.activate(title.language)
url = title.page.get_absolute_url(title.language)
translation.deactivate()
return url
def process_response(self, request, response):
patch_vary_headers(response, ("Accept-Language",))
response["Content-Language"] = translation.get_language()
translation.deactivate()
return response
def process_response(self, request, response):
patch_vary_headers(response, ("Accept-Language",))
response["Content-Language"] = translation.get_language()
translation.deactivate()
return response
def process_response(self, request, response):
patch_vary_headers(response, ("Accept-Language",))
response["Content-Language"] = translation.get_language()
translation.deactivate()
return response
def handle(self, **options):
""" Send Report E-mails """
from django.conf import settings
translation.activate(settings.LANGUAGE_CODE)
backend = get_backend()
# This command is a NOOP if using the Mixpanel backend
if backend == 'app_metrics.backends.mixpanel':
print "Useless use of metrics_send_email when using Mixpanel backend."
return
# Determine if we should also send any weekly or monthly reports
today = datetime.date.today()
if today.weekday == 0:
send_weekly = True
else:
send_weekly = False
if today.day == 1:
send_monthly = True
else:
send_monthly = False
qs = MetricSet.objects.filter(Q(no_email=False), Q(send_daily=True) | Q(send_monthly=send_monthly) | Q(send_weekly=send_weekly))
if "mailer" in settings.INSTALLED_APPS:
from mailer import send_html_mail
USE_MAILER = True
else:
from django.core.mail import EmailMultiAlternatives
USE_MAILER = False
for s in qs:
subject = _("%s Report") % s.name
recipient_list = s.email_recipients.values_list('email', flat=True)
(message, message_html) = generate_report(s, html=True)
if message == None:
continue
if USE_MAILER:
send_html_mail(subject=subject,
message=message,
message_html=message_html,
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=recipient_list)
else:
msg = EmailMultiAlternatives(subject=subject,
body=message,
from_email=settings.DEFAULT_FROM_EMAIL,
to=recipient_list)
msg.attach_alternative(message_html, "text/html")
msg.send()
translation.deactivate()
wiki_notifications_create_defaults.py 文件源码
项目:website
作者: hackerspace-ntnu
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def handle(self, *args, **options):
from django.conf import settings
translation.activate(settings.LANGUAGE_CODE)
from django.contrib.auth import get_user_model
from wiki.plugins.notifications import models
from wiki.plugins.notifications.settings import ARTICLE_EDIT
from wiki.models import Article
from django_nyt.utils import subscribe
from django_nyt.models import Settings
from django.contrib.contenttypes.models import ContentType
# User: Settings
settings_map = {}
def subscribe_to_article(article, user):
if user not in settings_map:
settings_map[user], __ = Settings.objects.get_or_create(
user=user)
return subscribe(
settings_map[user],
ARTICLE_EDIT,
content_type=ContentType.objects.get_for_model(article),
object_id=article.id)
subs = 0
articles = Article.objects.all()
for article in articles:
if article.owner:
subscription = subscribe_to_article(article, article.owner)
models.ArticleSubscription.objects.get_or_create(
article=article,
subscription=subscription)
subs += 1
for revision in article.articlerevision_set.exclude(
user=article.owner).exclude(
user=None).values('user').distinct():
user = get_user_model().objects.get(id=revision['user'])
subs += 1
subscription = subscribe_to_article(article, user)
models.ArticleSubscription.objects.get_or_create(
article=article,
subscription=subscription)
print("Created {subs:d} subscriptions on {arts:d} articles".format(
subs=subs,
arts=articles.count(),
))
translation.deactivate()
def handle(self, *app_labels, **options):
# Activate project's default language
translation.activate(settings.LANGUAGE_CODE)
comment = options["comment"]
batch_size = options["batch_size"]
verbosity = int(options.get("verbosity", 1))
app_list = SortedDict()
# if no apps given, use all installed.
if len(app_labels) == 0:
for app in models.get_apps ():
if not app in app_list:
app_list[app] = []
for model_class in models.get_models(app):
if not model_class in app_list[app]:
app_list[app].append(model_class)
else:
for label in app_labels:
try:
app_label, model_label = label.split(".")
try:
app = models.get_app(app_label)
except ImproperlyConfigured:
raise CommandError("Unknown application: %s" % app_label)
model_class = models.get_model(app_label, model_label)
if model_class is None:
raise CommandError("Unknown model: %s.%s" % (app_label, model_label))
if app in app_list:
if app_list[app] and model_class not in app_list[app]:
app_list[app].append(model_class)
else:
app_list[app] = [model_class]
except ValueError:
# This is just an app - no model qualifier.
app_label = label
try:
app = models.get_app(app_label)
if not app in app_list:
app_list[app] = []
for model_class in models.get_models(app):
if not model_class in app_list[app]:
app_list[app].append(model_class)
except ImproperlyConfigured:
raise CommandError("Unknown application: %s" % app_label)
# Create revisions.
for app, model_classes in app_list.items():
for model_class in model_classes:
self.create_initial_revisions(app, model_class, comment, batch_size, verbosity)
# Go back to default language
translation.deactivate()