本文整理汇总了Python中mezzanine.utils.importing.import_dotted_path函数的典型用法代码示例。如果您正苦于以下问题:Python import_dotted_path函数的具体用法?Python import_dotted_path怎么用?Python import_dotted_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了import_dotted_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_utils
def test_utils(self):
"""
Miscellanous tests for the ``mezzanine.utils`` package.
"""
self.assertRaises(ImportError, import_dotted_path, "mezzanine")
self.assertRaises(ImportError, import_dotted_path, "mezzanine.NO")
self.assertRaises(ImportError, import_dotted_path, "mezzanine.core.NO")
try:
import_dotted_path("mezzanine.core")
except ImportError:
self.fail("mezzanine.utils.imports.import_dotted_path" 'could not import "mezzanine.core"')
示例2: recalculate_cart
def recalculate_cart(request):
"""
Updates an existing discount code, shipping, and tax when the
cart is modified.
"""
from cartridge.shop import checkout
from cartridge.shop.forms import DiscountForm
from cartridge.shop.models import Cart
# Rebind the cart to request since it's been modified.
if request.session.get('cart') != request.cart.pk:
request.session['cart'] = request.cart.pk
request.cart = Cart.objects.from_request(request)
discount_code = request.session.get("discount_code", "")
if discount_code:
# Clear out any previously defined discount code
# session vars.
names = ("free_shipping", "discount_code", "discount_total")
clear_session(request, *names)
discount_form = DiscountForm(request, {"discount_code": discount_code})
if discount_form.is_valid():
discount_form.set_discount()
handler = lambda s: import_dotted_path(s) if s else lambda *args: None
billship_handler = handler(settings.SHOP_HANDLER_BILLING_SHIPPING)
tax_handler = handler(settings.SHOP_HANDLER_TAX)
try:
if request.session["order"]["step"] >= checkout.CHECKOUT_STEP_FIRST:
billship_handler(request, None)
tax_handler(request, None)
except (checkout.CheckoutError, ValueError, KeyError):
pass
示例3: comment
def comment(request, template="generic/comments.html", extra_context=None):
"""
Handle a ``ThreadedCommentForm`` submission and redirect back to its
related object.
"""
response = initial_validation(request, "comment")
if isinstance(response, HttpResponse):
return response
obj, post_data = response
form_class = import_dotted_path(settings.COMMENT_FORM_CLASS)
form = form_class(request, obj, post_data)
if form.is_valid():
url = obj.get_absolute_url()
if is_spam(request, form, url):
return redirect(url)
comment = form.save(request)
response = redirect(add_cache_bypass(comment.get_absolute_url()))
# Store commenter's details in a cookie for 90 days.
for field in ThreadedCommentForm.cookie_fields:
cookie_name = ThreadedCommentForm.cookie_prefix + field
cookie_value = post_data.get(field, "")
set_cookie(response, cookie_name, cookie_value)
return response
elif request.is_ajax() and form.errors:
return HttpResponse(dumps({"errors": form.errors}))
# Show errors with stand-alone comment form.
context = {"obj": obj, "posted_comment_form": form}
context.update(extra_context or {})
return TemplateResponse(request, template, context)
示例4: urls
def urls(self):
urls = [
url("", super(LazyAdminSite, self).urls),
]
# Filebrowser admin media library.
fb_name = getattr(settings, "PACKAGE_NAME_FILEBROWSER", "")
if fb_name in settings.INSTALLED_APPS:
try:
fb_urls = import_dotted_path("%s.sites.site" % fb_name).urls
except ImportError:
fb_urls = "%s.urls" % fb_name
urls = [
# This gives the media library a root URL (which filebrowser
# doesn't provide), so that we can target it in the
# ADMIN_MENU_ORDER setting, allowing each view to correctly
# highlight its left-hand admin nav item.
url("^media-library/$", lambda r: redirect("fb_browse"),
name="media-library"),
url("^media-library/", include(fb_urls)),
] + urls
# Give the urlpattern for the user password change view an
# actual name, so that it can be reversed with multiple
# languages are supported in the admin.
User = get_user_model()
for admin in self._registry.values():
user_change_password = getattr(admin, "user_change_password", None)
if user_change_password:
bits = (User._meta.app_label, User._meta.object_name.lower())
urls = [
url("^%s/%s/(\d+)/password/$" % bits,
self.admin_view(user_change_password),
name="user_change_password"),
] + urls
break
return urls
示例5: build_modelgraph
def build_modelgraph(docs_path, package_name="mezzanine"):
"""
Creates a diagram of all the models for mezzanine and the given
package name, generates a smaller version and add it to the
docs directory for use in model-graph.rst
"""
project_path = os.path.join(docs_path, "..", package_name,
"project_template")
settings = import_dotted_path(package_name + ".project_template.settings")
apps = [a.rsplit(".")[1] for a in settings.INSTALLED_APPS
if a.startswith("mezzanine.") or a.startswith(package_name + ".")]
os.chdir(project_path)
cmd = "python manage.py graph_models -e -o graph.png %s" % " ".join(apps)
os.system(cmd)
to_path = os.path.join(docs_path, "img", "graph.png")
move(os.path.join(project_path, "graph.png"), to_path)
build_path = os.path.join(docs_path, "build", "_images")
if not os.path.exists(build_path):
os.makedirs(build_path)
copyfile(to_path, os.path.join(build_path, "graph.png"))
image = Image.open(to_path)
image.width = 800
image.height = image.size[1] * 800 / image.size[0]
resized_path = os.path.join(os.path.dirname(to_path), "graph-small.png")
image.save(resized_path, "PNG", quality=100)
示例6: urls
def urls(self):
from django.conf import settings
urls = patterns("", ("", super(LazyAdminSite, self).urls))
# Filebrowser admin media library.
fb_name = getattr(settings, "PACKAGE_NAME_FILEBROWSER", "")
if fb_name in settings.INSTALLED_APPS:
try:
fb_urls = import_dotted_path("%s.sites.site" % fb_name).urls
except ImportError:
fb_urls = "%s.urls" % fb_name
urls = patterns("", ("^media-library/", include(fb_urls))) + urls
# Give the urlpatterm for the user password change view an
# actual name, so that it can be reversed with multiple
# languages are supported in the admin.
User = get_user_model()
for admin in self._registry.values():
user_change_password = getattr(admin, "user_change_password", None)
if user_change_password:
bits = (User._meta.app_label, User._meta.object_name.lower())
urls = (
patterns(
"",
url(
"^%s/%s/(\d+)/password/$" % bits,
self.admin_view(user_change_password),
name="user_change_password",
),
)
+ urls
)
break
return urls
示例7: test_default_handler_exists
def test_default_handler_exists(self):
"""
Ensure that the handler specified in default settings exists as well as
the default setting itself.
"""
settings.use_editable()
handler = lambda s: import_dotted_path(s) if s else lambda *args: None
self.assertTrue(handler(settings.SHOP_HANDLER_TAX) is not None)
示例8: richtext_filters
def richtext_filters(content):
"""
Takes a value edited via the WYSIWYG editor, and passes it through
each of the functions specified by the RICHTEXT_FILTERS setting.
"""
for filter_name in settings.RICHTEXT_FILTERS:
filter_func = import_dotted_path(filter_name)
content = filter_func(content)
return content
示例9: is_spam
def is_spam(request, form, url):
"""
Main entry point for spam handling - called from the comment view and
page processor for ``mezzanine.forms``, to check if posted content is
spam. Spam filters are configured via the ``SPAM_FILTERS`` setting.
"""
for spam_filter_path in settings.SPAM_FILTERS:
spam_filter = import_dotted_path(spam_filter_path)
if spam_filter(request, form, url):
return True
示例10: richtext_filter
def richtext_filter(content):
"""
This template filter takes a string value and passes it through the
function specified by the RICHTEXT_FILTER setting.
"""
if settings.RICHTEXT_FILTER:
func = import_dotted_path(settings.RICHTEXT_FILTER)
else:
func = lambda s: s
return func(content)
示例11: upload_to
def upload_to(field_path, default):
"""
Used as the ``upload_to`` arg for file fields - allows for custom
handlers to be implemented on a per field basis defined by the
``UPLOAD_TO_HANDLERS`` setting.
"""
for k, v in settings.UPLOAD_TO_HANDLERS.items():
if k.lower() == field_path.lower():
return import_dotted_path(v)
return default
示例12: widget_extra_permission
def widget_extra_permission(user):
from mezzanine.conf import settings
try:
perm = import_dotted_path(settings.WIDGET_PERMISSION)
return perm(user)
except AttributeError:
return False
except ImportError:
raise ImproperlyConfigured(_("Could not import the value of ",
"settings.WIDGET_PERMISSION: %s" % settings.WIDGET_PERMISSION))
示例13: save
def save(self, *args, **kwargs):
keywords = []
if not self.keywords_string and getattr(settings, "AUTO_TAG", False):
func_name = getattr(settings, "AUTO_TAG_FUNCTION",
"drum.links.utils.auto_tag")
keywords = import_dotted_path(func_name)(self)
super(Link, self).save(*args, **kwargs)
if keywords:
lookup = reduce(ior, [Q(title__iexact=k) for k in keywords])
for keyword in Keyword.objects.filter(lookup):
self.keywords.add(AssignedKeyword(keyword=keyword), bulk=True)
示例14: get_profile_form
def get_profile_form():
"""
Returns the profile form defined by ``ACCOUNTS_PROFILE_FORM_CLASS``.
"""
from mezzanine.conf import settings
try:
return import_dotted_path(settings.ACCOUNTS_PROFILE_FORM_CLASS)
except ImportError:
raise ImproperlyConfigured("Value for ACCOUNTS_PROFILE_FORM_CLASS "
"could not be imported: %s" %
settings.ACCOUNTS_PROFILE_FORM_CLASS)
示例15: formfield
def formfield(self, **kwargs):
"""
Apply the widget class defined by the ``HTML_WIDGET_CLASS`` setting.
"""
try:
widget_class = import_dotted_path(settings.HTML_WIDGET_CLASS)
except ImportError:
raise ImproperlyConfigured(_("Could not import the value of "
"settings.HTML_WIDGET_CLASS: %s" % settings.HTML_WIDGET_CLASS))
kwargs["widget"] = widget_class()
formfield = super(HtmlField, self).formfield(**kwargs)
return formfield