Skip to main content

django-hyperview

Django extensions for Hyperview mobile apps

Installation and Setup

Install with pip

python -m pip install django-hyperview

Configure

Add the app, once installed, to your INSTALLED_APPS

INSTALLED_APPS = [
    ...
    "django_hv",
    ...
]

Optionally, you can add the HyperviewMiddleware middleware to your settings.

MIDDLEWARE = [
    ...
    "django_hv.middleware.HyperviewMiddleware",
]

Usage

xml-based form fields

As with Django, you can dynamically create your xml-based forms with this package.

from .models import Contact

from django_hv.forms import ModelForm
from django_hv import widgets


class ContactForm(ModelForm):
    class Meta:
        model = Contact
        fields = ("first_name", "last_name", "phone_number", "email")
        widgets = {
            "first_name": widgets.TextField(attrs={"placeholder": "First name"}),
            "last_name": widgets.TextField(attrs={"placeholder": "Last name"}),
            "phone_number": widgets.TextField(attrs={"placeholder": "Phone number"}),
            "email": widgets.TextField(attrs={"placeholder": "Email address"}),
        }

In your view you can initiate the form as usual:

def contact_new(request):
    context = {"form": ContactForm(request.POST or None)}
    if request.method == "GET":
        response = render(request, "new.xml", context)
    elif request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            context["saved"] = True
            context["contact"] = form.save()
        response = render(request, "form_fields.xml", context)
    return hv_repond(response)

And the xml template, you can render the form as follows:

{% load hv_tags %}
<view xmlns="https://hyperview.org/hyperview" style="edit-group">
{% if saved %}
  <behavior trigger="load" once="true" action="dispatch-event" event-name="contact-updated" />
  <behavior trigger="load" once="true" action="reload" href="{{ contact.detail_url }}" />
{% endif %}
{% hv_csrf_token request %}
{{ form }}
</view>

Note that you can create a CSRF token if you load the template tags of this package: {% hv_csrf_token request %}. It needs the request as an argument since Django requires that object to create a token.

Hyperview response

You can use this package for your views.

from .models import Contact
from .forms import ContactForm

from django_hv.http import hv_repond


def contact_detail(request, id):
    response = render(request, "show.xml", {"contact": Contact.objects.get(id=id)})
    return hv_repond(response)

def contact_new(request):
    ...
    return HyperviewResponse(request, "new.xml", context={}) 

Check if the request comes from a Hypermedia client

For this to work, you need to add HyperviewMiddleware to MIDDLEWARE.

def contact_detail(request, id):
    template = "show.xml" if request.hv else "show.html"
    response = render(request, template, {"contact": Contact.objects.get(id=id)})
    return hv_repond(response)

The property request.hv checks if the request has a specific header that is passed by the Hypermedia client.

Metadata

Release files for django-hyperview 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-hyperview 0.0.2
File Size Uploaded Provenance Actions
django-hyperview-0.0.2.tar.gz 7.5 kB Without provenance Details for django-hyperview-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-hyperview 0.0.2
File Interpreter ABI Platform Actions
django_hyperview-0.0.2-py3-none-any.whl Python 3 none any Details for django_hyperview-0.0.2-py3-none-any.whl

Total release size: 17.9 kB

Release files / django-hyperview-0.0.2.tar.gz

Download URL django-hyperview-0.0.2.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f88c9003855b4f8093ed38e6a6e161e63d27d477ede26addcb6a9ad7a771432e
BLAKE2b-256 checksum
How to use checksums
431bc6abb94f86fd374ea345de7df90d2ba8227982064bd4054e1faa0c6d977e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/42.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

Release files / django_hyperview-0.0.2-py3-none-any.whl

Download URL django_hyperview-0.0.2-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68fbbe761ab2fc950b9de4c8e2be82dbe7b7467eab5b0e7ab950a99772079c59
BLAKE2b-256 checksum
How to use checksums
5a4ae68aea6ef23636425898b0e8163ecf81da302aba45bc8b352ffe272752e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/42.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

Security for django-hyperview 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page