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.9.0rc11.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

garpix_company-2.9.0rc11-py3-none-any.whl (51.6 kB view details)

Uploaded Python 3

File details

Details for the file garpix_company-2.9.0rc11.tar.gz.

File metadata

  • Download URL: garpix_company-2.9.0rc11.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/7.0.2 pkginfo/1.10.0 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.66.2 CPython/3.8.19

File hashes

Hashes for garpix_company-2.9.0rc11.tar.gz
Algorithm Hash digest
SHA256 094a8c321990fa827fa81a6f113388e2b75b28df098ed3a3df6c3f5545b602a5
MD5 cdd1c7d6097d647fa2550940f7ead2ed
BLAKE2b-256 7f76e8d0b4c2e66f3ff88416d06d22dd076fecb8b11dd059d9fa05a1df3de497

See more details on using hashes here.

File details

Details for the file garpix_company-2.9.0rc11-py3-none-any.whl.

File metadata

  • Download URL: garpix_company-2.9.0rc11-py3-none-any.whl
  • Upload date:
  • Size: 51.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/7.0.2 pkginfo/1.10.0 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.66.2 CPython/3.8.19

File hashes

Hashes for garpix_company-2.9.0rc11-py3-none-any.whl
Algorithm Hash digest
SHA256 f015c283f2da6d0bc0c2e02e9b603b06f227f42ad495e7f70e617b0a18145982
MD5 799e98bdd20d90f9e833b07b68c25f39
BLAKE2b-256 2b748a82a10562adcfb10a52006e2bb9b6212d6d12bff4e98b44085c695e4068

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