43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
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
|
|
template_name = 'store/signup_modal.html'
|
|
success_message = 'Success: Sign up succeeded. You can now Log in.'
|
|
success_url = reverse_lazy('store_front_page')
|
|
|
|
|
|
class CustomLoginView(BSModalLoginView):
|
|
authentication_form = CustomAuthenticationForm
|
|
template_name = 'store/login_modal.html'
|
|
success_message = 'Success: You were successfully logged in.'
|
|
extra_content = dict(success_url=reverse_lazy('index'))
|
|
|
|
|
|
class UploadView(LoginRequiredMixin, 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})
|