Metadata-Version: 2.0
Name: sweetify
Version: 1.0.0
Summary: TODO: Placeholder - Description
Home-page: https://github.com/atrox/sweetify-django
Author: Atrox
Author-email: mail@atrox.me
License: ISC
Description-Content-Type: UNKNOWN
Platform: any
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries :: Python Modules

Sweetify - SweetAlert for Django
================================

|Build Status| |Latest Version| |Coverage Status|

This gem allows you to use
`SweetAlert <http://t4t5.github.io/sweetalert/>`__ or
`SweetAlert2 <https://github.com/limonte/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:

.. code:: bash

    pip install --upgrade sweetify

Then you have to add ``sweetify`` to your django apps:

.. code:: python

    INSTALLED_APPS = [
        ...
        'sweetify'
    ]

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

.. code:: html

    ...

    {% load sweetify %}
    {% sweetify %}

    </body>
    </html>

Usage
-----

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

.. code:: python

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

.. code:: python

    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.

.. code:: python

    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**:

.. code:: python

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

The following special options provided by **Sweetify** are available:

.. code:: python

    # 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 <http://t4t5.github.io/sweetalert/>`__:

.. code:: python

    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:

-  `Report bugs <https://github.com/atrox/sweetify-django/issues>`__
-  Fix bugs and `submit pull
   requests <https://github.com/atrox/sweetify-django/pulls>`__
-  Write, clarify, or fix documentation
-  Suggest or add new features

.. |Build Status| image:: https://img.shields.io/travis/Atrox/sweetify-django.svg?style=flat-square
   :target: https://travis-ci.org/Atrox/sweetify-django
.. |Latest Version| image:: https://img.shields.io/pypi/v/sweetify.svg?style=flat-square
   :target: https://pypi.python.org/pypi/sweetify
.. |Coverage Status| image:: https://img.shields.io/coveralls/Atrox/sweetify-django.svg?style=flat-square
   :target: https://coveralls.io/r/Atrox/sweetify-django


