8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-24 16:03:47 +00:00
re2o/printer/views.py

56 lines
1.3 KiB
Python
Raw Normal View History

2018-06-28 18:20:08 +00:00
# -*- mode: python; coding: utf-8 -*-
"""printer.views
The views for the printer app
Author : Maxime Bombar <bombar@crans.org>.
Date : 29/06/2018
"""
from __future__ import unicode_literals
from django.urls import reverse
from django.shortcuts import render, redirect
from django.forms import modelformset_factory, formset_factory
2018-06-29 04:06:52 +00:00
from django.contrib.auth.decorators import login_required
2018-06-28 18:20:08 +00:00
from re2o.views import form
from users.models import User
from . import settings
from .forms import (
2018-06-29 03:05:15 +00:00
JobWithOptionsForm,
2018-06-28 18:20:08 +00:00
)
2018-06-29 04:06:52 +00:00
@login_required
2018-06-28 18:20:08 +00:00
def new_job(request):
"""
View to create a new printing job
"""
2018-06-29 03:05:15 +00:00
job_formset = formset_factory(JobWithOptionsForm)(
request.POST or None, request.FILES or None,
2018-06-28 18:20:08 +00:00
)
if job_formset.is_valid():
for job in job_formset:
job = job.save(commit=False)
job.user=request.user
job.status='Printable'
job.save()
return redirect(reverse(
'printer:success',
))
return form(
{
'jobform': job_formset,
'action_name': "Print",
},
'printer/newjob.html',
request
)
def success(request):
return form(
{},
'printer/success.html',
request
)