• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python language.load_language函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wger.utils.language.load_language函数的典型用法代码示例。如果您正苦于以下问题:Python load_language函数的具体用法?Python load_language怎么用?Python load_language使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了load_language函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:romansp,项目名称:wger,代码行数:33,代码来源:plan.py


示例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
开发者ID:itsdtr,项目名称:wger,代码行数:60,代码来源:context_processor.py


示例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)
开发者ID:jamessimas,项目名称:wger,代码行数:33,代码来源:plan.py


示例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)
开发者ID:Tushar-Gupta,项目名称:wger,代码行数:7,代码来源:exercises.py


示例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)
开发者ID:gelliravi,项目名称:wger,代码行数:25,代码来源:exercises.py


示例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)
开发者ID:Tushar-Gupta,项目名称:wger,代码行数:25,代码来源:plan.py


示例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()
开发者ID:lediable,项目名称:wger,代码行数:9,代码来源:views.py


示例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}))
开发者ID:romansp,项目名称:wger,代码行数:11,代码来源:plan.py


示例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}))
开发者ID:jamessimas,项目名称:wger,代码行数:11,代码来源:plan.py


示例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
开发者ID:seraphyn,项目名称:wger,代码行数:49,代码来源:context_processor.py


示例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)
开发者ID:itsdtr,项目名称:wger,代码行数:16,代码来源:ingredient.py


示例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))
开发者ID:seraphyn,项目名称:wger,代码行数:17,代码来源:exercises.py


示例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))
开发者ID:seraphyn,项目名称:wger,代码行数:42,代码来源:exercises.py


示例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))
开发者ID:httpdss,项目名称:wger,代码行数:21,代码来源:plan.py


示例15: items

 def items(self):
     return (Ingredient.objects.filter(language=load_language())
                               .filter(status__in=Ingredient.INGREDIENT_STATUS_OK))
开发者ID:DeveloperMal,项目名称:wger,代码行数:3,代码来源:sitemap.py


示例16: processor

def processor(request):

    language = load_language()
    full_path = request.get_full_path()
    i18n_path = {}
    static_path = static('images/logos/logo-marketplace-256.png')

    for lang in settings.LANGUAGES:
        i18n_path[lang[0]] = u'/{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,

        # The current full path with host
        'request_absolute_path': request.build_absolute_uri(),
        'image_absolute_path': request.build_absolute_uri(static_path),


        # Translation links
        'i18n_path': i18n_path,

        # 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'],

        # Used for logged in trainers
        'trainer_identity': request.session.get('trainer.identity'),
    }

    # 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
            context['show_shariff'] = True

    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
开发者ID:abeworld,项目名称:wger,代码行数:67,代码来源:context_processor.py


示例17: perform_create

 def perform_create(self, serializer):
     '''
     Set the owner
     '''
     serializer.save(user=self.request.user, language=load_language())
开发者ID:jamessimas,项目名称:wger,代码行数:5,代码来源:views.py


示例18: items

 def items(self):
     return (Ingredient.objects.filter(language=load_language())
                               .filter(status=Ingredient.STATUS_ACCEPTED))
开发者ID:ZidHuss,项目名称:wger,代码行数:3,代码来源:sitemap.py


示例19: form_valid

    def form_valid(self, form):

        form.instance.language = load_language()
        form.instance.set_author(self.request)
        return super(IngredientCreateView, self).form_valid(form)
开发者ID:ZidHuss,项目名称:wger,代码行数:5,代码来源:ingredient.py


示例20: form_valid

 def form_valid(self, form):
     form.instance.language = load_language()
     return super(WeightUnitCreateView, self).form_valid(form)
开发者ID:drkarl,项目名称:wger,代码行数:3,代码来源:unit.py



注:本文中的wger.utils.language.load_language函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wget.download函数代码示例发布时间:2022-05-26
下一篇:
Python cache_mapper.get_workout_canonical函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap