Remind me to never use Django again

This commit is contained in:
Fergal Moran
2018-11-02 00:45:43 +00:00
parent 66668cd58f
commit 63c86d31e9
6 changed files with 31 additions and 34 deletions

View File

@@ -14,4 +14,4 @@ RUN mkdir /files/static && \
chmod +x /code/run_celery.sh
WORKDIR /code
RUN pip install -r requirements.txt
#RUN pip install -r requirements.txt

View File

@@ -1,37 +1,33 @@
from azure.common import AzureMissingResourceHttpError
from azure.storage.blob import BlobService
from azure.storage.blob import BlockBlobService, ContentSettings
from dss import settings
from dss.storagesettings import AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY, AZURE_CONTAINER
def upload_file_to_azure(in_file, file_name, container_name=settings.AZURE_CONTAINER):
def upload_file_to_azure(in_file, file_name, content_type='audio/mpeg', container_name=settings.AZURE_CONTAINER):
try:
blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY)
blob_service.put_block_blob_from_path(
blob_service = BlockBlobService(account_name=AZURE_ACCOUNT_NAME, account_key=AZURE_ACCOUNT_KEY)
blob_service.create_blob_from_path(
container_name=container_name,
blob_name=file_name,
file_path=in_file,
x_ms_blob_content_type='application/octet-stream'
content_settings=ContentSettings(content_type=content_type)
)
except Exception as ex:
print("Failed to upload blob: {0}".format(ex))
def set_azure_details(blob_name, download_name, container_name=AZURE_CONTAINER):
def set_azure_details(blob_name, download_name, content_type='audio/mpeg', container_name=AZURE_CONTAINER):
try:
blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY)
blob = blob_service.get_blob(container_name, blob_name)
if blob:
blob_service.set_blob_properties(
container_name,
blob_name,
x_ms_blob_content_type='audio/mpeg',
x_ms_blob_content_disposition='attachment;filename="{0}"'.format(download_name)
)
print("Processed: %s" % download_name)
else:
print("No blob found for: %s" % download_name)
blob_service = BlockBlobService(account_name=AZURE_ACCOUNT_NAME, account_key=AZURE_ACCOUNT_KEY)
blob_service.set_blob_properties(
container_name,
blob_name,
content_settings=ContentSettings(content_type=content_type,
content_disposition='attachment;filename="{0}"'.format(download_name))
)
print("Processed: %s" % download_name)
except AzureMissingResourceHttpError:
print("No blob found for: %s" % download_name)
except Exception as ex:
@@ -50,7 +46,7 @@ def file_exists(url):
def enumerate_objects(container):
blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY)
blob_service = BlockBlobService(account_name=AZURE_ACCOUNT_NAME, account_key=AZURE_ACCOUNT_KEY)
blobs = blob_service.list_blobs(container)
items = []
for blob in blobs:
@@ -60,5 +56,5 @@ def enumerate_objects(container):
def delete_object(container, name):
blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY)
blob_service = BlockBlobService(account_name=AZURE_ACCOUNT_NAME, account_key=AZURE_ACCOUNT_KEY)
blob_service.delete_blob(container, name)

View File

@@ -16,9 +16,9 @@ DATABASE_HOST = os.environ.get('DATABASE_HOST', 'localhost')
STATIC_URL = '/assets/'
MEDIA_ROOT = os.environ.get('MEDIA_ROOT', '/mnt/dev/deepsouthsounds.com/media')
STATIC_ROOT = os.environ.get('STATIC_ROOT', '/home/fergalm/dev/personal/deepsouthsounds.com/cache/static')
CACHE_ROOT = os.environ.get('CACHE_ROOT', '/mnt/dev/deepsouthsounds.com/cache')
MEDIA_ROOT = os.environ.get('MEDIA_ROOT', '/home/fergalm/dev/deepsouthsounds.com/media')
STATIC_ROOT = os.environ.get('STATIC_ROOT', '/home/fergalm/dev/deepsouthsounds.com/cache/static')
CACHE_ROOT = os.environ.get('CACHE_ROOT', '/home/fergalm/dev/deepsouthsounds.com/cache')
MEDIA_URL = os.environ.get('MEDIA_URL', 'http://localhost/DSSMedia/') # '{0}media/'.format(CDN_URL)

View File

@@ -16,6 +16,9 @@ from dss.psa import *
from dss.celerysettings import *
from dss.localsettings import *
DEBUG = False
DEFAULT_FILE_STORAGE = 'storages.backends.azure_storage.AzureStorage'
DEVELOPMENT = DEBUG
# AUTH_USER_MODEL = 'spa.UserProfile'
@@ -95,7 +98,7 @@ TEMPLATES = [
},
]
MIDDLEWARE_CLASSES = [
MIDDLEWARE = [
'django.middleware.gzip.GZipMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -160,7 +163,7 @@ INSTALLED_APPS = (
LOGIN_REDIRECT_URL = reverse_lazy('home')
LOGOUT_URL = reverse_lazy('home')
FACEBOOK_APP_ID = '154504534677009'
FACEBOOK_APP_ID = '344996219591469'
AVATAR_STORAGE_DIR = MEDIA_ROOT + '/avatars/'
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
@@ -225,8 +228,6 @@ DEFAULT_WAVEFORM_GENERATING = '/assets/images/waveform-interstitial.gif'
SITE_NAME = 'Deep South Sounds'
THUMBNAIL_PREFIX = '_tn/'
# THUMBNAIL_STORAGE = 'storages.backends.azure_storage.AzureStorage'
JWT_AUTH = {
'JWT_EXPIRATION_DELTA': timedelta(seconds=(60 * 60 * 24) * 14),
# 'JWT_EXPIRATION_DELTA': timedelta(seconds=5),

View File

@@ -2,8 +2,9 @@ Django==2.1.2
django-extensions
django-sendfile
Werkzeug
psycopg2
gunicorn
psycopg2-binary
dropbox
django-dirtyfields
django-storages
@@ -23,9 +24,8 @@ django-celery
django-scheduler
django-recurrence
django-compressor
azure
azure-storage==0.20.0
sorl-thumbnail

View File

@@ -3,8 +3,8 @@ from django.conf.urls import url
from spa.podcast.views import favourites, following, user, featured
urlpatterns = [
url(r'^(?P<uid>[\w\d_.-]+)/favourites/?$', favourites, name='podast_favourites_slug'),
url(r'^(?P<uid>[\w\d_.-]+)/following/?$', following, name='podast_following_slug'),
url(r'^(?P<uid>[\w\d_.-]+)/favourites/?$', favourites, name='podcast_favourites_slug'),
url(r'^(?P<uid>[\w\d_.-]+)/following/?$', following, name='podcast_following_slug'),
url(r'^(?P<slug>[\w\d_.-]+)/?$', user, name='podast_user_slug'),
url(r'^/?$', featured, name='podast_featured_slug'),
url(r'', featured, name='`podcast_featured_slug'),
]