All Projects → Atrox → sweetify-django

Atrox / sweetify-django

Licence: BSD-3-Clause license
SweetAlert integration for Django

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to sweetify-django

Sweetalert2
A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.
Stars: ✭ 13,929 (+30180.43%)
Mutual labels:  sweetalert, sweetalert2
Razor.SweetAlert2
A Razor class library for interacting with SweetAlert2
Stars: ✭ 98 (+113.04%)
Mutual labels:  sweetalert, sweetalert2
php-flasher
🔔 Flasher is a powerful and flexible flash notifications system for PHP, Laravel, Symfony
Stars: ✭ 68 (+47.83%)
Mutual labels:  sweetalert, sweetalert2
Backgroundtask
An infinite backgroundTask based on playing blank audio file ...
Stars: ✭ 122 (+165.22%)
Mutual labels:  messages
Google Messages For Desktop
A "native-like" OS X, Windows, & Linux desktop app for Google Messages
Stars: ✭ 140 (+204.35%)
Mutual labels:  messages
yii2-sweet-submit
sweet sumit using sweetalert
Stars: ✭ 26 (-43.48%)
Mutual labels:  sweetalert
flasher
A powerful and flexible flash notifications system for PHP
Stars: ✭ 46 (+0%)
Mutual labels:  sweetalert2
Mini Toastr
Small non-blocking notification library. No dependencies
Stars: ✭ 94 (+104.35%)
Mutual labels:  messages
sweetalert
Laravel 5 Package for SweetAlert2. Use this package to easily show sweetalert2 prompts in your laravel app.
Stars: ✭ 28 (-39.13%)
Mutual labels:  sweetalert2
Webpack Messages
Beautifully format Webpack messages throughout your bundle lifecycle(s)!
Stars: ✭ 238 (+417.39%)
Mutual labels:  messages
Sweetalert
A beautiful replacement for JavaScript's "alert"
Stars: ✭ 21,871 (+47445.65%)
Mutual labels:  sweetalert
Extract React Intl Messages
extract react intl messages
Stars: ✭ 174 (+278.26%)
Mutual labels:  messages
Laraflash
⚡ Flash messages on steroids.
Stars: ✭ 150 (+226.09%)
Mutual labels:  messages
Telegram Forward Bot
Simple Telegram Bot for forwarding messages easily between various related channels and groups.
Stars: ✭ 132 (+186.96%)
Mutual labels:  messages
qless-php
PHP Bindings for qless
Stars: ✭ 25 (-45.65%)
Mutual labels:  messages
Nsaga
Simple Saga Management library for .Net
Stars: ✭ 112 (+143.48%)
Mutual labels:  messages
nmea msgs
nmea_msgs is a ROS package containing messages related to the NMEA standard
Stars: ✭ 21 (-54.35%)
Mutual labels:  messages
catchr
catchr: Flexible, useful tools for dealing with conditions in R, for new users and veterans
Stars: ✭ 17 (-63.04%)
Mutual labels:  messages
BluetoothHelper
Bluetooth helper Java class
Stars: ✭ 13 (-71.74%)
Mutual labels:  messages
Stream Chat Android
Stream Chat official Android SDK. The tutorial covers how to build your own chat experience using either Java or Kotlin.
Stars: ✭ 165 (+258.7%)
Mutual labels:  messages

Sweetify - SweetAlert for Django

Build Status Latest Version Coverage Status

Sweetify allows you to use SweetAlert or SweetAlert2 for your temporary messages. See the examples below, to see how to use this library

Installation

Note: This package does not provide the client-side files of SweetAlert. You have to provide them yourself.

Install the latest version with pip:

pip install --upgrade sweetify

Then you have to add sweetify to your django apps:

INSTALLED_APPS = [
    ...
    'sweetify'
]

Next up you have to specify, in your settings, which library you are using (SweetAlert or SweetAlert2):

# possible options: 'sweetalert', 'sweetalert2' - default is 'sweetalert2'
SWEETIFY_SWEETALERT_LIBRARY = 'sweetalert2'

Next add the following lines to the bottom of your layout/base template:

...

{% load sweetify %}
{% sweetify %}

</body>
</html>

Usage

You can now easily create alerts in your views with any of the following methods provided by Sweetify:

import sweetify

# Base method with no type specified
sweetify.sweetalert(self.request, 'Westworld is awesome', text='Really... if you have the chance - watch it!', persistent='I agree!')

# Additional methods with the type already defined
sweetify.info(self.request, 'Message sent', button='Ok', timer=3000)
sweetify.success(self.request, 'You successfully changed your password')
sweetify.error(self.request, 'Some error happened here - reload the site', persistent=':(')
sweetify.warning(self.request, 'This is a warning... I guess')

We also support toast messages (SweetAlert2 only)

import sweetify

# Base method, default icon is set to success
sweetify.toast(self.request, 'Cheers to new toast')

sweetify.toast(self.request, 'Oops, something went wrong !', icon="error", timer=3000)
sweetify.toast(self.request, 'Persistent toast that only goes away once clicked', icon='warning', persistent="Bye toast!")

Additionally, you can issue multiple alerts without reloading the page ONLY if you are using SweetAlerts 2. To do so, you must define your options in a dictionary:

import sweetify

# Call two consecutive alerts (args1 is the options dict for the first alert and args2 the one for the second alert):
sweetify.multiple(self.request, args1, args2)

# Call five consecutive alerts:
sweetify.multiple(self.request, args1, args2, args3, args4, args5)

Example Usage

import sweetify

def test_view(request):
    sweetify.success(request, 'You did it', text='Good job! You successfully showed a SweetAlert message', persistent='Hell yeah')
    return redirect('/')

Example usage for multiple alerts:

import sweetify

def test_view(request):
    args1 = dict(title='Test1', icon='info', text="Text placeholder1", button="Next")
    args2 = dict(title='Test2', icon='success', text="Text placeholder2", timer=5000, timerProgressBar='true', persistent="Close")
    sweetify.multiple(request, args1, args2)
    return redirect('/')

Replacement for SuccessMessageMixin

Sweetify includes a drop-in replacement for SuccessMessageMixin. Just replace the Django mixin with Sweetify's SweetifySuccessMixin and you are good to go.

from sweetify.views import SweetifySuccessMixin

class TestUpdateView(SweetifySuccessMixin, UpdateView):
    model = TestModel
    fields = ['text']
    success_message = 'TestModel successfully updated!'

Options

By default, all alerts will dismiss after a sensible default number of seconds.

Default options set by Sweetify:

sweetify.DEFAULT_OPTS = {
    'showConfirmButton': False,
    'timer': 2500,
    'allowOutsideClick': True,
    'confirmButtonText': 'OK',
}

The following special options provided by Sweetify are available:

# Shows the alert with a button, but will still close automatically
sweetify.sweetalert(self.request, 'Title', button=True)
sweetify.sweetalert(self.request, 'Title', button='Awesome!') # Custom text for the button

# Shows the alert with a button and only closes if the button is pressed
sweetify.sweetalert(self.request, 'Title', persistent=True)
sweetify.sweetalert(self.request, 'Title', persistent='Awesome!') # Custom text for the button

You also can use any other available option that SweetAlert accepts:

sweetify.info(self.request, 'Sweet!', text='Here is a custom image', imageUrl='images/thumbs-up.jpg', timer=5000)

If you use CSP you can use the optional nonce parameter on the sweetify tag:

{% load sweetify %}

<!-- static nonce -->
{% sweetify nonce="XYZ" %}

<!-- from request -->
{% sweetify nonce=request.csp_nonce %}

Development

Use the Makefileto execute common tasks:

  • Install dependencies
$ make install
  • Run all tests
$ make test

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].