Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ cython_debug/
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/

Expand All @@ -217,4 +217,3 @@ __marimo__/

# Streamlit
.streamlit/secrets.toml

23 changes: 17 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
repos:
- repo: local

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: format-and-add
name: Format code and stage changes
entry: uv run scripts/pre-commit-format.py
language: system
pass_filenames: false
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.5
hooks:
- id: ruff-check
types_or: [python, pyi]
always_run: true
args: ["--fix"]
- id: ruff-format
types_or: [python, pyi]
always_run: true
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ format: format-backend format-frontend

format-backend:
@echo "Formatting backend (Python) code with isort and black..."
uvx ruff format
uv run ruff check --select I . && \
uv run ruff format

format-frontend:
@echo "Formatting frontend code with prettier..."
Expand All @@ -57,7 +58,7 @@ lint: lint-backend lint-frontend

lint-backend: format-backend
@echo "Linting backend (Python) code with ruff..."
uvx ruff check
uv run ruff check

lint-frontend: format-frontend
@echo "Linting frontend code with eslint..."
Expand Down
3 changes: 0 additions & 3 deletions apps/auth/admin.py

This file was deleted.

3 changes: 0 additions & 3 deletions apps/auth/models.py

This file was deleted.

3 changes: 0 additions & 3 deletions apps/auth/tests.py

This file was deleted.

2 changes: 1 addition & 1 deletion apps/auth/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import re
from typing import Any

import httpx
from django.conf import settings
Expand All @@ -9,7 +10,6 @@
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError
from rest_framework.response import Response
from typing import Any

from apps.web.models import Student

Expand Down
2 changes: 0 additions & 2 deletions apps/auth/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import asyncio
import base64
import hashlib
import json
import logging
import secrets
import time

import dateutil.parser
import httpx
from django.conf import settings
from django.contrib.auth import authenticate, get_user_model, login, logout
from django_redis import get_redis_connection
Expand Down
3 changes: 0 additions & 3 deletions apps/web/models.py

This file was deleted.

12 changes: 12 additions & 0 deletions apps/web/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@
from .student import Student
from .vote import Vote
from .vote_for_review import ReviewVote

__all__ = [
"Course",
"CourseMedian",
"CourseOffering",
"DistributiveRequirement",
"Instructor",
"Review",
"Student",
"Vote",
"ReviewVote",
]
2 changes: 2 additions & 0 deletions apps/web/models/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .review_form import ReviewForm

__all__ = ["ReviewForm"]
2 changes: 1 addition & 1 deletion apps/web/models/forms/review_form.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.core.exceptions import ValidationError

from apps.web.models import Course, Review
from apps.web.models import Review
from lib import constants
from lib.terms import is_valid_term

Expand Down
3 changes: 1 addition & 2 deletions apps/web/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

from apps.web.models import (
Course,
CourseMedian,
CourseOffering,
DistributiveRequirement,
Instructor,
Review,
Vote,
ReviewVote,
Vote,
)
from lib import constants

Expand Down
2 changes: 1 addition & 1 deletion apps/web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@
<script type="module" src="{% static 'assets/index.js' %}"></script>
</body>

</html>
</html>
3 changes: 0 additions & 3 deletions apps/web/tests.py

This file was deleted.

1 change: 0 additions & 1 deletion apps/web/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import factory
from django.contrib.auth.models import User
from django.db.models.signals import post_save

from apps.web import models
from lib import constants
Expand Down
46 changes: 3 additions & 43 deletions apps/web/tests/model_tests/test_student.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
from datetime import datetime

from django.test import TestCase

from apps.web.models import Review, Student, Vote
from apps.web.models import Vote
from apps.web.tests import factories
from lib import constants


class StudentTestCase(TestCase):
def test_is_valid_sjtu_student_email_only_allows_dartmouth(self):
self.assertFalse(
Student.objects.is_valid_sjtu_student_email("layuplist@gmail.com")
)
self.assertTrue(
Student.objects.is_valid_sjtu_student_email("layuplist.16@dartmouth.edu")
)

def test_is_valid_sjtu_student_email_allows_four_years_from_now(self):
self.assertTrue(
Student.objects.is_valid_sjtu_student_email(
"layuplist.{}@dartmouth.edu".format(str(datetime.now().year + 5)[2:])
)
)

def test_is_valid_sjtu_student_email_allows_dual_degree(self):
self.assertTrue(
Student.objects.is_valid_sjtu_student_email("layuplist.ug@dartmouth.edu")
)
self.assertTrue(
Student.objects.is_valid_sjtu_student_email("layuplist.UG@dartmouth.edu")
)

def test_is_valid_sjtu_student_email_allows_grad(self):
self.assertTrue(
Student.objects.is_valid_sjtu_student_email("layuplist.GR@dartmouth.edu")
)
self.assertTrue(
Student.objects.is_valid_sjtu_student_email("layuplist.gr@dartmouth.edu")
)

def test_is_valid_sjtu_student_email_forbids_alum(self):
self.assertFalse(
Student.objects.is_valid_sjtu_student_email(
"layuplist.16@alumni.dartmouth.edu"
)
)

def test_can_see_recommendations(self):
s = factories.StudentFactory()
self.assertFalse(s.can_see_recommendations())

# create sufficient votes of wrong type
for _ in xrange(constants.REC_UPVOTE_REQ):
for _ in range(constants.REC_UPVOTE_REQ):
factories.VoteFactory(
user=s.user, category=Vote.CATEGORIES.DIFFICULTY, value=1
)
Expand All @@ -62,7 +22,7 @@ def test_can_see_recommendations(self):
# cannot view if does not reach vote count
Vote.objects.all().delete()
factories.ReviewFactory(user=s.user)
for _ in xrange(constants.REC_UPVOTE_REQ - 1):
for _ in range(constants.REC_UPVOTE_REQ - 1):
factories.VoteFactory(
user=s.user, category=Vote.CATEGORIES.QUALITY, value=1
)
Expand Down
31 changes: 13 additions & 18 deletions apps/web/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import datetime
import uuid

import dateutil.parser
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db.models import Count
from rest_framework.decorators import (
api_view,
permission_classes,
)
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response

from apps.web.models import (
Course,
CourseMedian,
Expand All @@ -6,35 +19,17 @@
ReviewVote,
Vote,
)

from apps.web.models.forms import ReviewForm

from apps.web.serializers import (
CourseSearchSerializer,
CourseSerializer,
ReviewSerializer,
)

from lib import constants
from lib.departments import get_department_name
from lib.grades import numeric_value_for_grade
from lib.terms import numeric_value_of_term

import datetime
import uuid
import dateutil.parser

from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db.models import Count
from rest_framework.authentication import SessionAuthentication
from rest_framework.decorators import (
api_view,
permission_classes,
)
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response


LIMITS = {
"courses": 20,
"reviews": 5,
Expand Down
2 changes: 1 addition & 1 deletion docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Environment:

3. `git checkout dev`

4. `uv sync`
4. `uv sync --all-groups`

5. `uv run pre-commit install` (for installing git hook in .git)

Expand Down
2 changes: 1 addition & 1 deletion frontend
43 changes: 24 additions & 19 deletions pyproject.toml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can configure depandabot to regularly update dependencies and PR. Fixing version like this is OK and indeed prevent an ever changing uv.lock.

Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
[project]
name = ""
name = "course-review"
requires-python = ">=3.14, <3.15"
version = "0.0.1"
dependencies = [
"beautifulsoup4>=4.13.3",
"dj-database-url>=2.3.0",
"django>=5.1.6",
"django-debug-toolbar>=5.0.1",
"httpx>=0.28.1",
"psycopg2-binary>=2.9.10",
"python-dateutil>=2.9.0",
"python-dotenv>=1.0.1",
"pytz>=2025.1",
"redis>=5.2.1",
"requests>=2.32.3",
"bpython>=0.25",
"ptpython>=3.0.29",
"djangorestframework>=3.16.0",
"django-cors-headers>=4.7.0",
"django-redis",
"pyyaml>=6.0.2",
"beautifulsoup4==4.14.2",
"dj-database-url==3.0.1",
"django==5.2.8",
"django-debug-toolbar==6.1.0",
"httpx==0.28.1",
"psycopg2-binary==2.9.11",
"python-dateutil==2.9.0",
"python-dotenv==1.2.1",
"pytz==2025.2",
"redis==7.1.0",
"requests==2.32.5",
"bpython==0.26",
"greenlet==3.2.4",
"ptpython==3.0.31",
"djangorestframework==3.16.1",
"django-cors-headers==4.9.0",
"django-redis==6.0.0",
"pyyaml==6.0.3",
]

[tool.uv]
package = false

[dependency-groups]
dev = [
"pre-commit>=4.3.0",
"pre-commit==4.4.0",
]
lint = [
"ruff==0.14.5",
]
27 changes: 0 additions & 27 deletions scripts/pre-commit-format.py

This file was deleted.

Loading
Loading