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'
}
8. Run tests
$ python manage.py test htg_url
NOTE
Package expects you to have 'REDIS_HOST' and 'REDIS_PORT' environment variables as follows:
host = os.environ.get('REDIS_HOST'), port = int(os.environ.get('REDIS_PORT'))
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
Built Distribution
Close
Hashes for htg_url_generator-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd38f47f6d6409cef8acf2eca641a3e91615e4c36d8dd66516d4f1a5386ffe9e |
|
MD5 | 5f62959ca7ffe1e6fb77a4a62b28bbe9 |
|
BLAKE2b-256 | 421c4409b81f85917b116204227f291269d1a2287ca7ab7b533d6ac519185b2f |