本文整理汇总了Python中wger.utils.language.load_language函数的典型用法代码示例。如果您正苦于以下问题:Python load_language函数的具体用法?Python load_language怎么用?Python load_language使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_language函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: view
def view(request, id):
'''
Show the nutrition plan with the given ID
'''
template_data = {}
plan = get_object_or_404(NutritionPlan, pk=id)
user = plan.user
is_owner = request.user == user
if not is_owner and not user.userprofile.ro_access:
return HttpResponseForbidden()
uid, token = make_token(user)
# Load the language and pass it to the template
language = load_language()
template_data['language'] = language
template_data['MEALITEM_WEIGHT_GRAM'] = MEALITEM_WEIGHT_GRAM
template_data['MEALITEM_WEIGHT_UNIT'] = MEALITEM_WEIGHT_UNIT
# Get the nutritional info
template_data['plan'] = plan
template_data['nutritional_data'] = plan.get_nutritional_values()
# Tokens for the links
template_data['uid'] = uid
template_data['token'] = token
template_data['owner_user'] = user
template_data['is_owner'] = is_owner
template_data['show_shariff'] = is_owner
return render(request, 'plan/view.html', template_data)
示例2: processor
def processor(request):
language = load_language()
full_path = request.get_full_path()
i18n_path = {}
for lang in settings.LANGUAGES:
i18n_path[lang[0]] = '/{0}{1}'.format(lang[0], full_path[3:])
context = {
# Application version
'version': get_version(),
# User language
'language': language,
# Available application languages
'languages': settings.LANGUAGES,
# The current path
'request_full_path': full_path,
# Translation links
'i18n_path': i18n_path,
# Translation links
'datepicker_i18n_path': 'js/bootstrap-datepicker/locales/bootstrap-datepicker.{0}.js'.
format(language.short_name),
# Flag for guest users
'has_demo_data': request.session.get('has_demo_data', False),
# Don't show messages on AJAX requests (they are deleted if shown)
'no_messages': request.META.get('HTTP_X_WGER_NO_MESSAGES', False),
# Default cache time for template fragment caching
'cache_timeout': settings.CACHES['default']['TIMEOUT']
}
# Pseudo-intelligent navigation here
if '/software/' in request.get_full_path() \
or '/contact' in request.get_full_path() \
or '/api/v2' in request.get_full_path():
context['active_tab'] = constants.SOFTWARE_TAB
elif '/exercise/' in request.get_full_path():
context['active_tab'] = constants.EXERCISE_TAB
elif '/nutrition/' in request.get_full_path():
context['active_tab'] = constants.NUTRITION_TAB
elif '/weight/' in request.get_full_path():
context['active_tab'] = constants.WEIGHT_TAB
elif '/workout/' in request.get_full_path():
context['active_tab'] = constants.WORKOUT_TAB
else:
context['active_tab'] = constants.USER_TAB
return context
示例3: view
def view(request, id):
"""
Show the nutrition plan with the given ID
"""
template_data = {}
plan = get_object_or_404(NutritionPlan, pk=id)
user = plan.user
is_owner = request.user == user
if not is_owner and not user.userprofile.ro_access:
return HttpResponseForbidden()
uid, token = make_token(user)
# Load the language and pass it to the template
language = load_language()
template_data["language"] = language
template_data["MEALITEM_WEIGHT_GRAM"] = MEALITEM_WEIGHT_GRAM
template_data["MEALITEM_WEIGHT_UNIT"] = MEALITEM_WEIGHT_UNIT
# Get the nutritional info
template_data["plan"] = plan
template_data["nutritional_data"] = plan.get_nutritional_values()
# Tokens for the links
template_data["uid"] = uid
template_data["token"] = token
template_data["owner_user"] = user
template_data["is_owner"] = is_owner
template_data["show_shariff"] = is_owner
return render(request, "plan/view.html", template_data)
示例4: form_valid
def form_valid(self, form):
'''
Set language, author and status
'''
form.instance.language = load_language()
form.instance.set_author(self.request)
return super(ExerciseAddView, self).form_valid(form)
示例5: form_valid
def form_valid(self, form):
'''
Set the user that submitted the exercise
If admin, set appropriate status
'''
form.instance.language = load_language()
if self.request.user.has_perm('exercises.add_exercise'):
form.instance.status = Exercise.EXERCISE_STATUS_ADMIN
if not form.instance.license_author:
form.instance.license_author = 'wger.de'
else:
if not form.instance.license_author:
form.instance.license_author = self.request.user.username
subject = _('New user submitted exercise')
message = _(u'''The user {0} submitted a new exercise "{1}".'''.format(
self.request.user.username, form.instance.name))
mail.mail_admins(subject,
message,
fail_silently=True)
return super(ExerciseAddView, self).form_valid(form)
示例6: view
def view(request, id):
'''
Show the nutrition plan with the given ID
'''
template_data = {}
user = request.user
uid, token = make_token(user)
plan = get_object_or_404(NutritionPlan, pk=id, user=user)
template_data['plan'] = plan
# Load the language and pass it to the template
language = load_language()
template_data['language'] = language
template_data['MEALITEM_WEIGHT_GRAM'] = MEALITEM_WEIGHT_GRAM
template_data['MEALITEM_WEIGHT_UNIT'] = MEALITEM_WEIGHT_UNIT
# Get the nutritional info
template_data['nutritional_data'] = plan.get_nutritional_values()
# Tokens for the links
template_data['uid'] = uid
template_data['token'] = token
return render(request, 'plan/view.html', template_data)
示例7: perform_create
def perform_create(self, serializer):
'''
Set author and status
'''
language = load_language()
obj = serializer.save(language=language)
# Todo is it right to call set author after save?
obj.set_author(self.request)
obj.save()
示例8: add
def add(request):
'''
Add a new nutrition plan and redirect to its page
'''
plan = NutritionPlan()
plan.user = request.user
plan.language = load_language()
plan.save()
return HttpResponseRedirect(reverse('nutrition:plan:view', kwargs={'id': plan.id}))
示例9: add
def add(request):
"""
Add a new nutrition plan and redirect to its page
"""
plan = NutritionPlan()
plan.user = request.user
plan.language = load_language()
plan.save()
return HttpResponseRedirect(reverse("nutrition:plan:view", kwargs={"id": plan.id}))
示例10: processor
def processor(request):
full_path = request.get_full_path()
context = {
# Application version
'version': get_version(),
# User language
'language': load_language(),
# The current path
'request_full_path': full_path,
# Translation links
'i18n_path': {'de': '/de' + full_path[3:],
'en': '/en' + full_path[3:]},
# Contact email
'contact_email': 'roland @ geider.net',
# Flag for guest users
'has_demo_data': request.session.get('has_demo_data', False),
# Don't show messages on AJAX requests (they are deleted if shown)
'no_messages': request.META.get('HTTP_X_WGER_NO_MESSAGES', False),
}
# Pseudo-intelligent navigation here
if '/software/' in request.get_full_path() \
or '/contact' in request.get_full_path():
context['active_tab'] = constants.SOFTWARE_TAB
elif '/exercise/' in request.get_full_path():
context['active_tab'] = constants.EXERCISE_TAB
elif '/nutrition/' in request.get_full_path():
context['active_tab'] = constants.NUTRITION_TAB
elif '/weight/' in request.get_full_path():
context['active_tab'] = constants.WEIGHT_TAB
elif '/workout/' in request.get_full_path():
context['active_tab'] = constants.WORKOUT_TAB
else:
context['active_tab'] = constants.USER_TAB
return context
示例11: form_valid
def form_valid(self, form):
# set the submitter, if admin, set approrpiate status
form.instance.user = self.request.user
if self.request.user.has_perm('nutrition.add_ingredient'):
form.instance.status = Ingredient.INGREDIENT_STATUS_ADMIN
else:
subject = _('New user submitted ingredient')
message = _(u'''The user {0} submitted a new ingredient "{1}".'''.format(
self.request.user.username, form.instance.name))
mail.mail_admins(subject,
message,
fail_silently=True)
form.instance.language = load_language()
return super(IngredientCreateView, self).form_valid(form)
示例12: overview
def overview(request):
'''
Overview with all exercises
'''
language = load_language()
template_data = {}
template_data.update(csrf(request))
categories = (ExerciseCategory.objects.filter(language=language.id)
.filter(exercise__status__in=Exercise.EXERCISE_STATUS_OK)
.distinct())
template_data['categories'] = categories
return render_to_response('overview.html',
template_data,
context_instance=RequestContext(request))
示例13: search
def search(request):
'''
Search an exercise, return the result as a JSON list
'''
# Perform the search
q = request.GET.get('term', '')
user_language = load_language()
exercises = (Exercise.objects.filter(name__icontains=q)
.filter(category__language_id=user_language)
.filter(status__in=Exercise.EXERCISE_STATUS_OK)
.order_by('category__name', 'name')
.distinct())
# AJAX-request, this comes from the autocompleter. Create a list and send
# it back as JSON
if request.is_ajax():
results = []
for exercise in exercises:
exercise_json = {}
exercise_json['id'] = exercise.id
exercise_json['name'] = exercise.name
exercise_json['value'] = exercise.name
exercise_json['category'] = exercise.category.name
results.append(exercise_json)
data = json.dumps(results)
# Return the results to the server
mimetype = 'application/json'
return HttpResponse(data, mimetype)
# Usual search (perhaps JS disabled), present the results as normal HTML page
else:
template_data = {}
template_data.update(csrf(request))
template_data['exercises'] = exercises
template_data['search_term'] = q
return render_to_response('exercise_search.html',
template_data,
context_instance=RequestContext(request))
示例14: view
def view(request, id):
'''
Show the nutrition plan with the given ID
'''
template_data = {}
plan = get_object_or_404(NutritionPlan, pk=id, user=request.user)
template_data['plan'] = plan
# Load the language and pass it to the template
language = load_language()
template_data['language'] = language
template_data['MEALITEM_WEIGHT_GRAM'] = MEALITEM_WEIGHT_GRAM
template_data['MEALITEM_WEIGHT_UNIT'] = MEALITEM_WEIGHT_UNIT
# Get the nutritional info
template_data['nutritional_data'] = plan.get_nutritional_values()
return render_to_response('plan/view.html',
template_data,
context_instance=RequestContext(request))
示例15: items
def items(self):
return (Ingredient.objects.filter(language=load_language())
.filter(status__in=Ingredient.INGREDIENT_STATUS_OK))