本文整理汇总了Python中mezzanine.utils.importing.import_dotted_path函数的典型用法代码示例。如果您正苦于以下问题:Python import_dotted_path函数的具体用法?Python import_dotted_path怎么用?Python import_dotted_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了import_dotted_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"')
开发者ID:nym,项目名称:mezzanine,代码行数:11,代码来源:tests.py
示例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
开发者ID:CoffenHu,项目名称:cartridge,代码行数:33,代码来源:utils.py
示例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)
开发者ID:Liuer,项目名称:mezzanine,代码行数:29,代码来源:views.py
示例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
开发者ID:Liuer,项目名称:mezzanine,代码行数:35,代码来源:lazy_admin.py
示例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)
开发者ID:DanHoerst,项目名称:mezzanine,代码行数:25,代码来源:docs.py
示例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
开发者ID:ctrengove,项目名称:mezzanine,代码行数:33,代码来源:lazy_admin.py
示例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)
开发者ID:hithaieshl,项目名称:cartridge,代码行数:8,代码来源:tests.py
示例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
开发者ID:sjdines,项目名称:mezzanine,代码行数:9,代码来源:mezzanine_tags.py
示例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
开发者ID:AdnanHodzic,项目名称:mezzanine,代码行数:10,代码来源:views.py
示例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)
开发者ID:a5an0,项目名称:mezzanine,代码行数:10,代码来源:mezzanine_tags.py
示例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
开发者ID:Amisiti,项目名称:mezzanine,代码行数:10,代码来源:models.py
示例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))
开发者ID:osiloke,项目名称:mezzanine_widgets,代码行数:10,代码来源:utilities.py
示例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)
开发者ID:COLABORATI,项目名称:drum,代码行数:11,代码来源:models.py
示例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)
开发者ID:Catalyst4Success,项目名称:site-django-mezzanine,代码行数:11,代码来源:__init__.py
示例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
开发者ID:MechanisM,项目名称:mezzanine,代码行数:12,代码来源:fields.py
示例16: 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)),)
return urls
开发者ID:crazese,项目名称:stefanbo,代码行数:12,代码来源:lazy_admin.py
示例17: 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
"""
to_path = os.path.join(docs_path, "img", "graph.png")
build_path = os.path.join(docs_path, "build", "_images")
resized_path = os.path.join(os.path.dirname(to_path), "graph-small.png")
settings = import_dotted_path(package_name + ".project_template.project_name.settings")
apps = [
a.rsplit(".")[1]
for a in settings.INSTALLED_APPS
if a.startswith("mezzanine.") or a.startswith(package_name + ".")
]
try:
from django_extensions.management.commands import graph_models
except ImportError:
warn("Couldn't build model_graph, django_extensions not installed")
else:
options = {"inheritance": True, "outputfile": "graph.png", "layout": "dot"}
try:
graph_models.Command().execute(*apps, **options)
except Exception as e:
warn("Couldn't build model_graph, graph_models failed on: %s" % e)
else:
try:
move("graph.png", to_path)
except OSError as e:
warn("Couldn't build model_graph, move failed on: %s" % e)
# docs/img/graph.png should exist in the repo - move it to the build path.
try:
if not os.path.exists(build_path):
os.makedirs(build_path)
copyfile(to_path, os.path.join(build_path, "graph.png"))
except OSError as e:
warn("Couldn't build model_graph, copy to build failed on: %s" % e)
try:
from PIL import Image
image = Image.open(to_path)
image.width = 800
image.height = image.size[1] * 800 // image.size[0]
image.save(resized_path, "PNG", quality=100)
except Exception as e:
warn("Couldn't build model_graph, resize failed on: %s" % e)
return
# Copy the dashboard screenshot to the build dir too. This doesn't
# really belong anywhere, so we do it here since this is the only
# spot we deal with doc images.
d = "dashboard.png"
copyfile(os.path.join(docs_path, "img", d), os.path.join(build_path, d))
开发者ID:Liuer,项目名称:mezzanine,代码行数:52,代码来源:docs.py
示例18: comment_filter
def comment_filter(comment_text):
"""
Passed comment text to be rendered through the function defined
by the ``COMMENT_FILTER`` setting. If no function is defined
(the default), Django's ``linebreaksbr`` and ``urlize`` filters
are used.
"""
filter_func = settings.COMMENT_FILTER
if not filter_func:
def filter_func(s):
return linebreaksbr(urlize(s, autoescape=True), autoescape=True)
elif not callable(filter_func):
filter_func = import_dotted_path(filter_func)
return filter_func(comment_text)
开发者ID:peopleco,项目名称:mezzanine,代码行数:14,代码来源:comment_tags.py
示例19: comments_for
def comments_for(context, obj):
"""
Provides a generic context variable name for the object that
comments are being rendered for.
"""
form_class = import_dotted_path(settings.COMMENT_FORM_CLASS)
form = form_class(context["request"], obj)
try:
context["posted_comment_form"]
except KeyError:
context["posted_comment_form"] = form
context["unposted_comment_form"] = form
context["comment_url"] = reverse("comment")
context["object_for_comments"] = obj
return context
开发者ID:AliLozano,项目名称:mezzanine,代码行数:15,代码来源:comment_tags.py
示例20: formfield
def formfield(self, **kwargs):
"""
Apply the widget class defined by the
``RICHTEXT_WIDGET_CLASS`` setting.
"""
from mezzanine.conf import settings
try:
widget_class = import_dotted_path(settings.RICHTEXT_WIDGET_CLASS)
except ImportError:
raise ImproperlyConfigured(_("Could not import the value of "
"settings.RICHTEXT_WIDGET_CLASS: %s"
% settings.RICHTEXT_WIDGET_CLASS))
kwargs["widget"] = widget_class()
formfield = super(RichTextField, self).formfield(**kwargs)
return formfield
开发者ID:awsum,项目名称:mezzanine,代码行数:15,代码来源:fields.py
注:本文中的mezzanine.utils.importing.import_dotted_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论