Exemplo n.º 1
0
def Document_edit(request, id_documento):
    if userDocs(request) != True:
        return render(request, template_no_valid)

    doc_for_dept = Document.objects.filter(
        departament=request.session['departament']['active_id'])
    data = {'model': Document.objects.get(id=id_documento)}
    if request.method == "GET":
        form = DocumentForm(instance=data['model'])
    else:
        form = DocumentForm(request.POST, instance=data['model'])
        print(form)
        if form.is_valid():
            form.save()
        else:
            print(form.is_valid())
            print(form.errors)
            form = DocumentForm(request.POST)
        return redirect('document:documento_list')
    date = Current_date()
    if Document.objects.filter(id=data['model'].previous).count() > 0:
        data['previous'] = Document.objects.get(id=data['model'].previous)
    data['doc_for_dept'] = doc_for_dept
    data['remittent'] = Remittent.objects.filter(active=True).order_by('id')
    data['receiver'] = Receiver.objects.filter(active=True).order_by('id')
    data['type'] = Document_type.objects.all().order_by('id')
    data['form'] = form
    data['date'] = date
    data['editdoc'] = True
    data['edit'] = True
    return render(request, 'document/form.html', data)
Exemplo n.º 2
0
 def handle(self, *args, **options):
     for path in args:
         for fname in listdir(path):
             upload_file = open(join(path, fname), "rb")
             post_dict = {"title": fname, "author": "Auto Test"}
             file_dict = {"file": SimpleUploadedFile(upload_file.name, upload_file.read())}
             form = DocumentForm(post_dict, file_dict)
             if form.is_valid():
                 form.save()
                 file = form.cleaned_data["file"]
                 form.instance.set_file(file=file, filename=file.name)
Exemplo n.º 3
0
 def handle(self, *args, **options):
     for path in args:
         for fname in listdir(path):
             upload_file = open(join(path, fname), 'rb')
             post_dict = {'title': fname, 'author': "Auto Test"}
             file_dict = {
                 'file': SimpleUploadedFile(upload_file.name,
                 upload_file.read())}
             form = DocumentForm(post_dict, file_dict)
             if form.is_valid():
                 form.save()
Exemplo n.º 4
0
Arquivo: views.py Projeto: AmiZya/kala
class ProjectView(LoginRequiredMixin, TemplateView):
    template_name = 'project.html'

    def get_context_data(self, **kwargs):
        documents = Document.objects.active().filter(project=self.project)
        if hasattr(self, 'sort_order'):
            if self.sort_order == 'AZ':
                documents = documents.order_by('name')
        if hasattr(self, 'category'):
            mimes = get_mimes_for_category(self.category)
            documents = documents.filter(mime__in=mimes)
        return {
            'categories_form': self.categories_form,
            'company_form': self.company_form,
            'documents': documents,
            'form': self.form,
            'project': self.project,
            'sort_form': self.sort_form,
            }

    def dispatch(self, request, pk, *args, **kwargs):
        self.project = get_object_or_404(Project.objects.active(), pk=pk)
        person = Person.objects.get(pk=self.request.user.pk)
        self.form = DocumentForm(request.POST or None, request.FILES or None, person=person,
                                 project=self.project)
        self.categories_form = CategoryForm(request.GET or None, project=self.project)
        self.company_form = CompanyForm(request.POST or None, project=self.project)
        self.sort_form = SortForm(request.GET or None)
        if 'search' in request.GET:
            self.sort_order = request.GET.get('search')
        if 'category' in request.GET and request.GET.get('category'):
            self.category = request.GET.get('category')
        return super(ProjectView, self).dispatch(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        if 'delete' in request.POST and request.user.is_admin:
            self.project.set_active(False)
            messages.success(request, 'The project has been deleted')
            return redirect(reverse('projects'))

        if 'move' in request.POST and request.user.is_admin and self.company_form.is_valid():
            self.company_form.save()
            return redirect(reverse('project', args=[self.project.pk]))

        if 'upload' in request.POST and self.form.is_valid():
            self.form.save()
            messages.success(request, 'The document has been created')
            return redirect(reverse('project', args=[self.project.pk]))
        return self.render_to_response(self.get_context_data())
Exemplo n.º 5
0
def edit(request, document_id):
    document = get_object_or_404(Document, pk=document_id, status__in=[0, 1])
    if not is_company_staff(request, document.company.pk):
        return redirect('mypage_home')

    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES, instance=document)
        if form.is_valid():
            document = form.save()
            if form.cleaned_data['status'] == 2:
                messages.add_message(request, messages.SUCCESS, '資料を削除しました')
            else:
                messages.add_message(request, messages.SUCCESS, '資料を保存しました')
            return redirect('document_edit_index')
    else:
        form = DocumentForm(instance=document)

    return render_to_response(
        'documents/add_edit.html',
        {
            'document': document,
            'action': 'edit',
            'form': form,
        },
        context_instance=RequestContext(request)
    )
Exemplo n.º 6
0
def add(request):
    if not is_company_staff(request):
        return redirect('mypage_home')
    user = request.user
    company = user.customer_company
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            document = form.save(commit=False)
            document.user = user
            document.company = company
            document.save()
            form.save_m2m()
            messages.add_message(request, messages.SUCCESS, '資料を保存しました')
            return redirect('document_edit', document_id=document.pk)
    else:
        form = DocumentForm()

    return render_to_response(
        'documents/add_edit.html',
        {
            'action': 'add',
            'form': form,
        },
        context_instance=RequestContext(request)
    )
Exemplo n.º 7
0
    def post(self,request,*args,**kwargs):
            form = DocumentForm(request.POST or None, request.FILES or None)
            data = {
                'form': form,
            }
            file_name = request.POST.get("files")

            if str(file_name).endswith('.pdf'):
                type = request.POST.get("type")
                documentsModel.type = type
                documentsModel.type = 1
            else:
                type = request.POST.get("type")
                documentsModel.type = type
                documentsModel.type = 5

            if form.is_valid():
                form.save(commit=True)
                return render(request,self.template_name,data)
            else:
                return render(request,self.template_name,data)
Exemplo n.º 8
0
 def post(self, request, *args, **kwargs):
     """Handles the file upload"""
     form = DocumentForm(request.POST, request.FILES)
     if form.is_valid():
         file = form.save(commit=False)
         file.user = request.user
         file.save()
         messages.success(
             request,
             'El documento "{}" se subió correctamente, ¡muchas gracias!'.
             format(form.files['file']))
         return self.form_valid(form)
     else:
         for error in form.errors['file']:
             messages.error(request, error)
         return redirect('documents:home')
Exemplo n.º 9
0
def edit(request, document_id):
    document = get_object_or_404(Document, pk=document_id, status__in=[0, 1])
    if not is_company_staff(request, document.company.pk):
        return redirect('mypage_home')

    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES, instance=document)
        if form.is_valid():
            document = form.save()
            if form.cleaned_data['status'] == 2:
                messages.add_message(request, messages.SUCCESS, '資料を削除しました')
            else:
                messages.add_message(request, messages.SUCCESS, '資料を保存しました')
            return redirect('document_edit_index')
    else:
        form = DocumentForm(instance=document)

    return render_to_response('documents/add_edit.html', {
        'document': document,
        'action': 'edit',
        'form': form,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 10
0
def add(request):
    if not is_company_staff(request):
        return redirect('mypage_home')
    user = request.user
    company = user.customer_company
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            document = form.save(commit=False)
            document.user = user
            document.company = company
            document.save()
            form.save_m2m()
            messages.add_message(request, messages.SUCCESS, '資料を保存しました')
            return redirect('document_edit', document_id=document.pk)
    else:
        form = DocumentForm()

    return render_to_response('documents/add_edit.html', {
        'action': 'add',
        'form': form,
    },
                              context_instance=RequestContext(request))
Exemplo n.º 11
0
def Document_create(request):
    if userDocs(request) != True:
        return render(request, template_no_valid)

    depto = Departament.objects.get(
        id=request.session['departament']['active_id'])
    doc_for_dept = Document.objects.filter(
        departament=request.session['departament']['active_id'])
    date = Current_date()
    date_str = date['nday'] + ", " + str(
        date['day']) + " de " + date['month'] + " del " + str(date['year'])
    data = {}
    if request.method == 'POST':

        form = DocumentForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.user = request.user
            obj.departament = depto
            valdos = 0
            if doc_for_dept.count() > 0:
                type = doc_for_dept.filter(type=obj.type)
                last_document = type.last()
                data['change'] = last_document.change
                obj.number = int(last_document.number) + 1
                if obj.remittent != last_document.remittent:
                    valdos = valdos + 1
                if obj.receiver != last_document.receiver:
                    valdos = valdos + 1
                if obj.body != last_document.body:
                    valdos = valdos + 1
                if obj.footer != last_document.footer:
                    valdos = valdos + 1
                if obj.matter != last_document.matter:
                    valdos = valdos + 1
                if obj.change != last_document.change:
                    valdos = valdos + 1
                if obj.previous != last_document.previous:
                    valdos = valdos + 1

                if valdos < 2:
                    act = Document.objects.get(id=last_document.id)
                    act.number = last_document.number
                    act.matter = obj.matter
                    act.remittent = obj.remittent
                    act.receiver = obj.receiver
                    act.body = obj.body
                    act.footer = obj.footer
                    act.previous = obj.previous
                    act.save()
                    obj.id = last_document.id
                    if valdos > 0:
                        request.session[
                            'alert'] = 'Se a modificado el documento. ' + str(
                                obj.id)
                else:

                    obj.year = date['year']
                    form.save()

            else:
                obj.number = 1

                #obj.creacion = date_str
                obj.year = date['year']
                obj.type_id = 1
                form.save()

            return redirect('document:documento_detalle', obj.id)
        else:
            print(form.is_valid())
            print(form.errors)
            form = DocumentForm(request.POST)

    else:
        form = DocumentForm()
    data['doc_for_dept'] = doc_for_dept
    data['edit'] = True  #Para activar texto enriquesido
    data['remittent'] = Remittent.objects.filter(active=True).order_by('id')
    data['receiver'] = Receiver.objects.filter(active=True).order_by('id')
    data['type'] = Document_type.objects.all().order_by('id')
    data['form'] = form
    data['date'] = date
    data['model'] = doc_for_dept.last()
    print(data['model'].change)
    return render(request, 'document/form.html', data)