Skip to main content

shopcloud-django-toolbox

install

$ pip install shopcloud-django-toolbox

Models

Add the GID as identifier to all django models

from shopcloud_django_toolbox import GID

class FooBarModel(models.Model, GID):
    pass

URL-Signing

generate or load signed base64 encoded dict containing versioned with expiration date for access-control

Usage

settings.py

DJ_TOOLBOX_SIGNER = {
    'VERSION': "1",
}

dump values dict:

from shopcloud django.toolbox import signer

signing_key = signer.dumps({"foo":"bar"}, expire_in_hours:12)

load values dict:

from shopcloud django.toolbox import signer
from django.http import HttpResponseForbidden

def some_view(request):
    sign_str = request.GET.get("sign")
    is_valid, data = signer.loads(sign_str)
    if not is_valid(request):
        return HttpResponseForbidden("Not allowed")
    data.get("xxx")
    #
    ## … some view logic
    #

alternative for a django Request:

from shopcloud django.toolbox import signer
from django.http import HttpResponseForbidden

def some_view(request):
    sign_str = request.GET.get("sign")
    is_valid, data = signer.loads_from_request(sign_str)
    if not is_valid(request):
            return HttpResponseForbidden("Not allowed")
    data.get("xxx")
    #
    ## … some view logic
    #

Django View Decorator

check if GET-parameter sign is set and has required keys in data objects

from shopcloud_django_toolbox import signer
from shopcloud_django_toolbox.decorators import


@require_toolbox_sign(needed_keys=['key_that_must_exist', 'foo', 'bar'])
def some_view(request):
    is_valid, data = signer.loads_from_request(request)
    #
    ## … some view logic
    #

Testing

API standart tests

Standart template for the tests.py file in all modules with admin and REST API`s

from shopcloud_django_toolbox import TestAdminTestCase
from shopcloud_django_toolbox.tests import BaseTestApiAuthorization
from shopcloud_django_toolbox import SetupClass
from shopcloud_django_toolbox.tests import Representation
__


class TestRepresentation(utils.Representation):
    def test_representation(self):
        from . import seeds
        self._test_representations_from_seeds(seeds)


class TestAdminPages(TestAdminTestCase):
    MODULE = 'url-name'

    def test_admin_easylineitem(self):
        self.run_for_model(
            'url-model-name',
            is_check_add=False,  # deactivate when add function is deactivated
            is_check_template=False,  # deactivate generic template check
            is_check_search=True,  # activate searchbar check
            is_check_detail=False, # erzeugt ein Model-Object und ruft den Detail-View auf,
            creation_parameters={}, # notwendig für den detailcheck da ein generisches erzeugen von spezeillen Models nicht mgl
        )


class TestApiAuthorization(BaseTestApiAuthorization):
    app_name = "url-module-name"

    def test_model_foo(self):
        self.run_test_endpoint("url-model-name")

    def test_model_bar(self):
        self.run_test_endpoint("url-model-name")


class YoutAPITest(SetupClass):
    def test_api_endpint(self):
        client = APIClient()
        client.login(username=self.username, password=self.pwd)

        r = client.get('/module/api/endpoint')
        self.assertEqual(r.status_code, status.HTTP_201_CREATED)

Event

To fire events and run tasks in prarallel, need [PROJECT] to receive and run the output from log and call the API.

from shopcloud_django_toolbox import Event


class FooBarModel(models.Model):
    ...

    def do_event(self):
        event = Event(
            name="de.talk-point.platform/module/model/sync",
            model=self,
        )
        event.add_task(
            queue="default",
            url=f"moduke/api/model/{self.id}/action/",
            json={}
        )
        event.fire()

File Hash Generating

generate sha-384 file hash for sri with given filepath

from shopcloud-django-toolbox import hash_for_file


hash_for_file("./some-file.txt")

deploy

# change version Number in setup.py ändern und dann erst releasen
# delete build and dist-directory
$ rm -rf build dist
$ pip3 install wheel twine
$ python3 setup.py sdist bdist_wheel
$ twine upload dist/*
  - username __token__

Metadata

Release files for shopcloud-django-toolbox 1.20.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 shopcloud-django-toolbox 1.20.0
File Size Uploaded Provenance Actions
shopcloud_django_toolbox-1.20.0.tar.gz 11.0 kB Without provenance Details for shopcloud_django_toolbox-1.20.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shopcloud-django-toolbox 1.20.0
File Interpreter ABI Platform Actions
shopcloud_django_toolbox-1.20.0-py3-none-any.whl Python 3 none any Details for shopcloud_django_toolbox-1.20.0-py3-none-any.whl

Total release size: 23.1 kB

Release files / shopcloud_django_toolbox-1.20.0.tar.gz

Download URL shopcloud_django_toolbox-1.20.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cccc9587950a5e043624a7eb2370631c2b21e34fb8b8b639b6de2c881e8131a3
BLAKE2b-256 checksum
How to use checksums
fcd1049b019ff22fd6c1aac4d0af19e9b5717f118b2b9ef066c9e8ac9e79a0b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / shopcloud_django_toolbox-1.20.0-py3-none-any.whl

Download URL shopcloud_django_toolbox-1.20.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6428ff05d49c360f79009bb7998cf901303712d4f7afa789709590c30c38e78
BLAKE2b-256 checksum
How to use checksums
5c3f58474054d4e02b7047a0e61a63678c83e26c38dd8ed3cbd137437140032f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Security for shopcloud-django-toolbox 1.20.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.

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