Web & Telegram Quiz Generator
Originally developed two years ago for a Physics teacher to automate student testing; the codebase was uploaded subsequently.
Testopia is a Django‑powered application that lets educators create and administer quizzes by simply uploading an Excel file of questions. Students can then take these quizzes either via a web interface or interactively through a Telegram bot.
- Excel‑based Quiz Creation: Upload
.xlsxfiles containing questions, options, correct answers, and point values; Testopia parses and stores them automatically. - Django Backend: Robust data models for Tests, Questions, Choices, User Answers, and User Test sessions.
- Web Interface: Simple upload form (
/upload/) to create quizzes, plus web view to render and submit tests (prototype stage). - Telegram Bot: Interactive quiz delivery via inline buttons using pyTelegramBotAPI. Commands:
/start— Register and welcome message/tests— List available quizzes- Inline buttons to answer, skip, or finish a quiz
- Automated Test Generation:
utils/TestGeneratorreads your Excel sheet, randomizes questions/variants, dumps JSON for both web and bot consumption. - Persistence & Analytics: Tracks user answers, computes scores, and logs results in
UserTestrecords.
├── TGBOT/ # Telegram bot handlers and Test session classes
├── data/ # Django app: models, forms, views, tests for web quiz interface
├── core/ # Django core: settings, URLs, user model extensions
├── utils/ # TestGenerator: parses Excel & builds quiz JSON
├── templates/ # HTML templates: upload form, success page, quiz view
├── static/ # CSS/JS assets for web interface
├── .github/workflows/ # CI pipeline for linting & testing
├── manage.py # Django CLI
├── requirements.txt # Python dependencies
└── README.md # This documentation
- Clone the repo
git clone https://github.com/habiboffdev/testopia.git cd testopia - Create & activate an environment
python3 -m venv venv source venv/bin/activate # Windows: `venv\\Scripts\\activate` pip install -r requirements.txt
- Configure environment variables
- Copy
.env.exampleto.envand set:SECRET_KEY=your_django_secret_key TELEGRAM_BOT_TOKEN=your_telegram_token DEBUG=True ALLOWED_HOSTS=localhost,127.0.0.1 DATABASE_URL=sqlite:///db.sqlite3
- Copy
- Apply migrations
python manage.py migrate
- Run Django server
python manage.py runserver
- Start the Telegram Bot (in a separate terminal)
python TGBOT/main.py
- Create a Quiz:
- Visit
http://localhost:8000/upload/ - Fill in title, description, number of variants, and upload your Excel file (columns:
question,A,B,C,D,point).
- Visit
- View Quiz Data:
- After upload, view parsed data on the success page.
- Take Quiz via Web (Prototype):
- Browse to
/solve/<test_id>/to see questions rendered and submit answers.
- Browse to
- Take Quiz via Telegram:
- Message your bot on Telegram:
/startto register/teststo list quizzes- Tap inline buttons to select answers, skip, or finish. Score is sent at end.
- Message your bot on Telegram:
| Model | Purpose |
|---|---|
| TestModel | Metadata for each quiz (title, description, variants) |
| Question | Each question text, point value, order, multiple-choice flag |
| Choice | Options for questions; flags correct answers |
| UserAnswer | Tracks raw answer selections per user & quiz |
| UserTest | Summarizes a user’s quiz session: correct, incorrect, total points |
- Web UI Completion: Finish the
/solve/and/submit/endpoints and add styled templates. - Error Handling: Improve exception logging and user feedback on upload/view pages.
- CI Pipeline: Expand GitHub Actions to run
pytest,flake8, and code coverage checks. - Deployment: Containerize with Docker and deploy on Heroku or DigitalOcean.
MIT License. See LICENSE for details.
Last updated: April 23, 2025