Esempio n. 1
0
def report(request, pk):
    insert_history(
        HISTORY_STRING.format(request.user.name, request.method,
                              request.build_absolute_uri()))
    draft = Draft.objects.get(pk=pk)
    contract = Contract.objects.get(pk=draft.contractId_id)
    user = MyUser.objects.get(pk=contract.userId_id)
    items = get_needed_items(pk=pk)
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", size=25)
    pdf.cell(200, 10, txt=user.name, ln=1, align="C")
    pdf.set_font("Arial", size=20)
    pdf.cell(200, 10, txt="Report " + contract.title, ln=1, align="C")
    pdf.set_font("Arial", size=12)
    for i in draft.text.split("\n"):
        pdf.cell(200, 10, txt=i, ln=1, align="L")
    for item in items:
        if item.satisfied:
            pdf.cell(200, 10, txt=item.type + " Satisfied", ln=1, align="L")
        else:
            pdf.cell(200,
                     10,
                     txt=item.type + " not satisfied",
                     ln=1,
                     align="L")

    pdf.output("some.pdf")
    response = FileResponse(open('some.pdf', 'rb'))
    return response
Esempio n. 2
0
    def get_context_data(self, **kwargs):
        insert_history(
            HISTORY_STRING.format(self.request.user.name, self.request.method,
                                  self.request.build_absolute_uri()))
        context = super(DetailSupplier, self).get_context_data(**kwargs)
        context['suppliers'] = Supplier.objects.all()
        if 'pk' in kwargs:
            supplier = Supplier.objects.get(pk=kwargs['pk'])
            sql = "SELECT * FROM dashboard_item WHERE id in (select item_id FROM dashboard_itemsupplier WHERE supplier_id=%s)"
            context['supplier'] = supplier
            context['supplier_items'] = Supplier.objects.raw(
                sql, [supplier.id])
        print("sss")
        if 'showall' in kwargs and self.request.method == 'POST':
            show_all = kwargs['showall']
            try:
                if show_all == 0:
                    context['showall'] = 1
                else:
                    context['showall'] = 0
            except Exception as e:
                print(e)

        print(kwargs)
        return context
Esempio n. 3
0
 def dispatch(self, request, *args, **kwargs):
     insert_history(
         HISTORY_STRING.format(request.user.name, request.method,
                               request.build_absolute_uri()))
     if request.method == 'POST':
         return self.post()
     return super(DetailContract, self).dispatch(request, *args, **kwargs)
Esempio n. 4
0
def satisfy_all_possible(request, pk):
    try:
        insert_history(
            HISTORY_STRING.format(request.user.name, request.method,
                                  request.build_absolute_uri()))
        satisfy_all_possible_items(pk)
        return redirect(DRAFTS_DETAIL_REDIRECT.format(pk))
    except Exception as e:
        print(e)
    return HttpResponse(status=400)
Esempio n. 5
0
def satisfy(request, pk, ipk):
    try:
        insert_history(
            HISTORY_STRING.format(request.user.name, request.method,
                                  request.build_absolute_uri()))
        d = satisfy_item(pk, ipk)
        if not d:
            print("errr")
        response = redirect(DRAFTS_DETAIL_REDIRECT.format(pk))
        return response
    except Exception as e:
        print(e)
    return HttpResponse(status=400)
Esempio n. 6
0
def update_for(request, pk):
    insert_history(
        HISTORY_STRING.format(request.user.name, request.method,
                              request.build_absolute_uri()))
    print("ssfsf")
    if request.method == 'POST':
        form = TextForm(request.POST)
        print("form")
        if form.is_valid():
            text = form.cleaned_data['text']
            print(text)
            update_text(pk, text)
            print("success")
    return redirect(DRAFTS_DETAIL_REDIRECT.format(pk))
Esempio n. 7
0
def finish(request, pk):
    try:
        insert_history(
            HISTORY_STRING.format(request.user.name, request.method,
                                  request.build_absolute_uri()))
        print(pk)
        print('chees')
        d = finish_draft(pk)
        if not d:
            print("err")
        response = redirect(DRAFTS_DETAIL_REDIRECT.format(pk))
        return response
    except Exception as e:
        print(e)
    return HttpResponse(status=400)
Esempio n. 8
0
def get_show_all_form_data(post_data, context, **kwargs):
    try:
        insert_history(
            HISTORY_STRING.format(request.user.name, request.method,
                                  request.build_absolute_uri()))
        form = ShowAllForm(post_data)
        if form.is_valid():
            show_all = form.cleaned_data['showall']
            if show_all == 0:
                context['showall'] = 1
            else:
                context['showall'] = 0
            print(show_all)
        else:
            context['showall'] = 0
    except Exception as e:
        print(e)
    return context
Esempio n. 9
0
def delete_draft(request, pk):
    try:
        insert_history(
            HISTORY_STRING.format(request.user.name, request.method,
                                  request.build_absolute_uri()))
        draft = Draft.objects.get(pk=pk)
        contract = Contract.objects.get(pk=draft.contractId.id)
        if request.user.id == contract.userId.id and request.method == 'POST':
            draft.delete()
            Contract.objects.filter(pk=contract.id).update(taken=False,
                                                           userId=None)
            redirect_path = "/dashboard/drafts"
            response = redirect(redirect_path)
            return response
    except Exception as e:
        print(e)
        pass
    return HttpResponse(status=400)
Esempio n. 10
0
def create_draft(request, pk):
    #try:
    insert_history(
        HISTORY_STRING.format(request.user.name, request.method,
                              request.build_absolute_uri()))
    contract = Contract.objects.get(pk=pk)
    if contract.userId is None and request.method == 'POST':
        title = "Draft of : \"" + contract.title + "\""
        draft = Draft.objects.create(title=title,
                                     text=contract.content,
                                     contractId=contract)
        Contract.objects.filter(pk=contract.id).update(userId=request.user,
                                                       taken=True)
        print("saf")
        add_needed_items_to_draft(contract.needed, draft)  # adds DraftItem
        response = redirect(DRAFTS_DETAIL_REDIRECT.format(draft.id))
        return response
    #except Exception as e:
    #    print(e)
    return HttpResponse(status=400)