Skip to content

Commit d60ef64

Browse files
YosefAshenaficlaudejontsai
authored
docs: add comprehensive README files across the codebase (#507)
# README Documentation Updates ## What This PR Does This PR updates all README files across the codebase to provide clear, practical documentation for each module. ## Changes ### Main README Updated the main README to use dynamic counts instead of hardcoded numbers. Added clearer organization with links to major components. ### All App READMEs Added consistent documentation structure for all Django apps: - Quick Start with immediate usage examples - Common Patterns with real code examples - Configuration showing Django settings - Best Practices Updated apps include: accounts, assessments, bible, blob_storage, file_storage, feedback, mobile, mp, notifications, organizations, prelaunch, sites, and others. ### API and Utils Subdirectories Added comprehensive documentation for API endpoints, utility functions, forms, and models across all apps and libraries. API documentation includes: request/response examples, authentication, error handling, pagination. Utils documentation includes: function naming conventions, lookup/creation/validation patterns, usage examples. ### Library Integration Documentation Updated documentation for all third-party service integrations including Google services, AWS, Stripe, Zillow, Facebook, LinkedIn, Discord, Slack, Yahoo services, and others. Each integration includes: initialization, basic operations, authentication, response format, caching, and configuration. ### Constants Directories Replaced TODO placeholders in all constants directories with actual documentation explaining the types of constants defined (enums, configuration values, lookup tables, etc). ## Structure All READMEs now follow the same structure: - Overview - Quick Start - Detailed usage sections (specific to each module) - Configuration - Best Practices This makes the documentation consistent and easy to navigate. --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Jonathan Tsai <jontsai@users.noreply.github.com>
1 parent c618313 commit d60ef64

File tree

175 files changed

+18863
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+18863
-137
lines changed

README.md

Lines changed: 140 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,143 @@
1-
django-htk
2-
==========
1+
# HTK: Django Hacktoolkit
32

4-
A set of apps, utilities, middlewares, etc for Django
3+
A comprehensive Django framework providing reusable apps, utilities, and third-party integrations for rapid development. Designed for hackathons and production applications.
54

6-
Used/embedded in <https://github.com/hacktoolkit/htk-django-skeleton
5+
## Overview
76

8-
Author: Jonathan Tsai <https://github.com/jontsai>
9-
License: MIT
7+
HTK includes:
8+
9+
- **[Reusable Django Apps](./apps/README.md)** - Pre-built apps for accounts, organizations, payments, messaging, and more
10+
- **[Third-Party Integrations](./lib/README.md)** - Ready-to-use connectors for 45+ external services (Stripe, Google, AWS, Slack, etc.)
11+
- **[Utility Modules](./utils/README.md)** - Common patterns for caching, text processing, APIs, and data handling
12+
- **[API Helpers](./api/README.md)** - Tools for building REST APIs with DataTables support
13+
- **[Form Utilities](./forms/README.md)** - Base form classes and validators
14+
- **[Decorators](./decorators/README.md)** - Django and function decorators for common tasks
15+
- **[Models & Fields](./models/README.md)** - Abstract models and custom Django fields
16+
- **[Middleware](./middleware/README.md)** - Request/response processing utilities
17+
18+
## Quick Start
19+
20+
### Using HTK Apps
21+
22+
HTK provides pre-built Django apps that can be installed and configured in your project:
23+
24+
```python
25+
# settings.py
26+
INSTALLED_APPS = [
27+
'htk.apps.accounts',
28+
'htk.apps.organizations',
29+
'htk.apps.stripe_lib',
30+
# ... more apps
31+
]
32+
```
33+
34+
### Common Patterns
35+
36+
**Caching objects:**
37+
```python
38+
from htk.cache.classes import CacheableObject
39+
40+
class UserFollowingCache(CacheableObject):
41+
def get_cache_key_suffix(self):
42+
return f'user_{self.user_id}_following'
43+
```
44+
45+
**User authentication:**
46+
```python
47+
from htk.apps.accounts.backends import HtkUserTokenAuthBackend
48+
from htk.apps.accounts.utils.auth import login_authenticated_user
49+
```
50+
51+
**API endpoints:**
52+
```python
53+
from htk.api.utils import json_response_form_error, get_object_or_json_error
54+
```
55+
56+
## Key Features
57+
58+
### Accounts & Authentication
59+
- User registration and email verification
60+
- Social authentication backends (OAuth2 support)
61+
- User profiles and email management
62+
- Token-based authentication
63+
64+
### Payments & Billing
65+
- Stripe integration (customers, subscriptions, charges)
66+
- Quote/Invoice system (CPQ)
67+
- Payment tracking and history
68+
69+
### Organizations
70+
- Multi-org support with roles and permissions
71+
- Org invitations and member management
72+
- Permission-based access control
73+
74+
### Messaging & Notifications
75+
- Email notifications
76+
- Slack integration
77+
- Conversation/threading support
78+
79+
### Utilities
80+
- Text processing (formatting, translation, sanitization)
81+
- Caching decorators and schemes
82+
- CSV/PDF generation
83+
- QR codes
84+
- Geolocation and distance calculations
85+
- Timezone handling
86+
87+
### Third-Party Services
88+
See [lib/README.md](./lib/README.md) for details on 45+ integrations including:
89+
- Cloud: AWS S3, Google Cloud
90+
- Communication: Slack, Discord, Gmail, Twilio
91+
- Data: Airtable, Stripe, Shopify, Zuora
92+
- Analytics: Iterable, Mixpanel
93+
- Location: Google Maps, Mapbox, Zillow
94+
- Search: Elasticsearch integration patterns
95+
96+
## Project Structure
97+
98+
```
99+
htk/
100+
├── apps/ # Pre-built Django apps
101+
├── lib/ # Third-party service integrations
102+
├── utils/ # Common utilities and helpers
103+
├── models/ # Abstract models and field types
104+
├── forms/ # Base form classes
105+
├── api/ # REST API utilities
106+
├── decorators/ # Function and class decorators
107+
├── middleware/ # Request/response processing
108+
├── cache/ # Caching framework
109+
├── constants/ # Project-wide constants
110+
├── extensions/ # Django extensions
111+
├── templates/ # Reusable templates
112+
└── templatetags/ # Custom template filters and tags
113+
```
114+
115+
## Module Documentation
116+
117+
For detailed information about each module, see:
118+
119+
- **[Apps](./apps/README.md)** - Reusable Django application packages
120+
- **[Libraries](./lib/README.md)** - Third-party service integrations
121+
- **[Utilities](./utils/README.md)** - Helper functions and utilities
122+
- **[API](./api/README.md)** - REST API patterns and tools
123+
- **[Cache](./cache/README.md)** - Caching framework and patterns
124+
- **[Forms](./forms/README.md)** - Form utilities and base classes
125+
- **[Decorators](./decorators/README.md)** - Function and class decorators
126+
- **[Models](./models/README.md)** - Abstract models and custom fields
127+
- **[Validators](./validators/README.md)** - Validation utilities
128+
129+
## Use Cases
130+
131+
**Hackathons:** Rapidly build production-quality features with pre-built apps and integrations.
132+
133+
**SaaS Applications:** Multi-organization support, billing, and user management out of the box.
134+
135+
**E-commerce:** Stripe payments, inventory management, order processing.
136+
137+
**Content Platforms:** User accounts, organizations, messaging, notifications.
138+
139+
**Marketplaces:** Payment processing, user profiles, organization support.
140+
141+
## Contributing
142+
143+
HTK is designed to be extended. Create custom apps that inherit from abstract base classes and add your own business logic.

admin/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Django Admin Utilities
2+
3+
Custom admin display and customization utilities.
4+
5+
## Quick Start
6+
7+
```python
8+
from htk.admin.decorators import django_admin_bool_field
9+
10+
@django_admin_bool_field('is_active')
11+
def is_active_display(obj):
12+
return obj.is_active
13+
is_active_display.short_description = 'Active'
14+
15+
class UserAdmin(admin.ModelAdmin):
16+
list_display = ['username', is_active_display]
17+
```
18+
19+
## Boolean Field Display
20+
21+
Display boolean fields as green checkmarks or red X marks in admin list view:
22+
23+
```python
24+
from htk.admin.decorators import django_admin_bool_field
25+
26+
class ProductAdmin(admin.ModelAdmin):
27+
list_display = ['name', is_available, is_featured]
28+
29+
@django_admin_bool_field('is_available')
30+
def is_available(obj):
31+
return obj.is_available
32+
33+
@django_admin_bool_field('is_featured')
34+
def is_featured(obj):
35+
return obj.is_featured
36+
```
37+
38+
## Configuration
39+
40+
```python
41+
# settings.py
42+
ADMIN_SITE_HEADER = 'My Admin'
43+
```

admintools/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Admin Tools
2+
3+
Advanced admin functionality including user impersonation and company user management.
4+
5+
## Quick Start
6+
7+
```python
8+
from htk.admintools.decorators import company_officer_required, company_employee_required
9+
from htk.admintools.utils import is_allowed_to_emulate_users, request_emulate_user
10+
11+
# Protect views for company officers
12+
@company_officer_required
13+
def officer_dashboard(request):
14+
return render(request, 'officer_dashboard.html')
15+
16+
# Protect views for company employees
17+
@company_employee_required
18+
def employee_portal(request):
19+
return render(request, 'employee_portal.html')
20+
```
21+
22+
## User Impersonation
23+
24+
Allow admins to emulate other users for testing:
25+
26+
```python
27+
from htk.admintools.utils import is_allowed_to_emulate_users, request_emulate_user
28+
29+
# Check if user can emulate others
30+
if is_allowed_to_emulate_users(request.user):
31+
# Allow user emulation in admin panel
32+
pass
33+
34+
# Emulate a specific user
35+
request_emulate_user(request, original_user, target_user)
36+
```
37+
38+
## Company User Management
39+
40+
Check company affiliation and roles:
41+
42+
```python
43+
from htk.admintools.models import company_officer_required, is_company_officer, is_company_employee
44+
45+
# Check officer status
46+
if is_company_officer(user):
47+
# User is a company officer
48+
pass
49+
50+
# Check employee status
51+
if is_company_employee(user):
52+
# User is a company employee
53+
pass
54+
55+
# Check email domain
56+
if user.has_company_email_domain():
57+
# User has company email
58+
pass
59+
```
60+
61+
## Company Data Lookups
62+
63+
Get mappings of company users:
64+
65+
```python
66+
from htk.admintools.utils import get_company_officers_id_email_map, get_company_employees_id_email_map
67+
68+
# Get officers mapping
69+
officers = get_company_officers_id_email_map()
70+
# Returns: {user_id: email, ...}
71+
72+
# Get employees mapping
73+
employees = get_company_employees_id_email_map()
74+
# Returns: {user_id: email, ...}
75+
```
76+
77+
## Configuration
78+
79+
```python
80+
# settings.py
81+
# Enable company user features
82+
COMPANY_ADMIN_ENABLED = True
83+
```

admintools/constants/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Admin Tools Constants
2+
3+
## Overview
4+
5+
This module provides configuration constants for the admin tools dashboard and user emulation features.
6+
7+
## Configuration Settings
8+
9+
```python
10+
from htk.admintools.constants import (
11+
HTK_COMPANY_EMAIL_DOMAINS,
12+
HTK_COMPANY_OFFICER_EMAILS,
13+
HTK_COMPANY_EMPLOYEE_EMAILS,
14+
HTK_EMULATE_USER_COOKIE_EXPIRATION_MINUTES,
15+
HTK_ADMINTOOLS_TODOS_CONFIGS
16+
)
17+
18+
# Email domains that identify company employees
19+
HTK_COMPANY_EMAIL_DOMAINS = () # e.g. ('company.com', 'internal.company.com')
20+
21+
# Email addresses of company officers
22+
HTK_COMPANY_OFFICER_EMAILS = () # e.g. ('ceo@company.com', 'cto@company.com')
23+
24+
# Email addresses of all company employees
25+
HTK_COMPANY_EMPLOYEE_EMAILS = () # Subset of HTK_COMPANY_OFFICER_EMAILS
26+
27+
# Session timeout for user emulation (minutes)
28+
HTK_EMULATE_USER_COOKIE_EXPIRATION_MINUTES = 15
29+
30+
# List of admin todo configurations
31+
HTK_ADMINTOOLS_TODOS_CONFIGS = []
32+
```
33+
34+
## Dashboard Constants
35+
36+
```python
37+
from htk.admintools.constants import (
38+
PULSE_RECENTLY_EDITED_PROFILES_LIMIT,
39+
PULSE_RECENTLY_JOINED_USERS_LIMIT,
40+
PULSE_RECENT_LOGINS_LIMIT,
41+
PULSE_STATS_PRECISION,
42+
ADMINTOOLS_USER_PAGE_SIZE
43+
)
44+
45+
# Dashboard data limits
46+
PULSE_RECENTLY_EDITED_PROFILES_LIMIT = 50
47+
PULSE_RECENTLY_JOINED_USERS_LIMIT = 50
48+
PULSE_RECENT_LOGINS_LIMIT = 50
49+
50+
# Decimal precision for statistics
51+
PULSE_STATS_PRECISION = 4
52+
53+
# User list pagination
54+
ADMINTOOLS_USER_PAGE_SIZE = 25
55+
```
56+
57+
## Customization
58+
59+
Override these settings in `settings.py`:
60+
61+
```python
62+
HTK_COMPANY_EMAIL_DOMAINS = ('acme.com', 'acme.internal')
63+
HTK_EMULATE_USER_COOKIE_EXPIRATION_MINUTES = 30
64+
PULSE_RECENTLY_EDITED_PROFILES_LIMIT = 100
65+
```

0 commit comments

Comments
 (0)