Skip to content

Commit

Permalink
Merge pull request #40 from ochan1/website-fixes
Browse files Browse the repository at this point in the history
Private Storage + Other Fixes
  • Loading branch information
ochan1 authored Sep 9, 2022
2 parents a262e7e + 1047f54 commit 5dabe52
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 10 deletions.
3 changes: 3 additions & 0 deletions base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def __str__(self):
if self.current:
name += ' (Current)'
return name

def __hash__(self):
return hash(self.__term_as_int())

def _calculate_pk(self):
return self.year * 10 + self.__term_as_int()
Expand Down
3 changes: 3 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def symlink_release(c: Connection):
print("-- Symlinking current@ to release")
c.run("ln -sfn {} {}".format(c.release_path, c.current_path), echo=True)

def run_permission(c: Connection):
print("-- Granting run file permission")
c.run("chmod +x {}/run".format(c.current_path), echo=True)

def systemd_restart(c: Connection):
print("-- Restarting systemd unit")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ tblib==1.7.0
urllib3==1.25.6
vobject==0.9.6.1
whitenoise==4.1.1
django-private-storage==3.0
4 changes: 2 additions & 2 deletions resumes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings
from django.db import models

from private_storage.fields import PrivateFileField

class Resume(models.Model):
RESUMES_LOCATION = 'resumes'
Expand Down Expand Up @@ -33,7 +33,7 @@ def rename_file(instance, filename):
verbose_name='GPA', max_digits=4, decimal_places=3,
help_text='GPA must have three decimal places (ex. 3.750)')
full_text = models.TextField(help_text='Full text of the resume')
resume_file = models.FileField(
resume_file = PrivateFileField(
upload_to=rename_file,
verbose_name='File', help_text='PDF only please')
# Each resume must be manually verified by an officer to determine
Expand Down
3 changes: 2 additions & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ fi
# PYTHONPATH=~/public_html/tbpweb/src:$PYTHONPATH

# TODO ?
# DJANGO_SETTINGS_MODULE=tbpweb.settings
# DJANGO_WSGI_MODULE=tbpweb.wsgi

export DJANGO_SETTINGS_MODULE=settings

DJANGO_DIR=~/tbpweb/prod/current
VENV=~/tbpweb/prod/shared/venv
SOCKFILE=/srv/apps/$(whoami)/tbp.sock
Expand Down
10 changes: 5 additions & 5 deletions settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/'

# Private Storage for Pip package django-private-storage
PRIVATE_STORAGE_ROOT = os.path.join(WORKSPACE_DJANGO_ROOT, 'private-media')
PRIVATE_STORAGE_AUTH_FUNCTION = 'private_storage.permissions.allow_authenticated'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
Expand All @@ -138,11 +142,6 @@
# URL prefix for static files.
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = [
os.path.join(WORKSPACE_DJANGO_ROOT, "static"),
]

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
Expand Down Expand Up @@ -230,6 +229,7 @@
'notifications',
'past_presidents',
'project_reports',
'private_storage',
'quote_board',
'resumes',
'syllabi',
Expand Down
5 changes: 5 additions & 0 deletions settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
'tbp.berkeley.edu'
]

# Additional locations of static files
STATICFILES_DIRS = [
os.path.join(WORKSPACE_DJANGO_ROOT, "static"),
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = 'https://www.ocf.berkeley.edu/~tbp/tbpweb/static/'
Expand Down
5 changes: 3 additions & 2 deletions urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.conf import settings
from django.urls import include
from django.urls import path, re_path
from django.urls import include, path, re_path
from django.contrib.flatpages import views
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.generic import RedirectView

import private_storage.urls

admin.autodiscover()

Expand All @@ -29,6 +29,7 @@
path('newsreel/', include(('newsreel.urls', 'newsreel'), namespace='newsreel')),
path('notifications/', include(('notifications.urls', 'notifications'), namespace='notifications')),
path('past-presidents/', include(('past_presidents.urls', 'past-presidents'), namespace='past-presidents')),
path('private-media/', include(private_storage.urls)),
path('profile/', include(('user_profiles.urls', 'user-profiles'), namespace='user-profiles')),
path('project-reports/', include(('project_reports.urls', 'project-reports'), namespace='project-reports')),
path('quote-board/', include(('quote_board.urls', 'quote-board'), namespace='quote-board')),
Expand Down

0 comments on commit 5dabe52

Please sign in to comment.