Skip to main content

The module contains several features that provide functionality for various aspects of your application. Here is a breakdown of each feature:

  1. Activity Events:

    • SqlAlchemy events are used to log user activity logs to Elasticsearch.
    • The dcg_service.core.events.py file contains more details about these events.
    • It includes SqlAlchemy model events such as before_create, after_create, before_update, and after_update.
    • The module includes an ActivityEvent class and registers the event class in the __init__.py file.
    • You can exclude specific model names from activity events by adding them to the EXCLUDE_MODEL_EVENTS list in the settings.py file.
    • You can add events to log activity by specifying them in the EVENTS list in the settings.py file.
    • The model file path can be specified using the APP_MODELS variable in the settings.py file.
  2. Authentication/Permission:

    • User authentication is handled using JWT tokens.
    • You need to set the signing key and JWT algorithms in your settings file.
    • The is_authenticated function from dcg_service.core.permissions can be used as a decorator to enforce authentication on API views.
  3. Service Cache:

    • The module includes a ServicePrice class that fetches service fee structure from an Elasticsearch index.
    • To retrieve service fee details, you can call ServicePrice(service_id, units).get_fee_details().
    • The get_fee_details function has an optional include_tax parameter to include/exclude tax details.
    • Additionally, you can use get_coupon_details to retrieve the total discount and coupon code.
  4. Filters:

    • The module provides a Flask filter class that can be inherited to apply filters on querysets.
    • You can create a custom filter class by inheriting from Filter and implementing the add_filter method.
    • In your API views or functions, you can use the filter class by setting the filter_class attribute and calling apply() on an instance of the filter class.
  5. Custom Response Handler:

    • You can change the default API response format by overriding the CustomResponse class from dcg_service.core.response.
    • The overridden class should provide a response JSON with the following structure: {"data": data, "message": message, "title": self.response.status, "code": self.response.status_code}.
  6. Logger:

    • The module provides an overridden logger for better app debugging.
  7. Encryption:

    • The module includes functions for encrypting and decrypting data.
    • You need to set the CIPHER_PRIVATE_KEY environment variable with a 16-character key for AES128 encryption.
  8. Elastic-search DSL:

    • The module utilizes Elastic-search DSL for connecting and querying Elastic search indexes.
    • You need to set the ELASTICSEARCH_URL environment variable in your settings file.
    • The ACTIVITY_INDEX and SERVICE_CACHE_INDEX variables can be set to specify the indexes to be used for activity logs and service caching, respectively.

Elastic-search DSL

Elastic-search DSL is used to connect/query on elastic search indexes.

Must add following in your settings.py file:

ELASTICSEARCH_URL = os.environ.get('ELASTICSEARCH_URL')
ACTIVITY_INDEX = os.environ.get('ACTIVITY_INDEX', '').lower() # must be lower
SERVICE_CACHE_INDEX = os.environ.get('SERVICE_CACHE_INDEX')

Activity Events

SqlAlchemy events are used to log user activity logs to 'Elasticsearch'.

You can check dcg_service.core.events.py file for details.

Contains: SqlAlchemy model events before_create, after_create, before_update, after_update.

Activity event class,
registerd event class in __init__.py file

e.g.
def register_events():
    from . import events
    activity_events = events.ActivityEvent()
    activity_events.initialise_events()

register_events()

Add models names of your apps in settings.py to exclude from activity events.

e.g.  EXCLUDE_MODEL_EVENTS = ['Cart']

Add events to log activity.

e.g.  EVENTS = ['after_insert', 'before_update']

Add model file path.

e.g APP_MODELS = 'order_app.models'

Authentication/Permission

User authentication JWT token, set following details in your settings file.

    SIGNING_KEY = os.environ.get('SIGNING_KEY')
    JWT_ALGORITHMS = ['HS256']

Start using:

from dcg_service.core.permissions import is_authenticated

class ExampleView(views.MethodView):
"""
APIs Methods
-----------
GET: Get list.
"""
decorators = [is_authenticated]

def get(self):

Service cache

    Service price class to fetch service fee structure from `Elasticsearch` index.
    service_id: Respective service id,
    units: Units/quantity of service
    -----------------------------------------------------------------------------
    Call `ServicePrice(service_id, units).get_fee_details()` to get service fee details.
    
    For more information check file function docs.

Start using:

from dcg_service.core.services import ServicePrice
service = ServicePrice(service_id, units)
price_details = service.get_fee_details(include_tax=False)
total_discount, coupon_code = service.get_coupon_details()

Filters

Flask filter class, Inherit this class to apply filters on queryset.

e.g.

class ModelFilter(Filter):
    model = model_name
    def add_filter(self, *args, **kwargs):
        queryset = self.get_queryset()
        queryset = queryset.filter_by(**self.request_params)
        return queryset

use this filter class in your API view or function.

class APIView():
    filter_class = ModelFilter
    def get():
        queryset = self.filter_class(queryset).apply()

Custom Response handler

Change default API response, override dcg_service.core.response.CustomResponse class according to your need.

returns:

response_json = {
            "data": data,
            "message": message,
            "title": self.response.status,
            "code": self.response.status_code
        }

Logger

Logger override for maintain app debugging.

Encryption

Contain encrypt, decrypt functions for encryption.

Must add "CIPHER_PRIVATE_KEY" in your env:

key = os.environ['CIPHER_PRIVATE_KEY']  # Must Be 16 char for AES128

Metadata

Release files for dcg-service 1.9.2

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

Source distribution (sdist)

Source distribution for dcg-service 1.9.2
File Size Uploaded
dcg_service-1.9.2.tar.gz 36.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dcg-service 1.9.2
File Interpreter ABI Platform
dcg_service-1.9.2-py3-none-any.whl Python 3 none any Details

Total release size: 81.2 kB

Release files / dcg_service-1.9.2.tar.gz

Download URL dcg_service-1.9.2.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ffeb72439892a2b47bc1d0e10fe60c0051ed0235e38fb2985b91e873fceee8fc
BLAKE2b-256 checksum
How to use checksums
8ad2a648a54a97f0ab1a245aceeabd0ca67e885e18f9e7972b9cdc3c22de1256
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.6

Release files / dcg_service-1.9.2-py3-none-any.whl

Download URL dcg_service-1.9.2-py3-none-any.whl
Size 44.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5463599cdc3270d5727bca91dbc003a0da29183c9c0e000c80502961d8a81511
BLAKE2b-256 checksum
How to use checksums
622610655546a4d087d482d3614624d0086c479fc8de225c96d13e41fe5f1430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.9.2 This release

2 release files

1.9.1

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

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