Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
2.2 kB
3
Indexable
Never
@method_decorator(can_access_project_decorator, name="dispatch")
class ProjectFilesView(LoginRequiredMixin, ListView):
    template_name = "projects/project_files.html"

    def get(self, request, slug):
        project_files = projects.models.TranslationFile.objects.filter(
            project_language__project__slug=slug,
        )
        return render(
            request,
            self.template_name,
            context={
                "project_files": project_files,
                "slug": slug,
            },
        )

@method_decorator(can_access_project_decorator, name="dispatch")
class ProjectFilesUploadView(LoginRequiredMixin, ListView):
    template_name = "projects/project_files_upload.html"

    def get(self, request, slug):
        project_files = projects.models.TranslationFile.objects.filter(
            project_language__project__slug=slug,
        )
        project_languages = projects.models.ProjectLanguage.objects.filter(project__slug=slug)
        return render(
            request,
            self.template_name,
            context={
                "project_files": project_files,
                "project_languages": project_languages,
            },
        )

    def post(self, request, slug):
        if request.FILES:
            file = request.FILES["filename"]
            lang_object = projects.models.ProjectLanguage.objects.filter(lang_code=request.POST["lang"], project__slug=slug).first()
            projects.models.TranslationFile.objects.create(file=file, project_language_id=lang_object.id)
        return redirect("projects:project_files", slug)


@method_decorator(can_access_project_decorator, name="dispatch")
class ProjectFilesTranslateView(LoginRequiredMixin, ListView):
    template_name = "projects/project_file_translate.html"

    def get(self, request, slug, pk):
        project_files = projects.models.TranslationFile.objects.filter(
            project_language__project__slug=slug,
        )
        return render(
            request,
            self.template_name,
            context={
                "project_files": project_files,
            },
        )
Leave a Comment