def mylogin(request): if request.method == "POST": username = request.POST.get("username", "") password = request.POST.get("password", "") user = authenticate(username=username, password=password) if user is not None: login(request, user) return HttpResponseRedirect(reverse("file_list")) else: return render(request, "app/login.html", {"message": _(u"Incorrect username or password")}) else: return render(request, "app/login.html")
def file_list(request): module_thumbnails = settings.THUMBNAIL_MODULE if request.user.is_superuser: users = User.objects.all() else: users = User.objects.filter(pk=request.user.id) return render(request, "app/file_list.html", {"users": users, "module_thumbnails": module_thumbnails})
def delete_user(request, id): user = get_object_or_404(User, pk=id) if user.is_superuser: raise Http404 if request.method == "POST": user.delete() return HttpResponseRedirect(reverse("manage_users")) else: return render(request, "app/delete_user.html", {"show_form": True, "this_user": user})
def set_password(request, id): user = get_object_or_404(User, pk=id) if request.method == "POST": form = SetPasswordForm(user, request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse("manage_users")) else: form = SetPasswordForm(user) return render(request, "app/set_password.html", {"form": form, "this_user": user})
def send_instructions(request, id): user = get_object_or_404(User, pk=id) if user.is_superuser: raise Http404 if request.method == "POST": form = InstructionsForm(request.POST) if form.is_valid(): form.send(user.username, RawPassword.objects.get(user=user).password) return HttpResponseRedirect(reverse("file_list")) else: form = InstructionsForm() return render(request, "app/send_instructions.html", {"form": form})
def add_file(request, user_id): user = get_object_or_404(User, pk=user_id) # Only superusers or the owner can upload files to that profile. if not request.user.is_superuser and request.user != user: raise Http404 if request.method == "POST": xs = sorted(get_field_numbers(request.FILES)) new_post = select_fields(request.POST, xs) form = MultipleFileUploadForm(user, xs, new_post, request.FILES) if form.is_valid(): form.save() return HttpResponseRedirect(reverse("file_list")) else: form = SingleFileUploadForm(0) return render(request, "app/add_file.html", {"form": form, "user_id": user_id})
def view_thumbnail(request, id): file = get_object_or_404(File, pk=id) _, extension = os.path.splitext(file.file.path) if extension in settings.THUMBNAIL_SUPPORTED: is_supported = "true" else: is_supported = "false" if extension in settings.THUMBNAIL_ARCHIVES: is_archive = "true" else: is_archive = "false" return render( request, "app/view_thumbnail.json", {"file": file, "is_supported": is_supported, "is_archive": is_archive} )
def manage_users(request): if request.method == "POST": form = UserCreationForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse("manage_users")) else: form = UserCreationForm() # Remove help text form.fields["username"].help_text = "" user_list = [] for user in User.objects.all(): user_list.append((user, RawPassword.objects.get(user=user), user.file_set.count(), total_size(user))) return render(request, "app/manage_users.html", {"user_list": user_list, "form": form, "chart_url": get_stats()})
def disconnected(request): return render(request, "app/disconnected.html")
def help(request): return render(request, "app/help.html")