Giter Site home page Giter Site logo

okasen / django-profanity-filter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from reconcubed/django-profanity-filter

0.0 0.0 0.0 18 KB

Django profanity template filter and validators

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

django-profanity-filter's Introduction

Django Profanity Filter

PyPI license PyPI PyPI - Python Version PyPI - Django Version made-with-python

Django Profanity Filter is a simple Django app that introduces a range of template tags and filters and model validators that remove or censor inappropriate language.

Installation

  1. Install via pip
$ pip install django-profanity-filter
  1. Add 'profanity', to your INSTALLED_APPS in settings.py
INSTALLED_APPS = (
...
'profanity',
...
)

Usage

Template Tags

At the top of every template you wish to use profanity filters and tags on, make sure to load the profanity tags.

...
{% load profanity %}
...
Censor Filter
Example
{% with string='You are a bitch!' %}
{{ string|censor }}
{% endwith %}

The output will be You are a *****!, instead of You are a bitch!.

Is Profane Tag
Example
{% with string='You are a bitch!' %}
{{ string|is_profane }}
{% endwith %}

The output will be True, since the string contains profanity.

Validators

Is Profane Validator
Example
from profanity.validators import validate_is_profane

class Post(models.Model):
    post = models.TextArea(max_length=150, validators=[validate_is_profane])

You can also now validate text within unbroken strings, i.e. strings with no spaces in them (stringswithnospacesinthem). To do so, use the validate_is_profane_nospace validator as shown below:

from profanity.validators import validate_is_profane_nospace

class Post(models.Model):
    post = models.TextArea(max_length=150, validators=[validate_is_profane_nospace])

Because there are sometimes profane words nested within safe words (e.g. semen in basement), this validator also uses a "good list" of words that will trigger false positives. If you notice that a word is being blocked from use due to it triggering a false positive, simply add the word to goodlist.txt

TODO

Template Tags

  • Basic filter
  • Advanced filter
    • Keyword argument for custom word filter

Validators

  • Basic Censorship Validator
  • Nospace Profanity Validator (for usernames and other unbroken strings)
  • Advanced validator - perhaps with the ability to find common morphs of words

django-profanity-filter's People

Contributors

reconcubed avatar okasen avatar example123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.