{"id":22396977,"url":"https://github.com/atrox/sweetify-django","last_synced_at":"2025-05-12T14:48:03.634Z","repository":{"id":24870094,"uuid":"102643622","full_name":"Atrox/sweetify-django","owner":"Atrox","description":"SweetAlert integration for Django","archived":false,"fork":false,"pushed_at":"2023-04-21T21:51:48.000Z","size":107,"stargazers_count":56,"open_issues_count":7,"forks_count":22,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-04T00:35:05.379Z","etag":null,"topics":["django","messages","python","python3","sweetalert","sweetalert2"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Atrox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-06T18:25:51.000Z","updated_at":"2025-03-20T14:54:18.000Z","dependencies_parsed_at":"2024-06-18T21:21:22.807Z","dependency_job_id":"bba42791-4c46-4cad-b365-51a1542abb88","html_url":"https://github.com/Atrox/sweetify-django","commit_stats":{"total_commits":35,"total_committers":10,"mean_commits":3.5,"dds":0.5428571428571429,"last_synced_commit":"293fe5f38f1d25cbaa271362901eb9bab65a6172"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atrox%2Fsweetify-django","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atrox%2Fsweetify-django/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atrox%2Fsweetify-django/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atrox%2Fsweetify-django/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Atrox","download_url":"https://codeload.github.com/Atrox/sweetify-django/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253758203,"owners_count":21959547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","messages","python","python3","sweetalert","sweetalert2"],"created_at":"2024-12-05T06:10:04.900Z","updated_at":"2025-05-12T14:48:03.608Z","avatar_url":"https://github.com/Atrox.png","language":"Python","readme":"# Sweetify - SweetAlert for Django\n\n[![Build Status](https://img.shields.io/travis/Atrox/sweetify-django.svg?style=flat-square)](https://travis-ci.org/Atrox/sweetify-django)\n[![Latest Version](https://img.shields.io/pypi/v/sweetify.svg?style=flat-square)](https://pypi.python.org/pypi/sweetify)\n[![Coverage Status](https://img.shields.io/coveralls/Atrox/sweetify-django.svg?style=flat-square)](https://coveralls.io/r/Atrox/sweetify-django)\n\n**Sweetify** allows you to use [SweetAlert](http://t4t5.github.io/sweetalert/) or [SweetAlert2](https://github.com/limonte/sweetalert2) for your temporary messages.\n_See the examples below, to see how to use this library_\n\n## Installation\n\n**Note: This package does not provide the client-side files of SweetAlert. You have to provide them yourself.**\n\nInstall the latest version with `pip`:\n\n```bash\npip install --upgrade sweetify\n```\n\nThen you have to add `sweetify` to your django apps:\n\n```python\nINSTALLED_APPS = [\n    ...\n    'sweetify'\n]\n```\n\nNext up you have to specify, in your settings, which library you are using (SweetAlert or SweetAlert2):\n\n```python\n# possible options: 'sweetalert', 'sweetalert2' - default is 'sweetalert2'\nSWEETIFY_SWEETALERT_LIBRARY = 'sweetalert2'\n```\n\nNext add the following lines to the bottom of your layout/base template:\n\n```jinja\n...\n\n{% load sweetify %}\n{% sweetify %}\n\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Usage\n\nYou can now easily create alerts in your views with any of the following methods provided by **Sweetify**:\n\n```python\nimport sweetify\n\n# Base method with no type specified\nsweetify.sweetalert(self.request, 'Westworld is awesome', text='Really... if you have the chance - watch it!', persistent='I agree!')\n\n# Additional methods with the type already defined\nsweetify.info(self.request, 'Message sent', button='Ok', timer=3000)\nsweetify.success(self.request, 'You successfully changed your password')\nsweetify.error(self.request, 'Some error happened here - reload the site', persistent=':(')\nsweetify.warning(self.request, 'This is a warning... I guess')\n```\n\nWe also support toast messages _(SweetAlert2 only)_\n\n```python\nimport sweetify\n\n# Base method, default icon is set to success\nsweetify.toast(self.request, 'Cheers to new toast')\n\nsweetify.toast(self.request, 'Oops, something went wrong !', icon=\"error\", timer=3000)\nsweetify.toast(self.request, 'Persistent toast that only goes away once clicked', icon='warning', persistent=\"Bye toast!\")\n```\n\nAdditionally, 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:\n\n```python\nimport sweetify\n\n# Call two consecutive alerts (args1 is the options dict for the first alert and args2 the one for the second alert):\nsweetify.multiple(self.request, args1, args2)\n\n# Call five consecutive alerts:\nsweetify.multiple(self.request, args1, args2, args3, args4, args5)\n```\n\n## Example Usage\n\n```python\nimport sweetify\n\ndef test_view(request):\n    sweetify.success(request, 'You did it', text='Good job! You successfully showed a SweetAlert message', persistent='Hell yeah')\n    return redirect('/')\n```\n\nExample usage for multiple alerts:\n\n```python\nimport sweetify\n\ndef test_view(request):\n    args1 = dict(title='Test1', icon='info', text=\"Text placeholder1\", button=\"Next\")\n    args2 = dict(title='Test2', icon='success', text=\"Text placeholder2\", timer=5000, timerProgressBar='true', persistent=\"Close\")\n    sweetify.multiple(request, args1, args2)\n    return redirect('/')\n```\n\n## Replacement for SuccessMessageMixin\n\nSweetify includes a drop-in replacement for `SuccessMessageMixin`.\nJust replace the Django mixin with Sweetify's `SweetifySuccessMixin` and you are good to go.\n\n```python\nfrom sweetify.views import SweetifySuccessMixin\n\nclass TestUpdateView(SweetifySuccessMixin, UpdateView):\n    model = TestModel\n    fields = ['text']\n    success_message = 'TestModel successfully updated!'\n```\n\n## Options\n\n**By default, all alerts will dismiss after a sensible default number of seconds.**\n\nDefault options set by **Sweetify**:\n\n```python\nsweetify.DEFAULT_OPTS = {\n    'showConfirmButton': False,\n    'timer': 2500,\n    'allowOutsideClick': True,\n    'confirmButtonText': 'OK',\n}\n```\n\nThe following special options provided by **Sweetify** are available:\n\n```python\n# Shows the alert with a button, but will still close automatically\nsweetify.sweetalert(self.request, 'Title', button=True)\nsweetify.sweetalert(self.request, 'Title', button='Awesome!') # Custom text for the button\n\n# Shows the alert with a button and only closes if the button is pressed\nsweetify.sweetalert(self.request, 'Title', persistent=True)\nsweetify.sweetalert(self.request, 'Title', persistent='Awesome!') # Custom text for the button\n```\n\nYou also can use any other available option that [SweetAlert accepts](http://t4t5.github.io/sweetalert/):\n\n```python\nsweetify.info(self.request, 'Sweet!', text='Here is a custom image', imageUrl='images/thumbs-up.jpg', timer=5000)\n```\n\nIf you use [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) you can use the optional `nonce` parameter on the `sweetify` tag:\n\n```jinja\n{% load sweetify %}\n\n\u003c!-- static nonce --\u003e\n{% sweetify nonce=\"XYZ\" %}\n\n\u003c!-- from request --\u003e\n{% sweetify nonce=request.csp_nonce %}\n```\n\n## Development\n\nUse the `Makefile`to execute common tasks:\n\n- Install dependencies\n\n```shell\n$ make install\n```\n\n- Run all tests\n\n```shell\n$ make test\n```\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/atrox/sweetify-django/issues)\n- Fix bugs and [submit pull requests](https://github.com/atrox/sweetify-django/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatrox%2Fsweetify-django","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatrox%2Fsweetify-django","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatrox%2Fsweetify-django/lists"}