本文整理汇总了Python中shuup.admin.shop_provider.get_shop函数的典型用法代码示例。如果您正苦于以下问题:Python get_shop函数的具体用法?Python get_shop怎么用?Python get_shop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_shop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get
def get(self, request): # noqa (C901)
model_name = request.GET.get("model")
object_id = request.GET.get("pk", request.GET.get("id"))
if not model_name or not object_id:
return HttpResponseBadRequest(_("Invalid object."))
url = None
try:
model = apps.get_model(model_name)
except LookupError:
return HttpResponseBadRequest(_("Invalid model."))
instance = model.objects.filter(pk=object_id).first()
if instance:
try:
# try edit first
try:
url = get_model_url(
instance,
kind="edit",
user=request.user,
shop=get_shop(request),
raise_permission_denied=True
)
except NoModelUrl:
# try detail
try:
url = get_model_url(
instance,
kind="detail",
user=request.user,
shop=get_shop(request),
raise_permission_denied=True
)
except NoModelUrl:
pass
except PermissionDenied as exception:
from django.utils.encoding import force_text
raise Problem(force_text(exception))
if url:
# forward the mode param
if request.GET.get("mode"):
url = "{}?mode={}".format(url, request.GET["mode"])
return HttpResponseRedirect(url)
raise Http404(_("Object not found"))
开发者ID:ruqaiya,项目名称:shuup,代码行数:50,代码来源:edit.py
示例2: model_url
def model_url(context, model, kind="detail", default=None, **kwargs):
"""
Get a model URL of the given kind for a model (instance or class).
:param context: Jinja rendering context
:type context: jinja2.runtime.Context
:param model: The model instance or class.
:type model: django.db.Model
:param kind: The URL kind to retrieve. See `get_model_url`.
:type kind: str
:param default: Default value to return if model URL retrieval fails.
:type default: str
:return: URL string.
:rtype: str
"""
user = context.get("user")
try:
request = context.get("request")
shop = get_shop(request) if request else None
admin_model_url_resolvers = get_provide_objects("admin_model_url_resolver")
for resolver in admin_model_url_resolvers:
url = resolver(model, kind=kind, user=user, shop=shop, **kwargs)
if url:
return url
except NoModelUrl:
return default
开发者ID:shuup,项目名称:shuup,代码行数:27,代码来源:shuup_admin.py
示例3: media_upload
def media_upload(request, *args, **kwargs):
shop = get_shop(request)
try:
folder_id = int(request.POST.get("folder_id") or request.GET.get("folder_id") or 0)
path = request.POST.get("path") or request.GET.get("path") or None
if folder_id != 0:
folder = _get_folder_query(shop).get(pk=folder_id)
elif path:
folder = get_or_create_folder(shop, path)
else:
folder = None # Root folder upload. How bold!
except Exception as exc:
return JsonResponse({"error": "Invalid folder: %s" % force_text(exc)})
try:
upload_file = request.FILES["file"]
if upload_file.content_type.startswith("image/"):
filer_file = filer_image_from_upload(request, path=folder, upload_data=upload_file)
else:
filer_file = filer_file_from_upload(request, path=folder, upload_data=upload_file)
_ensure_media_file(shop, filer_file)
except Exception as exc:
return JsonResponse({"error": force_text(exc)})
return JsonResponse({
"file": _filer_file_to_json_dict(filer_file),
"message": _("%(file)s uploaded to %(folder)s") % {
"file": filer_file.label,
"folder": get_folder_name(folder)
}
})
开发者ID:ruqaiya,项目名称:shuup,代码行数:33,代码来源:views.py
示例4: is_url_valid
def is_url_valid(self, language_code, field_name, url):
"""
Ensure URL given is unique.
Check through the pages translation model objects to make
sure that the url given doesn't already exist.
Possible failure cases:
for new page:
* URL already exists
for existing page:
* URL (other than owned by existing page) exists
* URL exists in other languages of existing page
"""
pages_ids = Page.objects.for_shop(get_shop(self.request)).values_list("id", flat=True)
qs = self._get_translation_model().objects.filter(url=url, master_id__in=pages_ids)
if not self.instance.pk and qs.exists():
return False
other_qs = qs.exclude(master=self.instance)
if other_qs.exists():
return False
own_qs = qs.filter(master=self.instance).exclude(language_code=language_code)
if own_qs.exists():
return False
return True
开发者ID:ruqaiya,项目名称:shuup,代码行数:26,代码来源:views.py
示例5: get_context_data
def get_context_data(self, **kwargs):
context = super(ProductEditView, self).get_context_data(**kwargs)
orderability_errors = []
if self.object.pk:
context["title"] = self.object.product.name
shop = self.request.shop
try:
shop_product = self.object
orderability_errors.extend(
["%s: %s" % (shop.name, msg.message)
for msg in shop_product.get_orderability_errors(
supplier=None,
quantity=shop_product.minimum_purchase_quantity,
customer=None)])
except ObjectDoesNotExist:
orderability_errors.extend(["%s: %s" % (shop.name, _("Product is not available."))])
context["orderability_errors"] = orderability_errors
context["product_sections"] = []
context["tour_key"] = "product"
context["tour_complete"] = is_tour_complete(get_shop(self.request), "product", user=self.request.user)
product_sections_provides = sorted(get_provide_objects("admin_product_section"), key=lambda x: x.order)
for admin_product_section in product_sections_provides:
if admin_product_section.visible_for_object(self.object.product, self.request):
context["product_sections"].append(admin_product_section)
context[admin_product_section.identifier] = admin_product_section.get_context_data(
self.object.product, self.request
)
return context
开发者ID:ruqaiya,项目名称:shuup,代码行数:31,代码来源:edit.py
示例6: save_form
def save_form(self, form):
self.object = form.save()
contact = self._get_bind_contact()
# only touch in shop staff member if the user is not a superuser
if not getattr(self.object, "is_superuser", False):
shop = get_shop(self.request)
if getattr(self.object, "is_staff", False):
shop.staff_members.add(self.object)
else:
shop.staff_members.remove(self.object)
if contact and not contact.user:
contact.user = self.object
contact.save()
messages.info(self.request, _(u"User bound to contact %(contact)s.") % {"contact": contact})
if getattr(self.object, "is_staff", False) and form.cleaned_data.get("send_confirmation"):
shop_url = "%s://%s/" % (self.request.scheme, self.request.get_host())
admin_url = self.request.build_absolute_uri(reverse("shuup_admin:login"))
send_mail(
subject=_("You've been added as an admin user to %s" % shop_url),
message=NEW_USER_EMAIL_CONFIRMATION_TEMPLATE % {
"first_name": getattr(self.object, "first_name") or getattr(self.object, "username", _("User")),
"shop_url": shop_url,
"admin_url": admin_url,
"username": getattr(self.object, "username") or getattr(self.object.email)
},
from_email=django_settings.DEFAULT_FROM_EMAIL,
recipient_list=[self.object.email]
)
开发者ID:ruqaiya,项目名称:shuup,代码行数:31,代码来源:detail.py
示例7: get_help_blocks
def get_help_blocks(self, request, kind):
if kind == "setup":
shop = request.shop
yield SimpleHelpBlock(
text=_("Add a logo to make your store stand out"),
actions=[{
"text": _("Add logo"),
"url": self.get_model_url(shop, "edit"),
"hash": "#shop-images-section"
}],
icon_url="shuup_admin/img/logo_icon.svg",
done=shop.logo,
required=False
)
shop = get_shop(request)
yield SimpleHelpBlock(
priority=1000,
text=_("Publish your store"),
description=_("Let customers browse your store and make purchases"),
css_class="green ",
actions=[{
"method": "POST",
"text": _("Publish shop"),
"url": reverse("shuup_admin:shop.enable", kwargs={"pk": shop.pk}),
"data": {
"enable": True,
"redirect": reverse("shuup_admin:dashboard")
}
}],
icon_url="shuup_admin/img/publish.png",
done=(not shop.maintenance_mode),
required=False
)
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:__init__.py
示例8: handle_get_folder
def handle_get_folder(self, data):
shop = get_shop(self.request)
try:
folder_id = int(data.get("id", 0))
if folder_id:
folder = _get_folder_query(shop).get(pk=folder_id)
subfolders = folder.get_children().filter(_get_folder_query_filter(shop))
files = _get_file_query(shop, folder)
else:
folder = None
subfolders = _get_folder_query(shop).filter(parent=None)
files = _get_file_query(shop).filter(folder=None)
except ObjectDoesNotExist:
return JsonResponse({
"folder": None,
"error": "Folder does not exist"
})
if self.filter == "images":
files = files.instance_of(Image)
return JsonResponse({"folder": {
"id": folder.id if folder else 0,
"name": get_folder_name(folder),
"files": [_filer_file_to_json_dict(file) for file in files if file.is_public],
"folders": [
# Explicitly pass empty list of children to avoid recursion
_filer_folder_to_json_dict(subfolder, children=())
for subfolder in subfolders.order_by("name")
]
}})
开发者ID:ruqaiya,项目名称:shuup,代码行数:31,代码来源:views.py
示例9: get_queryset
def get_queryset(self):
# get coupons for this shop or for shared shops
queryset = super(CouponEditView, self).get_queryset().filter(shop=get_shop(self.request))
supplier = get_supplier(self.request)
if supplier:
queryset = queryset.filter(supplier=supplier)
return queryset
开发者ID:ruqaiya,项目名称:shuup,代码行数:7,代码来源:_edit.py
示例10: post
def post(self, request):
"""
Create the Script from template directly if the template does not have a bound form.
If the script template has a bound form, redirect to the template configuration view.
If no script template is found, redirect to the script list.
"""
identifier = request.POST.get("id", None)
script_template_class = get_identifier_to_object_map(SCRIPT_TEMPLATES_PROVIDE_CATEGORY).get(identifier)
if script_template_class:
script_template = script_template_class()
# the template has a form for configuration.. lets redirect to the correct view
if script_template.get_form():
return redirect("shuup_admin:notify.script-template-config", id=identifier)
else:
shop = get_shop(request)
script = script_template.create_script(shop)
if script:
script.template = identifier
script.save(update_fields=["template"])
messages.success(request, _("Script created from template!"))
return redirect("shuup_admin:notify.script.list")
else:
messages.error(request, _("Template Script not found!"))
return redirect("shuup_admin:notify.script.list")
开发者ID:ruqaiya,项目名称:shuup,代码行数:30,代码来源:template.py
示例11: save
def save(self, commit=True):
if not self.instance.pk:
self.instance.is_active = True
obj = super(ContactBaseFormMixin, self).save(commit)
shop = get_shop(self.request)
obj.groups = [obj.get_default_group()] + list(self.cleaned_data["groups"])
obj.add_to_shops(shop, list(self.cleaned_data["shops"]))
return obj
开发者ID:ruqaiya,项目名称:shuup,代码行数:8,代码来源:forms.py
示例12: get_context_data
def get_context_data(self, **kwargs):
context = super(CategoryEditView, self).get_context_data(**kwargs)
context["tour_key"] = "category"
context["tour_complete"] = is_tour_complete(get_shop(self.request), "category", user=self.request.user)
if self.object.pk:
context["title"] = self.object.name
return context
开发者ID:ruqaiya,项目名称:shuup,代码行数:8,代码来源:edit.py
示例13: __init__
def __init__(self, **kwargs):
self.request = kwargs.pop("request")
super(GDPRSettingsForm, self).__init__(**kwargs)
shop = get_shop(self.request)
choices = [(p.id, p.title) for p in get_possible_consent_pages(shop)]
self.fields["privacy_policy_page"].choices = choices
self.fields["consent_pages"].required = False
self.fields["consent_pages"].choices = choices
开发者ID:ruqaiya,项目名称:shuup,代码行数:8,代码来源:forms.py
示例14: get_queryset
def get_queryset(self):
"""
Ignore potentially active carts, displaying only those not updated for at least 2 hours.
"""
shop = get_shop(self.request)
cutoff = now() - datetime.timedelta(hours=get_cart_delay_hours(shop))
filters = {"updated_on__lt": cutoff, "product_count__gte": 0, "persistent": False, "shop": shop}
return super(CartListView, self).get_queryset().filter(**filters)
开发者ID:ruqaiya,项目名称:shuup,代码行数:8,代码来源:_list.py
示例15: __init__
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request")
super(TaskForm, self).__init__(*args, **kwargs)
shop = get_shop(self.request)
self.fields["assigned_to"].queryset = Contact.objects.filter(
Q(shops=shop) | Q(id__in=shop.staff_members.values_list("id"))
).distinct()
self.fields["assigned_to"].widget.editable_model = "shuup.Contact"
开发者ID:ruqaiya,项目名称:shuup,代码行数:9,代码来源:edit.py
示例16: get_queryset
def get_queryset(self):
queryset = super(CouponListView, self).get_queryset()
if not self.request.user.is_superuser:
queryset = queryset.filter(shop=get_shop(self.request))
supplier = get_supplier(self.request)
if supplier:
queryset = queryset.filter(supplier=supplier)
return queryset
开发者ID:ruqaiya,项目名称:shuup,代码行数:9,代码来源:_list.py
示例17: get_queryset
def get_queryset(self):
queryset = Contact.objects.all()
limited = (settings.SHUUP_ENABLE_MULTIPLE_SHOPS and settings.SHUUP_MANAGE_CONTACTS_PER_SHOP and
not self.request.user.is_superuser)
if limited:
queryset = queryset.filter(shops=get_shop(self.request))
return queryset
开发者ID:ruqaiya,项目名称:shuup,代码行数:9,代码来源:views.py
示例18: handle_post_rename_file
def handle_post_rename_file(self, data):
shop = get_shop(self.request)
file = _get_file_query(shop).get(pk=data["id"])
if _is_file_shared(file):
message = _("Can not rename shared file.")
return JsonResponse({"success": False, "message": message})
file.name = data["name"]
file.save(update_fields=("name",))
return JsonResponse({"success": True, "message": _("File renamed.")})
开发者ID:ruqaiya,项目名称:shuup,代码行数:10,代码来源:views.py
示例19: handle_post_delete_folder
def handle_post_delete_folder(self, data):
shop = get_shop(self.request)
folder = _get_folder_query(shop).get(pk=data["id"])
if _is_folder_shared(folder):
message = _("Can not delete shared folder.")
return JsonResponse({"success": False, "message": message})
new_selected_folder_id = folder.parent_id
message = delete_folder(folder)
return JsonResponse({"success": True, "message": message, "newFolderId": new_selected_folder_id})
开发者ID:ruqaiya,项目名称:shuup,代码行数:10,代码来源:views.py
示例20: form_valid
def form_valid(self, form):
identifier = form["theme"].cleaned_data["activate"]
data = {
"settings": {
"stylesheet": form["theme"].cleaned_data["selected_style"]
}
}
theme_settings, created = ThemeSettings.objects.get_or_create(
theme_identifier=identifier,
shop=get_shop(self.request)
)
if created:
theme_settings.data = data
theme_settings.save()
else:
theme_settings.update_settings(data["settings"])
set_current_theme(identifier, self.object)
cache.bump_version(get_theme_cache_key(get_shop(self.request)))
开发者ID:ruqaiya,项目名称:shuup,代码行数:19,代码来源:_theme.py
注:本文中的shuup.admin.shop_provider.get_shop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论