Generate hard to guess url from python secrets module. Implement custom view logic
Project description
HTG URL INSTALLATION
1. Install package
$ pip install htg-url-generator
2. Register package in INSTALLED_APPS in the Django settings:
INSTALLED_APPS = [
...
'htg_url',
...
]
3. Declare a new 'AbstractHtgUrlGenerator' wrapper class and override 'create_unique_identifier' method:
class ExampleGeneratorClass(AbstractHtgUrlGenerator):
@staticmethod
def create_unique_identifier(**properties):
...
Include
custom
implementation
...
Return value for the 'create_unique_identifier' method should be a string
4. Declare a new 'AbstractFetchDataFromSap' wrapper class and override 'create_unique_identifier' method:
class ExampleFetcherCLass(AbstractFetchDataFromSap):
@staticmethod
def fetch_document_from_sap(**properties):
...
Include
custom
implementation
...
Return value for the 'fetch_document_from_sap' method should be a base64 encoded string or None
5. Declare a new 'AbstractDownloadDocumentView' wrapper class:
class ExampleDownloadDocumentView(AbstractDownloadDocumentView):
pass
By default 'AbstractDownloadDocumentView' class does NOT require login or any permission. Override if necessary
6. Register a new path in 'urls.py' and map declared view class:
path('document/<token>/', ExampleDownloadDocumentView.as_view())
7. Declare settings for the package in the Django settings
HTG_URL_SETTINGS = {
'HTG_URL_REDIS_TTL': 216000, # 60 minutes
'HTG_WRAPPER_CLASS': 'app_name.file_name.class_name',
'DOC_WRAPPER_CLASS': 'app_name.file_name.class_name'
'REDIS_CONNECTION_STRING': 'redis_connection_string' or None
}
8. Run tests
$ python manage.py test htg_url
NOTE
Package will use connection string to connect to Redis if it is defined in settings under 'REDIS_CONNECTION_STRING'.
Otherwise it will initialize connection using environment variables (see below)
Package expects you to have 'REDIS_HOST', 'REDIS_PORT', 'REDIS_PASSWORD' and 'CACHE_REDIS_DB' (db index) environment variables as follows:
host = os.environ.get('REDIS_HOST'), port = int(os.environ.get('REDIS_PORT')),
password = os.environ.get('REDIS_PASSWORD'), os.environ.get('CACHE_REDIS_DB')
NOTE
Package also expects you to have 'libmagic' installed on your machine as 'python-magic' library depends on it:
$ sudo apt-get install libmagic1
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
htg_url_generator-0.2.tar.gz
(8.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file htg_url_generator-0.2.tar.gz.
File metadata
- Download URL: htg_url_generator-0.2.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59006caf1f9f9272b572cd3eaa2e58624fa4d9a6c6da76b8508dce829b4c5338
|
|
| MD5 |
1b9994f1ad49f31db82063a9e3ebcc2a
|
|
| BLAKE2b-256 |
d99db7c1ad4f2d092a33b19d5250211876a75ac7a12ff0f7dcc79b1edfa24917
|
File details
Details for the file htg_url_generator-0.2-py3-none-any.whl.
File metadata
- Download URL: htg_url_generator-0.2-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b89f4a601945f083505d872cb2962be9901299a2567a99789035cb33c540cb8
|
|
| MD5 |
2e28496fde03605a8f57f80e8df575ca
|
|
| BLAKE2b-256 |
83ca8d40af46e2b2da623cd48a4d3aaaf0229509792626460df921c489cfae35
|