Skip to main content

My app description

Project description

Brain Utils

Brain Utils is a Django app to let developers do not repeat same initial code for commons utilities. For example configuration system values in database, configurable messages with traduction, stantard mixins for models and admins, etc.

Quick start

  1. Install:

    pip install django-brain-utils

  2. Add "brainutils" to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [ ... 'brainutils', # Before allauth ... ]

  3. To start you can add a configurable message in your home page, example:

    {% load butils %}

    {% display_message request 'home.welcome' %}

  4. Run python manage.py migrate to create the brainutils models.

  5. Start the development server, visit http://127.0.0.1:8000 to watch first message and then go http://localhost:8000/admin/brainutils/message/ to edit the created message, you may set there the message you want all times you need (to refressh changes you need to restart your webserver Apache, Nginx, etc). Is easy and you got a total control for each message and it traduction

More utilities

Configuration variables:

You can set and use in your code a configuration variable very easy like this:

from brainutils import configuration

token = configuration.get_value('api.some.token','HEREYOURINITIALTOKENVALUE') max_items_per_page = configuration.get_integer('commons.pagination.maxitems','10')

Then you may set a new value whenever you whant in http://localhost:8000/admin/brainutils/configuration/. Again you need to restart your webserver to refresh changes

Model standart base fields:

`from brainutils import mixins

class MyModel(mixins.AuditMixin):

field1 = models.TextField(null=True, blank=True)
field2 = models.TextField(null=True, blank=True)`

Then you have this fields and you may use like you want: creation_date, modification_date, creation_user, modification_user, status

Extra Models Administrator Skills

If you need to interact with your model administrator with extra tags or actions you can use something like this:

`class MyModelAdmin(mixadmin.ModelAdminMixin):

list_display = ('field1', 'field2', 'modification_date', 'extra_actions')

def myaction_view(self, request, id):
    try:
        obj = models.MyModel.objects.get(pk = id)
        success = obj.do_action()
        if success:
            return self.response_view(request, True, 'myaction_view', 'OK')
        else:
            return self.response_view(request, False, 'myaction_view', 'FAIL')
    except Exception as e:
        return self.response_view(request, False, 'myaction_view', str(e))

def get_specific_dual_methods(self, obj):
    return [
        {'name':'actionname', 'activation':True, 'color':self.ENABLED_COLOR, 
        'myaction_view':self.myaction_view},
    ]`

Language Manager

Youre application may needs to be multilanguage, theres an easy way with Brain Utils, just set in your code:

`from brainutils import messages

def my_view(request):

current_language = messages.languages.get_language(request)

# Do whatever you want with language object

# You may change the current language online in each moment if you need

messages.languages.change_language(request,'english')`

In templates:

{% for l in LANGUAGES %} {{l.title}} {% endfor %}

Then you may set a new language value whenever you whant in http://localhost:8000/admin/brainutils/language/.

Customers Accounts

Brainutils gives you an standard login, signup and more functionalities for customers in your application.

To customize messages and else, copy our templates/account/ folder and change there whatever you want. You may reuse a lot of funcionality inside there if your application web structure is similar. We use bootstrap as this:

Code Generation

With Django Brain Utils you can generate repetitive code, as the Model Admins, for that objetive we have a console, you can run the console from this command:

./manage.py codegen

And this menu will be displayed:

Welcome to Brain Utils


BRAIN UTILS GENERATOR What we gonna do?:

  1. Generate Admins
  2. Generate URLs- Views
  3. Generate Signup - Login
  4. Exit

Select and option[and press ENTER]:

By the moment with just try with option 1, is very intuitive and easy to generate admins code.

Project details


Download files

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

Source Distribution

django_brain_utils-0.2.5.tar.gz (44.4 kB view details)

Uploaded Source

File details

Details for the file django_brain_utils-0.2.5.tar.gz.

File metadata

  • Download URL: django_brain_utils-0.2.5.tar.gz
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.11

File hashes

Hashes for django_brain_utils-0.2.5.tar.gz
Algorithm Hash digest
SHA256 33fad95150cf8d7054b942ecbbef699182569def0906a4e7e0c729f91c96d756
MD5 e2cdd48b3c80711dfea683f829840bec
BLAKE2b-256 7112410b5a594af249194b80f1b568b7d609803777dd6030e04f312b21ea2b66

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page