diff --git a/PDMI/PDMI/settings.py b/PDMI/PDMI/settings.py index c500787..96f94bd 100644 --- a/PDMI/PDMI/settings.py +++ b/PDMI/PDMI/settings.py @@ -126,6 +126,9 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, 'static/'), +) # Logout redirect url @@ -134,3 +137,7 @@ LOGOUT_REDIRECT_URL = reverse_lazy('store_front_page') # Login redirect url LOGIN_REDIRECT_URL = reverse_lazy('store_front_page') + +# Media_root + +MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') diff --git a/PDMI/db.sqlite3 b/PDMI/db.sqlite3 index fa00657..0209b69 100644 Binary files a/PDMI/db.sqlite3 and b/PDMI/db.sqlite3 differ diff --git a/PDMI/front/templates/front/index.html b/PDMI/front/templates/front/index.html index 9382cbc..3d67b78 100644 --- a/PDMI/front/templates/front/index.html +++ b/PDMI/front/templates/front/index.html @@ -50,12 +50,6 @@ - - {% endblock %} diff --git a/PDMI/static/dropzone-5.7.0/.gitignore b/PDMI/static/dropzone-5.7.0/.gitignore new file mode 100644 index 0000000..0a8439d --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/.gitignore @@ -0,0 +1,7 @@ +build +components +node_modules +.DS_Store +.sass-cache +_site +_config.yaml \ No newline at end of file diff --git a/PDMI/static/dropzone-5.7.0/.tagconfig b/PDMI/static/dropzone-5.7.0/.tagconfig new file mode 100644 index 0000000..4e0cad9 --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/.tagconfig @@ -0,0 +1,52 @@ +{ + "files": [ + { + "name": "src/dropzone.coffee", + "regexs": [ + "Dropzone.version = \"###\"" + ] + }, + { + "name": "dist/dropzone.js", + "regexs": [ + "version = \"###\"" + ] + }, + { + "name": "dist/min/dropzone.min.js", + "regexs": [ + "version=\"###\"" + ] + }, + { + "name": "dist/dropzone-amd-module.js", + "regexs": [ + "version = \"###\"" + ] + }, + { + "name": "dist/min/dropzone-amd-module.min.js", + "regexs": [ + "version=\"###\"" + ] + }, + { + "name": "package.json", + "regexs": [ + "\"version\": \"###\"" + ] + }, + { + "name": "component.json", + "regexs": [ + "\"version\": \"###\"" + ] + }, + { + "name": "bower.json", + "regexs": [ + "\"version\": \"###\"" + ] + } + ] +} diff --git a/PDMI/static/dropzone-5.7.0/CONTRIBUTING.md b/PDMI/static/dropzone-5.7.0/CONTRIBUTING.md new file mode 100644 index 0000000..98aebe0 --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/CONTRIBUTING.md @@ -0,0 +1,6 @@ +Contribute +========== + +DO NOT CREATE PULL REQUESTS ON GITHUB! + +I will simply close them. If you want to contribute, please use [gitlab.com](https://gitlab.com/meno/dropzone) instead. \ No newline at end of file diff --git a/PDMI/static/dropzone-5.7.0/LICENSE b/PDMI/static/dropzone-5.7.0/LICENSE new file mode 100644 index 0000000..2ec3379 --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/LICENSE @@ -0,0 +1,12 @@ +License + +(The MIT License) + +Copyright (c) 2012 Matias Meno +Logo & Website Design (c) 2015 "1910" www.weare1910.com + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/PDMI/static/dropzone-5.7.0/README.md b/PDMI/static/dropzone-5.7.0/README.md new file mode 100644 index 0000000..a22b3a1 --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/README.md @@ -0,0 +1,36 @@ +Dropzone.js + +Dropzone.js is a light weight JavaScript library that turns an HTML element into a dropzone. +This means that a user can drag and drop a file onto it, and the file gets uploaded to the server via AJAX. + +* * * + +_If you want support, please use [stackoverflow](http://stackoverflow.com/) with the `dropzone.js` tag and not the +GitHub issues tracker. Only post an issue here if you think you discovered a bug or have a feature request._ + +* * * + +**Please read the [contributing guidelines](CONTRIBUTING.md) before you start working on Dropzone!** + +
+
+ >> Download << +
+
+
+ +This is no longer the official repository for Dropzone. I have switched to [gitlab.com](https://gitlab.com/meno/dropzone) +as the primary location to continue development. + +There are multiple reasons why I am switching from GitHub to GitLab, but a few of the reasons are the +issue tracker that GitHub is providing, *drowning* me in issues that I am unable to categorise or prioritize properly, +the lack of proper continuous integration, and build files. I don't want the compiled `.js` files in my repository, and +people regularly commit changes to the compiled files and create pull requests with them. + +I will write a blog post soon, that goes into detail about why I am doing the switch. + +This repository will still remain, and always host the most up to date versions of dropzone, but only the distribution +files! + +MIT License +----------- diff --git a/PDMI/static/dropzone-5.7.0/bower.json b/PDMI/static/dropzone-5.7.0/bower.json new file mode 100644 index 0000000..0d5a701 --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/bower.json @@ -0,0 +1,16 @@ +{ + "name": "dropzone", + "location": "enyo/dropzone", + "version": "5.7.0", + "description": "Dropzone is an easy to use drag'n'drop library. It supports image previews and shows nice progress bars.", + "homepage": "http://www.dropzonejs.com", + "main": [ + "dist/min/dropzone.min.css", + "dist/min/dropzone.min.js" + ], + "ignore": [ + "*", + "!dist", + "!dist/**/*" + ] +} diff --git a/PDMI/static/dropzone-5.7.0/component.json b/PDMI/static/dropzone-5.7.0/component.json new file mode 100644 index 0000000..815c58e --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/component.json @@ -0,0 +1,10 @@ +{ + "name": "dropzone", + "repo": "enyo/dropzone", + "version": "5.7.0", + "description": "Handles drag and drop of files for you.", + "scripts": [ "index.js", "dist/dropzone.js" ], + "styles": [ "dist/basic.css" ], + "dependencies": { }, + "license": "MIT" +} diff --git a/PDMI/static/dropzone-5.7.0/composer.json b/PDMI/static/dropzone-5.7.0/composer.json new file mode 100644 index 0000000..6be6387 --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/composer.json @@ -0,0 +1,18 @@ +{ + "name": "enyo/dropzone", + "description": "Handles drag and drop of files for you.", + "homepage": "http://www.dropzonejs.com", + "keywords": [ + "dragndrop", + "drag and drop", + "file upload", + "upload" + ], + "authors": [{ + "name": "Matias Meno", + "email": "m@tias.me", + "homepage": "http://www.matiasmeno.com" + }], + "license": "MIT", + "minimum-stability": "dev" +} diff --git a/PDMI/static/dropzone-5.7.0/index.js b/PDMI/static/dropzone-5.7.0/index.js new file mode 100644 index 0000000..4a1d413 --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/index.js @@ -0,0 +1 @@ +module.exports = require("./dist/dropzone.js"); // Exposing dropzone diff --git a/PDMI/static/dropzone-5.7.0/package.json b/PDMI/static/dropzone-5.7.0/package.json new file mode 100644 index 0000000..555f58c --- /dev/null +++ b/PDMI/static/dropzone-5.7.0/package.json @@ -0,0 +1,40 @@ +{ + "name": "dropzone", + "version": "5.7.0", + "description": "Handles drag and drop of files for you.", + "keywords": [ + "dragndrop", + "drag and drop", + "file upload", + "upload" + ], + "homepage": "http://www.dropzonejs.com", + "main": "./dist/dropzone.js", + "maintainers": [ + { + "name": "Matias Meno", + "email": "m@tias.me", + "web": "http://www.colorglare.com" + } + ], + "contributors": [ + { + "name": "Matias Meno", + "email": "m@tias.me", + "web": "http://www.colorglare.com" + } + ], + "scripts": { + "test": "grunt && npm run test-prebuilt", + "test-prebuilt": "mocha-headless-chrome -f test/test-prebuilt.html -a no-sandbox -a disable-setuid-sandbox" + }, + "bugs": { + "email": "m@tias.me", + "url": "https://gitlab.com/meno/dropzone/issues" + }, + "license": "MIT", + "repository": { + "type": "git", + "url": "https://gitlab.com/meno/dropzone.git" + } +} diff --git a/PDMI/store/forms.py b/PDMI/store/forms.py index 4d86765..483e0e4 100644 --- a/PDMI/store/forms.py +++ b/PDMI/store/forms.py @@ -1,6 +1,8 @@ from django.contrib.auth.forms import UserCreationForm, AuthenticationForm from django.contrib.auth.models import User from bootstrap_modal_forms.mixins import PopRequestMixin, CreateUpdateAjaxMixin +from django import forms +from .models import Module class CustomUserCreationForm(PopRequestMixin, CreateUpdateAjaxMixin, UserCreationForm): @@ -12,3 +14,6 @@ class CustomAuthenticationForm(AuthenticationForm): class Meta: model = User fields = ['username', 'password'] + +class FileFieldForm(forms.Form): + file = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True})) diff --git a/PDMI/store/models.py b/PDMI/store/models.py index 71a8362..6d5ee67 100644 --- a/PDMI/store/models.py +++ b/PDMI/store/models.py @@ -1,3 +1,6 @@ from django.db import models -# Create your models here. +class Module(models.Model): + file = models.FileField() + name = models.CharField(max_length=255) + desc = models.TextField(max_length=2048) diff --git a/PDMI/store/response.py b/PDMI/store/response.py new file mode 100644 index 0000000..b4b0065 --- /dev/null +++ b/PDMI/store/response.py @@ -0,0 +1,32 @@ +# encoding: utf-8 +from django.http import HttpResponse +import json + +MIMEANY = '*/*' +MIMEJSON = 'application/json' +MIMETEXT = 'text/plain' + + +def response_mimetype(request): + """response_mimetype -- Return a proper response mimetype, accordingly to + what the client accepts, as available in the `HTTP_ACCEPT` header. + request -- a HttpRequest instance. + """ + can_json = MIMEJSON in request.META['HTTP_ACCEPT'] + can_json |= MIMEANY in request.META['HTTP_ACCEPT'] + return MIMEJSON if can_json else MIMETEXT + + +class JsonResponse(HttpResponse): + """JSONResponse -- Extends HTTPResponse to handle JSON format response. + This response can be used in any view that should return a json stream of + data. + Usage: + def a_iew(request): + content = {'key': 'value'} + return JSONResponse(content, mimetype=response_mimetype(request)) + """ + def __init__(self, obj='', json_opts=None, mimetype=MIMEJSON, *args, **kwargs): + json_opts = json_opts if isinstance(json_opts, dict) else {} + content = json.dumps(obj, **json_opts) + super(JsonResponse, self).__init__(content, mimetype, *args, **kwargs) diff --git a/PDMI/store/templates/store/store-navbar.html b/PDMI/store/templates/store/store-navbar.html index 3eaf248..534e33b 100644 --- a/PDMI/store/templates/store/store-navbar.html +++ b/PDMI/store/templates/store/store-navbar.html @@ -8,7 +8,6 @@ diff --git a/PDMI/store/templates/store/upload.html b/PDMI/store/templates/store/upload.html new file mode 100644 index 0000000..2de33ce --- /dev/null +++ b/PDMI/store/templates/store/upload.html @@ -0,0 +1,83 @@ +{% extends "base/base.html" %} +{% load static %} +{% block extra_static %} + + +{% endblock extra_static %} +{% block body %} +
+
+ + +
+
+ + +{% endblock body %} diff --git a/PDMI/store/urls.py b/PDMI/store/urls.py index 00fdcca..2d52cc5 100644 --- a/PDMI/store/urls.py +++ b/PDMI/store/urls.py @@ -22,5 +22,6 @@ urlpatterns = [ path('', TemplateView.as_view(template_name='store/index.html'), name='store_front_page'), path('login/', views.CustomLoginView.as_view(), name='login'), path('signup/', views.SignUpView.as_view(), name='signup'), - path('logout/', LogoutView.as_view(), name='logout') + path('logout/', LogoutView.as_view(), name='logout'), + path('upload/', views.FileFieldView.as_view(), name='upload'), ] diff --git a/PDMI/store/views.py b/PDMI/store/views.py index eda8f31..ec01af0 100644 --- a/PDMI/store/views.py +++ b/PDMI/store/views.py @@ -2,6 +2,11 @@ from django.shortcuts import render from django.urls import reverse_lazy from bootstrap_modal_forms.generic import BSModalCreateView, BSModalLoginView from .forms import CustomUserCreationForm, CustomAuthenticationForm +from django.views.generic.edit import FormView +from .forms import FileFieldForm +import os +import PDMI.settings as settings +from .response import response_mimetype, JsonResponse class SignUpView(BSModalCreateView): form_class = CustomUserCreationForm @@ -14,3 +19,20 @@ class CustomLoginView(BSModalLoginView): template_name = 'store/login.html' success_message = 'Success: You were successfully logged in.' extra_content = dict(success_url=reverse_lazy('index')) + +class FileFieldView(FormView): + form_class = FileFieldForm + template_name = 'store/upload.html' + + def post(self, request, *args, **kwargs): + form_class = self.get_form_class() + form = self.get_form(form_class) + files = request.FILES.getlist('file') + if form.is_valid(): + for f in files: + with open(os.path.join(settings.MEDIA_ROOT, f.name), 'wb+') as destination: + for chunk in f.chunks(): + destination.write(chunk) + return JsonResponse({'form': True}) + else: + return JsonResponse({'form': False}) diff --git a/PDMI/templates/base/base.html b/PDMI/templates/base/base.html index 5738c04..e3d42a5 100644 --- a/PDMI/templates/base/base.html +++ b/PDMI/templates/base/base.html @@ -19,6 +19,7 @@ + {% block extra_static %}{% endblock extra_static %} {% block navbar %}