Skip to main content

Build Status Latest Version Coverage Status

This gem 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.

Add this line to your application’s Gemfile:

pip install --upgrade sweetify

Then you have to add sweetify to your django apps:

INSTALLED_APPS = [
    ...
    'sweetify'
]

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')

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('/')

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)

Contributing

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

Download files

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

Source Distribution

sweetify-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

sweetify-1.0.0-py2.py3-none-any.whl (9.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sweetify-1.0.0.tar.gz.

File metadata

  • Download URL: sweetify-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sweetify-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0dfb471bdee8237ebfd80220c396039ff3af4bcb55c49b11c5178dabaabe1fa7
MD5 21cf3a1f0a771f15dbfec466f5694c83
BLAKE2b-256 5f4edd2fe5b6d742e05dbb88fd6688e91c9743ce751d080e1a7ce7f7f6042fc1

See more details on using hashes here.

File details

Details for the file sweetify-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sweetify-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 90dc047e85ea5ec0c031e80492343afd1fd0317ff45e7bc13d725768553bf2f0
MD5 7aa6a347f39243ca291506dbc77e3120
BLAKE2b-256 a1dbd2875ead7e3d28054ca64e6d79bebb585779dbcaec0df9a4e6b5a995a1c9

See more details on using hashes here.

Release history Release notifications | RSS feed

2.3.1

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.0

2 files

1.0.3

2 files

1.0.1

2 files

This release

1.0.0 This release

2 files

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