Skip to main content

No project description provided

Project description

Garpix Company

Company module for Django/DRF projects.

Quickstart

Install with pip:

pip install garpix_company

Add the garpix_company to your INSTALLED_APPS:

# settings.py

# ...
INSTALLED_APPS = [
    # ...
    'garpix_company',
]

and to migration modules:

# settings.py

# ...
MIGRATION_MODULES = {
    'garpix_company': 'app.migrations.garpix_company',
}

Add to urls.py:

# ...
urlpatterns = [
    # ...
    # garpix_company
    path('', include(('garpix_company.urls', 'garpix_company'), namespace='garpix_company')),

]

Add Company model to your project using abstract AbstractCompany from the model:

from garpix_company.models import AbstractCompany


class Company(AbstractCompany):
    pass

Add UserCompanyRole model to your project using abstract AbstractUserCompanyRole from the model:

from garpix_company.models import AbstractUserCompanyRole


class UserCompanyRole(AbstractUserCompanyRole):
    pass

Add GARPIX_COMPANY_MODEL, GARPIX_USER_COMPANY_MODEL and GARPIX_COMPANY_ROLE_MODEL to settings.py:

# settings.py

GARPIX_COMPANY_MODEL = 'app.Company'
GARPIX_COMPANY_ROLE_MODEL = 'app.UserCompanyRole'
GARPIX_USER_COMPANY_MODEL = 'garpix_company.UserCompany'

Use CompanyAdmin as base in your admin panel:

from django.contrib import admin

from app.models import Company
from garpix_company.admin import CompanyAdmin


@admin.register(Company)
class CompanyAdmin(CompanyAdmin):
    pass

Invite and create user

You can add fields to company_invite/create_and_invite endpoint.

To do it override CreateAndInviteToCompanySerializer by adding field and add it to settings:

# settings.py

GARPIX_COMPANY_CREATE_AND_INVITE_SERIALIZER = 'app.serializers.CustomInviteCompanySerializer'
# app.serializers.py

from rest_framework import serializers

from garpix_company.serializers import CreateAndInviteToCompanySerializer


class CustomInviteCompanySerializer(CreateAndInviteToCompanySerializer):
    username = serializers.CharField(write_only=True)

    class Meta(CreateAndInviteToCompanySerializer.Meta):
        fields = CreateAndInviteToCompanySerializer.Meta.fields + ('username',)

You also can override UserSerializer and CompanyRoleSerializer to add custom fields to user and role fields of /company/{pk}/user/ endpoints:

# settings.py

GARPIX_COMPANY_USER_SERIALIZER = 'app.serializers.UserSerializer'
GARPIX_COMPANY_ROLE_SERIALIZER = 'app.serializers.CompanyRoleSerializer'

You can also set GARPIX_COMPANY_INVITE_NOT_USERS setting to True (False is default) to allow to invite not registered users

Companies count limit

If you need to add some limitations on companies count the user can be a part of, you can override check_user_companies_limit class method of Company class:

from garpix_company.models import AbstractCompany, get_user_company_model


class Company(AbstractCompany):

    @classmethod
    def check_user_companies_limit(cls, user):
        UserCompany = get_user_company_model()
        return UserCompany.objects.filter(user=user).count() < 1

See garpix_company/tests/test_company.py for examples.

Changelog

Смотри CHANGELOG.md.

Contributing

Смотри CONTRIBUTING.md.

License

MIT


Developed by Garpix / https://garpix.com

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

garpix_company-2.8.3.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

garpix_company-2.8.3-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file garpix_company-2.8.3.tar.gz.

File metadata

  • Download URL: garpix_company-2.8.3.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.2 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.9

File hashes

Hashes for garpix_company-2.8.3.tar.gz
Algorithm Hash digest
SHA256 914d281ce46c58a78170fb8c57878c0a7681320525bf87d9994ba230b9e78abf
MD5 41d03d62b7bc76ec639d32cfd99df9ad
BLAKE2b-256 f118bd533daef09e5f1fb3e123a0a8e6cf1a1dfba9cae05f9f565d49eac4f5e2

See more details on using hashes here.

File details

Details for the file garpix_company-2.8.3-py3-none-any.whl.

File metadata

  • Download URL: garpix_company-2.8.3-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/6.0.0 pkginfo/1.9.6 requests/2.28.2 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.9

File hashes

Hashes for garpix_company-2.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ffcd67b7de4b0672d0d8fb17596d0e4f93b2fa76b4756aee496b6f57cf38792c
MD5 034b8158a663d8f76f94b3125d41d917
BLAKE2b-256 a9f31f22bc43a09b7b66c68e4ddbb12f26f3963e830102fd764b17505628c310

See more details on using hashes here.

Supported by

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