дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
Adds a Django Template language: .html/.txt files in a templates folder of a project with manage.py (new [[framework-files]] detection), a Lezer grammar for tags, variables, filters and comments with HTML mounted between them, block folding/indent/matching, {% %} / {{ }} / {# #} pairing, end-tag insertion and completion, per-line {# #} comments, HTML language server and Emmet in the HTML parts, a banner offering the language for HTML files with Django tags elsewhere, a fixture and docs. The built-in HTML syntax check skips Django templates, whose tags the HTML grammar reports as errors.
Refs #2581
Co-authored-by: andreabasile <[email protected]>
36 рядки
1.1 KiB
Python
36 рядки
1.1 KiB
Python
"""Views of the shop: a product list and a product page."""
|
|
|
|
import json # Intentional warning: unused import.
|
|
from dataclasses import dataclass
|
|
from decimal import Decimal
|
|
|
|
from django.http import Http404, HttpRequest, HttpResponse
|
|
from django.shortcuts import render
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Product:
|
|
slug: str
|
|
name: str
|
|
price: Decimal
|
|
tags: tuple[str, ...] = ()
|
|
|
|
|
|
PRODUCTS = [
|
|
Product("espresso", "Espresso", Decimal("1.20"), ("coffee", "hot")),
|
|
Product("cappuccino", "Cappuccino", Decimal("1.60"), ("coffee", "milk")),
|
|
Product("cornetto", "Cornetto", Decimal("1.30")),
|
|
]
|
|
|
|
|
|
def product_list(request: HttpRequest) -> HttpResponse:
|
|
# TODO: paginate once the menu grows.
|
|
return render(request, "shop/product_list.html", {"products": PRODUCTS})
|
|
|
|
|
|
def product_detail(request: HttpRequest, slug: str) -> HttpResponse:
|
|
product = next((p for p in PRODUCTS if p.slug == slug), None) # Set a breakpoint here
|
|
if product is None:
|
|
raise Http404(slug)
|
|
return render(request, "shop/product_list.html", {"products": [product], "single": True})
|