def post(self, request): form = UploadFileForm(request.POST, request.FILES) if not form.is_valid(): return HttpResponseBadRequest("You should attach a file") font_file = request.FILES['uploaded_file'] if not font_file: return HttpResponseBadRequest("You should attach a file") import base64 text_font_base64 = base64.b64encode(font_file.read()) user = User.objects.get(username=request.user.username) self.__remove_user_related_pdfs(user) user.text_font_base64 = text_font_base64 user.text_font_name = font_file.name user.save() return HttpResponseRedirect(request.META['HTTP_REFERER'])
def get(self, request): user = User.objects.get(username=request.user) form = UploadFileForm() return render(request, 'settings.html', { 'form': form, 'text_font_name': user.text_font_name })
def get(self, request, username): user = User.objects.get(username=username) # tasks = Task.objects.filter(contest__public=True).values_list('id', 'title') translations = [] for task in Task.objects.filter(contest__public=True): translation = Translation.objects.filter(user=user, task=task).first() is_editing = translation and is_translate_in_editing(translation) if translation: translations.append((task.id, task.name, True, translation.id, translation.frozen, is_editing)) else: translations.append((task.id, task.name, False, 'None', False, False)) tasks_by_contest = {contest: [] for contest in Contest.objects.all()} for task in Task.objects.filter(contest__public=True, contest__frozen=False).order_by('order'): translation = Translation.objects.filter(user=user, task=task).first() is_editing = translation and is_translate_in_editing(translation) frozen = translation and translation.frozen translation_id = translation.id if translation else None final_pdf_url = translation.final_pdf.url if translation and translation.final_pdf else None tasks_by_contest[task.contest].append( {'id': task.id, 'name': task.name, 'trans_id': translation_id, 'is_editing': is_editing, 'frozen': frozen, 'final_pdf_url': final_pdf_url}) tasks_lists = [{'title': c.title, 'slug': c.slug, 'id': c.id, 'user_contest': UserContest.objects.filter(contest=c, user=user).first(), 'tasks': tasks_by_contest[c]} for c in Contest.objects.order_by('-order') if len(tasks_by_contest[c]) > 0] can_upload_final_pdf = request.user.has_perm('trans.change_translation') form = UploadFileForm() return render(request, 'user.html', context={'user_name': username, 'country': user.country.name, 'is_editor': user.is_editor, 'tasks_lists': tasks_lists, 'language': user.credentials(), 'can_upload_final_pdf': can_upload_final_pdf, 'form': form})
def post(self, request): id = request.POST['trans_id'] trans = Translation.objects.filter(id=id).first() form = UploadFileForm(request.POST, request.FILES) if not form.is_valid(): return HttpResponseBadRequest("You should attach a file") pdf_file = request.FILES.get('uploaded_file', None) if not pdf_file or pdf_file.name.split('.')[-1] != 'pdf': return HttpResponseBadRequest("You should attach a pdf file") trans.frozen = True trans.final_pdf = pdf_file trans.save() trans.notify_final_pdf_change() return redirect(request.META.get('HTTP_REFERER'))
def post(self, request): id = request.POST['trans_id'] trans = Translation.objects.filter(id=id).first() form = UploadFileForm(request.POST, request.FILES) if not form.is_valid(): return HttpResponseBadRequest("You should attach a file") pdf_file = request.FILES.get('uploaded_file', None) if not pdf_file or pdf_file.name.split('.')[-1] != 'pdf': return HttpResponseBadRequest("You should attach a pdf file") pdf_file_path = final_pdf_path(trans.task.contest.slug, trans.task.name, trans.user) with open(pdf_file_path, 'wb') as f: for chunk in pdf_file.chunks(): f.write(chunk) trans.frozen = True trans.save() return redirect(request.META.get('HTTP_REFERER'))
def post(self, request): form = UploadFileForm(request.POST, request.FILES) if not form.is_valid(): return HttpResponseBadRequest("You should attach a file") font_file = request.FILES['uploaded_file'] if not font_file: return HttpResponseBadRequest("You should attach a file") import base64 text_font_base64 = base64.b64encode(font_file.read()) user = User.objects.get(username=request.user.username) for trans in Translation.objects.filter(user=user): if os.path.exists( unreleased_pdf_path(trans.task.contest.slug, trans.task.name, user)): os.remove( unreleased_pdf_path(trans.task.contest.slug, trans.task.name, user)) user.text_font_base64 = text_font_base64 user.text_font_name = font_file.name user.save() return HttpResponseRedirect(request.META['HTTP_REFERER'])
def post(self, request): user = User.objects.get(username=request.user) form = UploadFileForm(request.POST, request.FILES) if not form.is_valid(): return HttpResponseBadRequest("You should attach a file") pdf_file = request.FILES.get('uploaded_file', None) if not pdf_file or pdf_file.name.split('.')[-1] != 'pdf': return HttpResponseBadRequest("You should attach a pdf file") pdf_file_path = '/tmp/{}_{}'.format(user.country.code, pdf_file.name) with open(pdf_file_path, 'wb') as f: for chunk in pdf_file.chunks(): f.write(chunk) send_pdf_to_printer_with_header_page(pdf_file_path, user.country.code, user.country.name) response = redirect('printcustomfile') response['Location'] += urllib.parse.quote('?pdf_file=%s' % pdf_file.name, safe='=?&') return response
def get(self, request): form = UploadFileForm() return render(request, 'custom-print.html', {'form': form})