semvec/pypi-packages huggingface dataset:
micro-django-base 1.0.1
A Reusable RTL Django Base App
License: MIT
Requires Python: >=3.9

# Micro Base - A Reusable RTL Django Base App

[![PyPI version](https://badge.fury.io/py/micro-django-base.svg)](https://pypi.org/project/micro-django-base/)

**RTL** lightweight, reusable django app that provides a dynamic base for your django projects.
It includes base templates, authentication utilities, and file management helpers.

## Features
- **Dynamic Model Lookup**: Reference models by name (e.g., `'Decree'`) or app label (e.g., `'documents.Decree'`).
- **App-Agnostic Utilities**: Generic file downloaders, permission checkers, and archiving helpers.
- **RTL Support**: Built-in RTL styling for Arabic applications.
- **Unified Base Templates**: Ready-to-use `base.html` with sidebar and topbar integration.

## Installation

1.  **Install the package:**
    ```bash
    pip install micro-django-base
    ```

2.  **Add to `INSTALLED_APPS`:**
    In your `settings.py`:
    ```python
    INSTALLED_APPS = [
        ...
        'base',
        'users',  # Required dependency (micro-users-pkg)
        ...
    ]
    ```

3.  **Run Migrations:**
    Since `base` is a reusable app, run migrations from your main project:
    ```bash
    python manage.py makemigrations base
    python manage.py migrate base
    ```

## Usage

### File Downloading
Use the universal downloader in your views or templates.

**`file_type` Parameters:**
- `'all'`: **(Default)** Dynamically finds and downloads *all* `FileField` and `ImageField` files attached to the record.
- `'field_name'`: Downloads a specific field by its name (e.g., `'pdf_file'`, `'custom_doc'`, `'cover_image'`).

**Usage in Python Views:**
```python
from base.fetcher import download_single_file

def my_download_view(request, record_id):
    # Download ALL files for this record
    return download_single_file(request, 'Decree', record_id, file_type='all')

    # Download only a specific field
    return download_single_file(request, 'Decree', record_id, file_type='my_custom_field')
```

**Usage in HTML Templates:**
You can use the built-in URL pattern directly:
```html
<!-- Download specific file -->
<a href="{% url 'base:download_file' model_name='Decree' record_id=obj.id file_type='pdf_file' %}" class="btn btn-primary">
    Download PDF
</a>

<!-- Download ALL files (zipped) -->
<a href="{% url 'base:download_file' model_name='Decree' record_id=obj.id file_type='all' %}" class="btn btn-info">
    Download All
</a>
```
*Note: Ensure you include `base.urls` in your project's `urls.py` with `namespace='base'`.*

### Static Files
Base templates are available under `base/templates/`. Extend them in your project:
```html
{% extends "base.html" %}

{% block content %}
    <h1>My Page</h1>
{% endblock %}
```
Static files (CSS/JS) are allocated in `base/static/base/`.

## Version History

| Version | Changes |
| :--- | :--- |
| **v1.0.0** | Initial Release. |