Skip to main content

djangomixin

Is a set of utilities to give you advantage on your django development. This utilities can help you to manage and upgrade django application.

Is a open source package that works on top django mainly. Several mixins and snippets is to make django more handy in case of development. Have class based view snippet, date snippet, mail sending snippet, permission snippet and so on.

Installation

The latest version of djangomixin can be installed from PyPI:

pip install djangomixin

Quick use

After install djangomixin you can test some awesome snippet, best example:

filename

from djangomixin import filename

# filename is a simple function to give you actual filename of a source file
my_file_name = filename("C://path/this is file.jpg")

random_string

random_string is a function to give you a lengthy random_string, such as when we need to generate a slug filed over a model we can simply use random_string to generate lengthy random_string

from djangomixin import random_string

slug = models.CharField(max_length=20, default=random_string)

# string length is by default 10, but we can change the length by passing a value in it
slug = models.CharField(max_length=20, default=lambda: random_string(20))

bootstrap_visible_fields

bootstrap_visible_fields is for generating bootstrap field for your form and model form all you need to do just go to your form class then call this function and pass the specific object to it

from django import forms
from djangomixin import bootstrap_visible_fields


class MyModelForm(forms.ModelForm):
  def __init__(self, *args, **kwargs):
      super(MyModelForm, self).__init__(*args, **kwargs)
      bootstrap_visible_fields(self.visible_fields)

RequestAttachMixin

RequestAttachMixin is a class snippet which can be inherit by any class based view. By default class based view have not request object in it. So, when we need to get or verify request we have some problem in the class based view This snippet will attach request object in that class object You can get this request from any of method, we are using get_context_data for example

from djangomixin.class_mixin import RequestAttachMixin


class TestView(RequestAttachMixin):
  template_name = 'home.html'

  def get_context_data(self, *args, **kwargs):
    data = dict(self.request.GET)
    print(data)
    return super(TestView, self).get_context_data(*args, **kwargs)

NextUrlMixin

NextUrlMixin is a class snippet which can be inherit by any class based view. By default class based view have not support next url which declined in the browser path like /?next=/admin/ This snippet will attach get_next_url method to your class object djangomixin will verify the validity of next url, if it secure then it will give you next url path

from djangomixin.class_mixin import NextUrlMixin


class TestView(NextUrlMixin):
  template_name = 'home.html'

  def get_context_data(self, *args, **kwargs):
    next_url = self.get_next_url()
    print(next_url)
    return super(TestView, self).get_context_data(*args, **kwargs)

send_mail

send_mail snippet is to give you nice and pretty good solution for sending mail. You can verify the mail sending for any server including s3 preferable. To send mail we must set some flag to our settings file and call this function with appropriate values

# In your settings, let's add this lines for server configuration

DEFAULT_FROM_EMAIL = "Your default email who will be the sender"
DEFAULT_FROM_SENDER = "Your default name who will be the sender"
USERNAME_SMTP = "Mail server user name"
PASSWORD_SMTP = "Mail server password"
HOST_SMTP = "Mail server host address"
PORT_SMTP = "Mail server host port"

# After adding this lines to your settings, now you can send email

from djangomixin.mail_mixin import send_mail

# send_mail accept at most six parameter, which is your info and body of mailing

send_mail(
  sender="email@example.com",
  sender_name="Test User",
  recipient=None,
  subject='Message From Django Server',
  body_tex='',
  body_html=''
)

last_month_start_end

last_month_start_end is to provide last month start and end day before today To check this snippet work you can just pass datetime for today into it

form djangomixin.date_mixin import last_month_start_end
import datetime

start_end = last_month_start_end(datetime.datetime.now())
print(start_end)

month_data_range

month_data_range is to provide comprehensive month data with all of info Check the output of month_data_range to get and check how this value can help you rustically

from djangomixin.date_mixin import month_data_range

json_data = month_data_range()

# month_data_range have two exceptional parameter which can be more handy for you

# months_ago is by default 4
# include_this_month is by default False

json_data = month_data_range(months_ago=4, include_this_month=True)

allowed_roles

allowed_roles is a fancy function to verify and block access to a view function. Works as decorator in a view function as like other decorator. It usage django permission management for this work. you can pass allowed permission for a user as defined in django documentation for permission verification.

from djangomixin.permission_mixin import allowed_roles

# django permission verification 'module.model_action'
# here action can be view, change, add, delete

@allowed_roles(['store.book_view'])
def book_view(request):
  ....

Author

djangomixin is a open source libraries for Python, Initially developed by Nj Nafir.

Contribute

Support

If you are having issues, please let us know. We have a mailing list located at: njnafir@gmail.com

License

The project is licensed under the MIT license.

Metadata

Release files for djangomixin 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djangomixin 1.0.0
File Size Uploaded Provenance Actions
djangomixin-1.0.0.tar.gz 6.6 kB Without provenance Details for djangomixin-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for djangomixin 1.0.0
File Interpreter ABI Platform Actions
djangomixin-1.0.0-py3-none-any.whl Python 3 none any Details for djangomixin-1.0.0-py3-none-any.whl

Total release size: 14.0 kB

Release files / djangomixin-1.0.0.tar.gz

Download URL djangomixin-1.0.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8fc5389dfe5f52e70373d21a5215223877c8f728337d87c8f2cddc9a091d9a44
BLAKE2b-256 checksum
How to use checksums
1713370edf07b0bda7789c62d35ebe571a75398fa34365fab2d5aee23c22a85e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.6

Release files / djangomixin-1.0.0-py3-none-any.whl

Download URL djangomixin-1.0.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c9aa7c14fbf7e50ddfed96537eec35da2c73c6e2d28a572de9a5a3edf48cd4d
BLAKE2b-256 checksum
How to use checksums
4bb40db276710f24f36e88c3e55ee195073896a647fc21f77a45e5de905e9698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.6

Security for djangomixin 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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