Source code for shuup.xtheme.plugins.widgets

# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2017, Shoop Commerce Ltd. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from django import forms
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe


[docs]class XThemeModelChoiceWidget(forms.Select):
[docs] def render(self, name, value, attrs=None, choices=()): return mark_safe( render_to_string("shuup/xtheme/_model_widget.jinja", { "name": name, "selected_value": value, "objects": self.choices, }) )
[docs]class XThemeModelChoiceField(forms.ModelChoiceField): widget = XThemeModelChoiceWidget
[docs] def label_from_instance(self, obj): return obj