Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrading python and django to latest #177

Merged
merged 4 commits into from
Jan 11, 2025
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
9 changes: 5 additions & 4 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.13]

steps:
- uses: actions/checkout@v2
Expand All @@ -32,6 +32,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests
run: |
python manage.py test ponder.tests
# Disabling tests for now as it requires a DB to connect to.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Commenting out these tests for now as it requires a DB setup to connect to to run the tests against. Maybe look into local testing for now. Will create an issue for this.

# - name: Run Tests
# run: |
# python manage.py test ponder.tests
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ https://fathomless-inlet-57767.herokuapp.com

## Setup/Run Instructions
### Pre-requisites
- Ensure Django is set up: https://docs.djangoproject.com/en/3.1/topics/install/

#### Version Requirements
```aiignore
Python 3.13.1
Pip: 3.13
Django: 5.1.4
```
- Ensure Django is set up: https://docs.djangoproject.com/en/5.1/topics/install/
- For MySQL databases, ensure mysql is set up: https://dev.mysql.com/doc/refman/8.0/en/installing.html
- Additionally, also ensure `mysqlclient` is installed (either via Brew or other methods) https://pypi.org/project/mysqlclient/
- Ensure the below PATH is exported in your environment `export DYLD_LIBRARY_PATH="/usr/local/mysql/lib/"`
Expand All @@ -15,15 +22,17 @@ https://fathomless-inlet-57767.herokuapp.com
### Run Instructions
1) Ensure all pre-requisites above are met.
2) Install dependencies: `pip install -r requirements.txt`
3) Run the app: `python manage.py runserver`
4) Navigate to: `localhost:8000` to view the app.
5) To create an admin account, `python manage.py createsuperuser` and follow instructions to provide account credentials.
3) Ensure database is set up correctly (both remote and local as needed), see instructions below.
4) Run the app: `python manage.py runserver`
5) Navigate to: `localhost:8000` to view the app.
6) To create an admin account, `python manage.py createsuperuser` and follow instructions to provide account credentials.

- Debug: If the above `localhost:8000` page throws an access error, consider adding `localhost` to `ALLOWED_HOSTS` in the `settings.py` file.
- Debug: If you run into error regarding `STATIC_ROOT` see: https://github.com/OpenToAllCTF/OTA-University/issues/9 suggestion to change `STATIC_ROOT` assignment to just `/static/`

### Connect to a database
1) Create a database and configure the `DATABASES` dictionary in the `settings.py` file to connect to it.
1) Create a database and configure the `DATABASES` dictionary in the `settings.py` file to connect to it.
2) See steps below to set up a local database if needed.
2) Run migrations to create the schema using the commands:
```bash
python manage.py makemigrations
Expand Down
50 changes: 31 additions & 19 deletions mysite/settings.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 3.1.5.

*Upgraded to Django 5.1.4 on Jan 10th, 2025. See 5.1 versions of the docs below

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
https://docs.djangoproject.com/en/5.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
https://docs.djangoproject.com/en/5.1/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
ROOT_PATH = Path(__file__).resolve().parent.parent
BASE_DIR = os.path.join(ROOT_PATH,'ponder')

TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')
STATIC_DIR = os.path.join(BASE_DIR,'static')
MEDIA_DIR = os.path.join(BASE_DIR,'media')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#f)c)#%(9gcx9d27nh_4#1aghrgo$xqgx!kqzk2-()ccwv1mc3'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True # We are currently in dev per #16.

ALLOWED_HOSTS = ['fathomless-inlet-57767.herokuapp.com']
ALLOWED_HOSTS = ['fathomless-inlet-57767.herokuapp.com', 'localhost']


# Application definition
Expand Down Expand Up @@ -82,25 +87,32 @@


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases

DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'heroku_4ac11fb2946b4e7',
# 'USER': 'be05ffb901b132',
# 'PASSWORD': '3d94000c',
# 'HOST': 'us-cdbr-east-03.cleardb.com',
# # 'OPTIONS': {'ssl_mode': 'DISABLED'}
# 'TEST': {
# 'MIRROR': 'default',
# },
# },
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'heroku_4ac11fb2946b4e7',
'USER': 'be05ffb901b132',
'PASSWORD': '3d94000c',
'HOST': 'us-cdbr-east-03.cleardb.com',
# 'OPTIONS': {'ssl_mode': 'DISABLED'}
'TEST': {
'MIRROR': 'default',
},
'ENGINE': 'django.db.backends.mysql', # Or other DBs as needed.
'NAME': '<LOCAL_DB_DATABASE_NAME>',
'USER': '<LOCAL_DB_USER>',
'PASSWORD': '<LOCAL_DB_PASSWORD>',
'HOST': '127.0.0.1',
}
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
Expand Down Expand Up @@ -135,7 +147,7 @@
]

# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
# https://docs.djangoproject.com/en/5.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

Expand All @@ -149,7 +161,7 @@


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Expand All @@ -164,4 +176,4 @@

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
18 changes: 9 additions & 9 deletions mysite/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from django.contrib import admin
from django.urls import path
from django.conf.urls import url,include
from django.urls import re_path, path
from django.conf.urls import include
from ponder import views
from django.conf import settings

urlpatterns = [
path('admin/', admin.site.urls),
url(r'^$',views.index,name='index'),
url(r'^special/',views.special,name='special'),
url(r'^',include('ponder.urls')),
url(r'^logout/$', views.user_logout, name='logout'),
url(r'^bug_fixes/', views.categorizations_by_bugFixID, name='id'),
re_path(r'^$',views.index,name='index'),
re_path(r'^special/',views.special,name='special'),
re_path(r'^',include('ponder.urls')),
re_path(r'^logout/$', views.user_logout, name='logout'),
re_path(r'^bug_fixes/', views.categorizations_by_bugFixID, name='id'),
]

if settings.DEBUG:
import debug_toolbar

urlpatterns += [
url(r'^__debug__/', include(debug_toolbar.urls)),
]
re_path(r'^__debug__/', include(debug_toolbar.urls)),
]
16 changes: 8 additions & 8 deletions ponder/templates/ponder/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</a>
<center></center><h2>Welcome to the Ponder's Web App !</h2></center>
{% if user.is_authenticated %}
{% ifequal user.groups.all.0.name "Admin" %}
{% if user.groups.all.0.name == "Admin" %}
<h2>Hello, Admin! </h2>
{% else %}
<h2>Hello, {{ user.username }}! </h2>
{% endifequal %}
{% endif %}
<div class="dropdown" style="float: right; width: 200px;">
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="width: 200px; height: 40px; font-size: 18px; float: right; margin: -45px 10px; border-style: dotted; border-radius: 3px; background-color: white;">
{% if user.groups.all %}
Expand All @@ -29,19 +29,19 @@ <h2>Hello, {{ user.username }}! </h2>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
{% for group in groups %}
<li><a class="dropdown-item" href="{% url 'ponder:index' %}?role={{group}}" style="font-size: 16px;">{{group}}</a></li>
{% endfor %}
{% endfor %}
</ul>
</div>
{% else %}
<h2>Login if you'd like to</h2>
{% endif %}
</div>
{% if user.is_authenticated %}
{% ifequal user.groups.all.0.name "Admin" %}
{% if user.groups.all.0.name == "Admin" %}
<center><h1>Categorizations Page for Admin</h1></center>
{% else %}
<center><h1>Categorizations Page for {{ user.username }}</h1></center>
{% endifequal %}
{% endif %}
<div class="row">
{% for project in projects %}
{% if project == "Commits" and perms.ponder.view_commit or project == "Categorizations" and perms.ponder.view_categorization or project == "Bug Fixes" and perms.ponder.view_bugfix %}
Expand All @@ -56,7 +56,7 @@ <h2 class="card-title">{{ project }}</h2>
View commits
</a>
{% elif project == "Categorizations"%}
{% ifnotequal user.groups.all.0.name "Categorizer" %}
{% if user.groups.all.0.name != "Categorizer" %}
<p class="card-text">View all categorizations.</p>
<a href="{% url 'ponder:categorizations_filter' %}"
class="btn btn-primary">
Expand All @@ -68,7 +68,7 @@ <h2 class="card-title">{{ project }}</h2>
class="btn btn-primary">
View your categorizations
</a>
{% endifnotequal %}
{% endif %}
{% else %}
<p class="card-text">View the agreed upon categorizations for each sha.</p>
<a href="{% url 'ponder:bugfixes_table' %}"
Expand All @@ -83,4 +83,4 @@ <h2 class="card-title">{{ project }}</h2>
{% endfor %}
{% endif %}
</div>
{% endblock %}
{% endblock %}
16 changes: 8 additions & 8 deletions ponder/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from django.urls import path,include
from django.conf.urls import url
from django.urls import re_path,path,include

from django.views.generic import TemplateView
from . import views
app_name = 'ponder'

urlpatterns=[
url(r'^$',views.index,name='index'),
url(r'^user_login/$',views.user_login,name='user_login'),
re_path(r'^$',views.index,name='index'),
re_path(r'^user_login/$',views.user_login,name='user_login'),
path('commits/<str:pk>', views.CommitDetailsTableView.as_view(), name='commits_details'),
url('commits', views.CommitsTableView, name='commits_table'),
re_path('commits', views.CommitsTableView, name='commits_table'),
path('bug_fixes/', views.BugFixesTableView.as_view(), name='bugfixes_table'),
url('bug_fixes/<int:pk>', views.categorizations_by_bugFixID, name='id'),
re_path('bug_fixes/<int:pk>', views.categorizations_by_bugFixID, name='id'),
path('categorizations/update_categorization', views.update_categorization, name='update_categorization'),
path('categorizations/delete_categorization', views.delete_categorization, name='delete_categorization'),
path('categorizations/new', views.AddCategorization, name='categorizations_add'),
url('categorizations', views.categorizations_by_userID, name='categorizations_filter'),
re_path('categorizations', views.categorizations_by_userID, name='categorizations_filter'),
path('success_categorization/<str:pk>', views.success_categorization, name='success_categorization'),
path('forbidden/', views.permission_denied, name='permission_denied'),
path('categorizers/new', views.AddCategorizer, name='categorizers_add'),
]
]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
django==3.2.8
django==5.1.4
mysqlclient
gunicorn
django-tables2
Expand All @@ -10,4 +10,4 @@ django-debug-toolbar
django-widget-tweaks
django-bootstrap-modal-forms
djangorestframework
pytz
pytz
Loading