Skip to main content

The easiest way to build views for Django.

Project description

Frontly

The easiest way to build views for Django. Without building any views!

Frontly allows you to make front-end changes to text and images without building custom views or using the admin. It can edit any field the ORM has access to. For example:

{% load frontly %}

<!-- Please see https://htmx.org/docs/#installing about the recommended way to install HTMX -->
<script src="https://unpkg.com/htmx.org@1.9.6" integrity="sha384-FhXw7b6AlE/jyjlZH5iHa/tTe9EpJ1Y55RjcgPbjeWMskSxZt1v9qkxLJWNJaGni" crossorigin="anonymous"></script>

<!-- This replaces {{ author.name }} -->
<h1>{% fr_input request.user instance=author field="name" default="Jordan Doe"%}<h1>

This will display what's in auther.name by default and, if you have the correct permissions, it will allow you to double-click and edit the field.

INSTALLATION 🚀

You can install Frontly by using pip:

$ pip install django-frontly

Then add this to your settings.py:

INSTALLED_APPS = (
    ...
    'frontly',
)

And add this to your main urls.py:

urlpatterns = [
    ...
    path('frontly/', include('frontly.urls', namespace='frontly')),
]

CONFIGURATION ⚙️

You can add these to you settings file.

FRONTLY_CHECK_KILLSWITCH_PERM = True  # default

If FRONTLY_CHECK_KILLSWITCH_PERM is True (default), it will check to see if the user has the permission frontly.frontly_killswitch. If the permission is missing, they will not be able to make changes in the front-end.

You will want to temporarily set to False while testing only.

By default all input is sanitized using nh3. You can disable this by settings FRONTLY_SANITIZE to False in your settings.py.

USAGE

Using Frontly in your existing application is designed to be very simple. It's template tags are designed to be a drop-in replacement, where you would normally output the context variable in your template.

Two things to keep in mind are:

  • Always include HTMX in your template. You can do this in a base template if you are using it everywhere.
  • Always include {% load frontly %} to get access to the frontly tags.

The template tags currently available are: fr_input, fr_textarea, fr_img. PRs for additional editing widgets are welcome.

EXAMPLES

{% fr_img request.user instance=user_profile field="profile_pic" class="border-radius" alt=user_profile.name default=user_profile.get_profile_pic_url %}

fr_img example:

  • request.user - used to check permissions.
  • instance - the django model instance you are working on.alt
  • field - the name of the field within the model. Note that you can have a JSONField and refer to a value deep within the json. i.e. user.misc_json.key
  • default - A default value to display if the field is null.

Anything else passed to the template tag will passed directly to the html field. In this example class is passed directly to the field.

SECURITY

Row level security is handled by model_instance.frontly_permission_check(). Returning True will allow the editing to happen.

Add this to your models:

    def frontly_permission_check(self, user):
        """ Check if a certain user has permission to do this.
        """
        return self.user == user

FEATURES

  • Allow for simple front-end editing.
  • Built-in support for input, textarea and image types.
  • Ability to customize additional editor types.
  • Row level security

CONTRIBUTING

We welcome PRs for new editor types and new features. If you get stuck, please open an issue so that we can improve the documentation.

If you find a bug :bug:, please open a bug report. If you have an idea for an improvement or new feature :rocket:, please open a feature request.

AUTHORS & ACKNOWLEDGEMENTS

  • Ed Menendez
  • The HTMX Project
  • Trix Project

LICENSE

This project is licensed under the MIT License

MIT License

Copyright (c) 2023 Ed Menendez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-frontly-1.0.4.tar.gz (128.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_frontly-1.0.4-py3-none-any.whl (134.0 kB view details)

Uploaded Python 3

File details

Details for the file django-frontly-1.0.4.tar.gz.

File metadata

  • Download URL: django-frontly-1.0.4.tar.gz
  • Upload date:
  • Size: 128.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for django-frontly-1.0.4.tar.gz
Algorithm Hash digest
SHA256 a9a8346f9dc5d87dedc0fffe9a42fd4eca62dd901323767db847a90774b766cf
MD5 0e9e98d18b8bf8a0da62f249d7591b2c
BLAKE2b-256 2d75d5768f5cc14e35333ca83cbee5bc289a69415bcd1cd39e5c22727bcabfb8

See more details on using hashes here.

File details

Details for the file django_frontly-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: django_frontly-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 134.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for django_frontly-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 29bcbdb1a53b1b41f3e74d02ce5698c37d08509f3b963e3221bd9b491a17065f
MD5 a012b0bd88c47ae55041fa13b54aa0c7
BLAKE2b-256 69baf6d6bccca3e8e84bfd129253abb1db815c995682d74048a014fdc2855a04

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page