當前位置: 首頁>>代碼示例>>Python>>正文


Python shortcuts.render方法代碼示例

本文整理匯總了Python中django.shortcuts.render方法的典型用法代碼示例。如果您正苦於以下問題:Python shortcuts.render方法的具體用法?Python shortcuts.render怎麽用?Python shortcuts.render使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.shortcuts的用法示例。


在下文中一共展示了shortcuts.render方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: delete_product

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def delete_product(request, pk, group):
    from django.db.models import ProtectedError
    product = get_object_or_404(Product, pk=pk)

    if request.method == 'POST':
        try:
            product.delete()
            Inventory.objects.filter(product=product).delete()
            messages.success(request, _("Product deleted"))
        except ProtectedError:
            messages.error(request, _('Cannot delete product'))

        return redirect(list_products, group)

    action = request.path
    return render(request, 'products/remove.html', locals()) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:18,代碼來源:product.py

示例2: choose_product

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def choose_product(request, order_id, product_id=None, target_url="orders-add_product"):
    """
    order_id can be either Service Order or Purchase Order
    """
    data = {'order': order_id}
    data['action'] = request.path
    data['target_url'] = target_url

    if request.method == "POST":
        query = request.POST.get('q')

        if len(query) > 2:
            products = Product.objects.filter(
                Q(code__icontains=query) | Q(title__icontains=query)
            )
            data['products'] = products

        return render(request, 'products/choose-list.html', data)

    return render(request, 'products/choose.html', data) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:22,代碼來源:product.py

示例3: devices

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def devices(request):
    data = prep_view(request)
    data['form'] = DeviceStatsForm()
    start_date = data['initial']['start_date']
    end_date = data['initial']['end_date']

    if request.method == 'POST':
        form = DeviceStatsForm(request.POST)
        if form.is_valid():
            start_date = form.cleaned_data['start_date']
            end_date = form.cleaned_data['end_date']

    cursor  = connection.cursor()
    query = '''SELECT d.description device, count(o) AS orders, count(r) AS repairs 
        FROM servo_device d, servo_order o, servo_repair r, servo_orderdevice od 
        WHERE d.id = od.device_id 
            AND o.id = od.order_id 
            AND r.order_id = o.id
            AND (o.created_at, o.created_at) OVERLAPS (%s, %s)
        GROUP BY d.description''';
    cursor.execute(query, [start_date, end_date])
    data['results'] = cursor.fetchall()
    data['title'] = _('Device statistics')

    return render(request, "stats/devices.html", data) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:27,代碼來源:stats.py

示例4: index

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def index(request):
    ctx = get_context(request)
    cname = os.environ["PORTAL_CNAME"]
    template_dir = get_app_template_dirs("templates/notebooks")[0]
    htmls = os.path.join(template_dir, cname, "*.html")
    ctx["notebooks"] = [
        p.split("/" + cname + "/")[-1].replace(".html", "") for p in glob(htmls)
    ]
    ctx["PORTAL_CNAME"] = cname
    ctx["landing_pages"] = []
    mask = ["project", "title", "authors", "is_public", "description", "urls"]
    client = Client(headers=get_consumer(request))  # sets/returns global variable
    entries = client.projects.get_entries(_fields=mask).result()["data"]
    for entry in entries:
        authors = entry["authors"].strip().split(",", 1)
        if len(authors) > 1:
            authors[1] = authors[1].strip()
        entry["authors"] = authors
        entry["description"] = entry["description"].split(".", 1)[0] + "."
        ctx["landing_pages"].append(
            entry
        )  # visibility governed by is_public flag and X-Consumer-Groups header
    return render(request, "home.html", ctx.flatten()) 
開發者ID:materialsproject,項目名稱:MPContribs,代碼行數:25,代碼來源:views.py

示例5: contribution

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def contribution(request, cid):
    ctx = get_context(request)
    client = Client(headers=get_consumer(request))  # sets/returns global variable
    contrib = client.contributions.get_entry(
        pk=cid, _fields=["id", "identifier"]
    ).result()
    ctx["identifier"], ctx["cid"] = contrib["identifier"], contrib["id"]
    nb = client.notebooks.get_entry(pk=cid).result()  # generate notebook with cells
    ctx["ncells"] = len(nb["cells"])

    if not nb["cells"][-1]["outputs"]:
        try:
            nb = client.notebooks.get_entry(pk=cid).result(
                timeout=1
            )  # trigger cell execution
        except HTTPTimeoutError as e:
            dots = '<span class="loader__dot">.</span><span class="loader__dot">.</span><span class="loader__dot">.</span>'
            ctx["alert"] = f"Detail page is building in the background {dots}"

    ctx["nb"], ctx["js"] = export_notebook(nb, cid)
    return render(request, "contribution.html", ctx.flatten()) 
開發者ID:materialsproject,項目名稱:MPContribs,代碼行數:23,代碼來源:views.py

示例6: upload_gsx_parts

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def upload_gsx_parts(request, group=None):
    from servo.forms.product import PartsImportForm
    form = PartsImportForm()

    data = {'action': request.path}

    if request.method == "POST":

        form = PartsImportForm(request.POST, request.FILES)

        if form.is_valid():
            data = form.cleaned_data
            filename = "servo/uploads/products/partsdb.csv"
            destination = open(filename, "wb+")

            for chunk in data['partsdb'].chunks():
                destination.write(chunk)

            messages.success(request, _("Parts database uploaded for processing"))
            return redirect(list_products)

    data['form'] = form
    return render(request, "products/upload_gsx_parts.html", data) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:25,代碼來源:product.py

示例7: edit_group

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def edit_group(request, group='all'):
    if group == 'all':
        group = CustomerGroup()
    else:
        group = CustomerGroup.objects.get(slug=group)

    title = group.name
    form = GroupForm(instance=group)

    if request.method == "POST":
        form = GroupForm(request.POST, instance=group)
        if form.is_valid():
            group = form.save()
            messages.success(request, _(u'%s saved') % group.name)
            return redirect(index, group.slug)
        messages.error(request, form.errors['name'][0])
        return redirect(index)

    return render(request, "customers/edit_group.html", locals()) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:21,代碼來源:customer.py

示例8: move

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def move(request, pk, new_parent=None):
    """
    Moves a customer under another customer
    """
    customer = get_object_or_404(Customer, pk=pk)

    if new_parent is not None:
        if int(new_parent) == 0:
            new_parent = None
            msg = _(u"Customer %s moved to top level") % customer
        else:
            new_parent = Customer.objects.get(pk=new_parent)
            d = {'customer': customer, 'target': new_parent}
            msg = _(u"Customer %(customer)s moved to %(target)s") % d

        try:
            customer.move_to(new_parent)
            customer.save() # To update fullname
            messages.success(request, msg)
        except Exception as e:
            messages.error(request, e)

        return redirect(customer)

    return render(request, "customers/move.html", locals()) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:27,代碼來源:customer.py

示例9: index

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def index(request):
    """
    /stats/
    """
    data = prep_view(request)
    form = TechieStatsForm(initial=data['initial'])

    if request.method == 'POST':
        form = TechieStatsForm(request.POST, initial=data['initial'])
        if form.is_valid():
            request.session['stats_filter'] = form.serialize()

    data['form'] = form
    return render(request, "stats/index.html", data)


#@cache_page(15*60) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:19,代碼來源:stats.py

示例10: delete_calendar

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def delete_calendar(request, pk):
    calendar = get_object_or_404(Calendar, pk=pk)

    if calendar.user != request.user:
        messages.error(request, _("Users can only delete their own calendars!"))

        return redirect(calendars)

    if request.method == "POST":
        calendar.delete()
        messages.success(request, _('Calendar deleted'))
        return redirect(calendars)

    data = {'title': _("Really delete this calendar?")}
    data['action'] = request.path

    return render(request, "accounts/delete_calendar.html", data) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:19,代碼來源:account.py

示例11: edit_calendar

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def edit_calendar(request, pk=None, view="week"):
    from servo.models.calendar import CalendarForm
    calendar = Calendar(user=request.user)

    if pk:
        calendar = get_object_or_404(Calendar, pk=pk)
        if not calendar.user == request.user:
            messages.error(request, _('You can only edit your own calendar'))
            return redirect(calendars)

    if request.method == "POST":
        form = CalendarForm(request.POST, instance=calendar)

        if form.is_valid():
            calendar = form.save()
            messages.success(request, _("Calendar saved"))
            return redirect(view_calendar, calendar.pk, 'week')

    form = CalendarForm(instance=calendar)

    data = {'title': calendar.title}
    data['form'] = form
    data['action'] = request.path

    return render(request, "accounts/calendar_form.html", data) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:27,代碼來源:account.py

示例12: register

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def register(request):
    """
    New user applying for access
    """
    form = RegistrationForm()
    data = {'title': _("Register")}

    if request.method == 'POST':

        form = RegistrationForm(request.POST)

        if form.is_valid():
            user = User(is_active=False)
            user.email = form.cleaned_data['email']
            user.last_name = form.cleaned_data['last_name']
            user.first_name = form.cleaned_data['first_name']
            user.set_password(form.cleaned_data['password'])
            user.save()

            messages.success(request, _(u'Your registration is now pending approval.'))

            return redirect(login)

    data['form'] = form
    return render(request, 'accounts/register.html', data) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:27,代碼來源:account.py

示例13: find_device

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def find_device(request):
    device = Device(sn=request.GET['sn'])
    device.description = _('Other Device')
    device_form = forms.DeviceForm(instance=device)

    try:
        apple_sn_validator(device.sn)
    except Exception as e:  # not an Apple serial number
        return render(request, "checkin/device_form.html", locals())

    try:
        device = get_device(request, device.sn)
        device_form = forms.DeviceForm(instance=device)
    except GsxError as e:
        error = e

    return render(request, "checkin/device_form.html", locals()) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:19,代碼來源:checkin.py

示例14: status

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def status(request):
    """Check service order status through the checkin."""
    title = _('Repair Status')

    if request.GET.get('code'):
        timeline = []
        form = forms.StatusCheckForm(request.GET)
        if form.is_valid():
            code = form.cleaned_data['code']
            try:
                order = Order.objects.get(code=code)
                status_description = order.get_status_description()
                if Configuration.conf('checkin_timeline'):
                    timeline = order.orderstatus_set.all()
                if order.status is None:
                    order.status_name = _(u'Waiting to be processed')
            except Order.DoesNotExist:
                messages.error(request, _(u'Order %s not found') % code)
            return render(request, "checkin/status-show.html", locals())
    else:
        form = forms.StatusCheckForm()

    return render(request, "checkin/status.html", locals()) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:25,代碼來源:checkin.py

示例15: delete_device

# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import render [as 別名]
def delete_device(request, product_line, model, pk):
    dev = get_object_or_404(Device, pk=pk)

    if request.method == 'POST':
        from django.db.models import ProtectedError
        try:
            dev.delete()
            messages.success(request, _("Device deleted"))
        except ProtectedError:
            messages.error(request, _("Cannot delete device with GSX repairs"))
            return redirect(dev)

        return redirect(index)

    data = {'action': request.path}
    data['device'] = dev

    return render(request, "devices/remove.html", data) 
開發者ID:fpsw,項目名稱:Servo,代碼行數:20,代碼來源:device.py


注:本文中的django.shortcuts.render方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。