Project Configuration
Relevant source files
The following files were used as context for generating this wiki page:
This document provides a technical overview of the project configuration for the Campuspal Room Finder application. It covers the core Django settings, database setup, application structure, and administrative interface configuration, all derived from the project's source files. The configuration is designed to be flexible, separating sensitive information from the codebase using environment variables.
The project follows a standard Django structure with a central project directory (roomfinder) and a primary application (finder). Configuration is primarily managed through roomfinder/settings.py, which leverages python-decouple to read values from the environment, enhancing security and portability between development and production environments.
Core Django Settings
The main configuration file is roomfinder/settings.py. It defines the fundamental operational parameters of the Django project.
Environment-Driven Configuration
The project uses the python-decouple library to manage settings that vary between environments (e.g., development vs. production). This approach avoids hardcoding sensitive information like secret keys or database credentials in the source code.
The following diagram illustrates how settings are loaded from the environment.
This diagram shows that key settings are sourced from environment variables at runtime.
Sources: roomfinder/settings.py:11, 24, 27, 86
Key environment variables are:
| Variable | Description | Default | Type |
|---|---|---|---|
SECRET_KEY | A secret key for a particular Django installation. Used for cryptographic signing. | No default, required. | string |
DEBUG | A boolean that turns on/off debug mode. | False | boolean |
DATABASE_URL | A URL string that contains all database connection information. | No default, required. | string |
| Sources: roomfinder/settings.py:24, 27, 86 |
Application and Middleware
The INSTALLED_APPS setting lists all Django applications that are activated for this project. The primary custom application is finder.
# roomfinder/settings.py:33-40
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"finder.apps.FinderConfig" # Add new app here
]
Sources: roomfinder/settings.py:33-40
The MIDDLEWARE setting defines the stack of middleware classes that process requests and responses globally. The project uses the standard Django middleware stack for security, sessions, and authentication.
Sources: roomfinder/settings.py:42-50
WSGI Configuration
The roomfinder/wsgi.py file serves as the entry point for WSGI-compatible web servers to serve the project. It ensures that the DJANGO_SETTINGS_MODULE environment variable is set to point to the project's settings file and provides the application callable.
# roomfinder/wsgi.py:13-15
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "roomfinder.settings")
application = get_wsgi_application()
Sources: roomfinder/wsgi.py:13-15
Database Configuration
The database connection is configured in roomfinder/settings.py using the dj_database_url library, which parses a DATABASE_URL environment variable. This allows for easy switching between different database backends (e.g., SQLite for development, PostgreSQL for production) without code changes.
# roomfinder/settings.py:85-87
DATABASES = {
'default': dj_database_url.config(default=config('DATABASE_URL'))
}
Sources: roomfinder/settings.py:85-87
The data models that define the database schema are located in finder/models.py. The two main models are Room and ClassSchedule.
The following ER diagram shows the relationship between the database models.
This diagram illustrates that a Room can have multiple ClassSchedule entries.
Sources: finder/models.py
Static Files
Static files such as CSS, JavaScript, and images are configured to be served from the finder/static/ directory.
STATIC_URL: The URL to use when referring to static files located inSTATIC_ROOT. Set to"static/".STATICFILES_DIRS: A list of directories where Django will look for static files. It is configured to include thefinder/staticdirectory at the project's base.
# roomfinder/settings.py:126-127
STATIC_URL = "static/"
STATICFILES_DIRS = [BASE_DIR / "finder" / "static"]
Sources: roomfinder/settings.py:126-127
Admin Interface Configuration
The Django admin site is customized in finder/admin.py to provide a user-friendly interface for managing Room and ClassSchedule data.
Admin Models
RoomAdmin: Customizes the admin view for theRoommodel. It displays the room name, building, and a count of its scheduled classes. It also allows filtering by building and searching by name or building.ClassScheduleAdmin: Customizes the admin view for theClassSchedulemodel. It provides detailed list display, filtering options (by day, status, building), and search capabilities. Theis_cancelledfield is made directly editable from the list view.
The following diagram shows the flow of registering models with the admin site.
This diagram shows how model admin classes are defined and registered to appear in the Django admin.
Sources: finder/admin.py:5, 16
The site header, title, and index title of the admin interface are also customized for branding.
# finder/admin.py:51-53
admin.site.site_header = "Campuspal Room Finder Admin"
admin.site.site_title = "Room Finder Admin"
admin.site.index_title = "Welcome to Room Finder Administration"
Sources: finder/admin.py:51-53
Sample Data Generation
For development and testing, a script generate_sample_data.py is provided to create realistic sample data. The script's behavior is configured by several constants at the top of the file.
| Constant | Description | Example Value |
|---|---|---|
NUM_ROOMS | The total number of rooms to generate. | 50 |
NUM_SCHEDULES | The total number of class schedules to generate. | 300 |
BUILDINGS | A dictionary mapping building full names to their codes. | {"Hephaestus Hall": "HH"} |
AMENITIES_LIST | A list of possible amenities a room can have. | ["Projector", "Whiteboard"] |
COURSES | A list of course codes to be used in schedules. | ["CS101", "MA203"] |
DAYS | A list of days for which schedules are generated. | ["Mon", "Tue", "Wed", "Thu", "Fri"] |
This script generates rooms.xlsx and timetable.xlsx files, which can then be loaded into the database using custom management commands.
Sources: generate_sample_data.py:5-23, README.md:105-108