Skip to main content

Modular Django-based data management framework with ORM, GraphQL, fine-grained permissions, rule validation, calculations and caching.

Project description

GeneralManager

Overview

GeneralManager is a powerful and flexible framework designed for managing and processing data. It provides a modular structure that enables developers to implement complex business logic efficiently. The module is written entirely in Python and uses Django as the backend framework.

Key Features

1. Data Management

  • Flexibility: Supports managing all kinds of data, not just projects and derivatives.
  • Database Integration: Seamless integration with the Django ORM for database operations.
  • External Interfaces: Support for interfaces to other programs, such as Excel.

2. Data Modeling

  • Django Models: The data structure is based on Django models, extended by custom fields like MeasurementField.
  • Rules and Validations: Define rules for data validation, e.g., ensuring that a project's start date is before its end date.

3. GraphQL Integration

  • Automatic generation of GraphQL interfaces for all models.
  • Support for custom queries and mutations.

4. Permission System

  • ManagerBasedPermission: A flexible permission system based on user roles and attributes.
  • Attribute-level CRUD permissions.

5. Interfaces

  • CalculationInterface: Allows the implementation of calculation logic.
  • DatabaseInterface: Provides a standardized interface for database operations.
  • ReadOnlyInterface: For read-only data access.

6. Data Distribution and Calculations

  • Volume Distribution: Automatically calculates and distributes volume over multiple years.
  • Commercial Calculations: Calculates total volume, shipping costs, and revenue for projects.

Usage

Installation

Install the module via pip:

pip install GeneralManager

Example Code

The following example demonstrates how to create a GeneralManager and generate sample data (in this case 10 projects):

from general_manager import GeneralManager
from general_manager.interface.database import DatabaseInterface
from general_manager.measurement import MeasurementField, Measurement
from general_manager.permission import ManagerBasedPermission

class Project(GeneralManager):
    name: str
    start_date: Optional[date]
    end_date: Optional[date]
    total_capex: Optional[Measurement]
    derivative_list: DatabaseBucket[Derivative]

    class Interface(DatabaseInterface):
        name = CharField(max_length=50)
        number = CharField(max_length=7, validators=[RegexValidator(r"^AP\d{4,5}$")])
        description = TextField(null=True, blank=True)
        start_date = DateField(null=True, blank=True)
        end_date = DateField(null=True, blank=True)
        total_capex = MeasurementField(base_unit="EUR", null=True, blank=True)

        class Meta:
            constraints = [
                constraints.UniqueConstraint(
                    fields=["name", "number"], name="unique_booking"
                )
            ]

            rules = [
                Rule["Project"](
                    lambda x: cast(date, x.start_date) < cast(date, x.end_date)
                ),
                Rule["Project"](lambda x: cast(Measurement, x.total_capex) >= "0 EUR"),
            ]

        class Factory:
            name = LazyProjectName()
            end_date = LazyDeltaDate(365 * 6, "start_date")
            total_capex = LazyMeasurement(75_000, 1_000_000, "EUR")

    class Permission(ManagerBasedPermission):
        __read__ = ["ends_with:name:X-771", "public"]
        __create__ = ["admin", "isMatchingKeyAccount"]
        __update__ = ["admin", "isMatchingKeyAccount", "isProjectTeamMember"]
        __delete__ = ["admin", "isMatchingKeyAccount", "isProjectTeamMember"]

        total_capex = {"update": ["isSalesResponsible", "isProjectManager"]}

Project.Factory.createBatch(10)

GraphQL Integration

The module automatically generates GraphQL endpoints for all models. You can run queries and mutations through the GraphQL URL defined in your Django settings.

Example of a GraphQL query:

query {
  projectList {
    name
    startDate
    endDate
    totalCapex {
      value
      unit
    }
  }
}

Benefits

  • Modularity: Easy to extend and adapt.
  • Flexibility: Supports complex business logic and calculations.
  • Integration: Seamless integration with Django and GraphQL.
  • Permissions: Fine-grained permissions for users and attributes.
  • Data Validation: Automatic validation of data through rules and constraints.
  • Caching: Automatic cache generation with the @cached decorator to improve performance.

Requirements

  • Python >= 3.12
  • Django >= 5.2
  • Additional dependencies (see requirements.txt):
    • graphene
    • numpy
    • Pint
    • factory_boy
    • and more.

License

This project is distributed under the Non-Commercial MIT License. It may only be used for non-commercial purposes. For further details see the LICENSE file.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

generalmanager-0.7.0.tar.gz (117.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

generalmanager-0.7.0-py3-none-any.whl (81.1 kB view details)

Uploaded Python 3

File details

Details for the file generalmanager-0.7.0.tar.gz.

File metadata

  • Download URL: generalmanager-0.7.0.tar.gz
  • Upload date:
  • Size: 117.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for generalmanager-0.7.0.tar.gz
Algorithm Hash digest
SHA256 3662f0eca33676b4000fd9e6906be034609481172020634ed11c447676d871b9
MD5 bf227fb2f262c597fda47be3288fd4f7
BLAKE2b-256 d804e7afe3ecc6ed888ad7ff71424f9e7c03988b3f2d604935818ed3c81c2950

See more details on using hashes here.

File details

Details for the file generalmanager-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: generalmanager-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 81.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for generalmanager-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58a63c4ec458e329e3eb74ce82b9b70e153a24ae647d717801dc770cce6a84d6
MD5 c8876e31154101d6ce1aa2fa51f85268
BLAKE2b-256 cebea53321eb81d6dd9831b20b969dbd90e3154119ab7b00f979c8f6052bff29

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