This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import BytesIO | |
from django.http import HttpResponse | |
from django.template.loader import get_template | |
import xhtml2pdf.pisa as pisa | |
class Render: | |
@staticmethod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic import View | |
from django.utils import timezone | |
from .models import * | |
from .render import Render | |
class Pdf(View): | |
def get(self, request): | |
sales = Sales.objects.all() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Sales Report</title> | |
<style type="text/css"> | |
@page { | |
size: A4; | |
margin: 1cm; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import BytesIO | |
from django.http import HttpResponse | |
from django.template.loader import get_template | |
import xhtml2pdf.pisa as pisa | |
import os | |
from random import randint | |
class Render: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic import View | |
from django.utils import timezone | |
from .models import * | |
from .render import * | |
import requests | |
from threading import Thread, activeCount | |
def send_email(file: list): | |
r = requests.post( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic.base import View | |
from django.http import HttpResponse | |
from .render import Render | |
class RenderPDF(Render): | |
params: dict = None | |
template: str = None | |
email: bool = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReportRequest(models.Model): | |
host = models.CharField(max_length=1000) | |
path = models.CharField(max_length=1000) | |
method = models.CharField(max_length=50) | |
uri = models.CharField(max_length=2000) | |
status_code = models.IntegerField() | |
remote_addr = models.IPAddressField() | |
remote_addr_fwd = models.IPAddressField(blank=True, null=True) | |
request_meta = models.TextField() | |
query = models.TextField() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import request as Request | |
from django.db.models.query import QuerySet | |
from django.forms.models import model_to_dict | |
from random import randint | |
import os | |
import csv | |
class Generate: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Csv(View): | |
def get(self, request): | |
sales = Sales.objects.all() | |
headers = [(h.column) for h in Sales._meta.get_fields()] | |
csv_array = Generate(request).csv_file(headers=headers, data=sales) | |
return HttpResponse(f'{csv_array[0]}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Csv(View): | |
def get(self, request): | |
sales = Sales.objects.all() | |
headers = [(h.column) for h in Sales._meta.get_fields()] | |
csv_array = Generate(request).csv_file(headers=headers, data=sales) | |
if os.path.exists(csv_array[1]): | |
with open(csv_array[1], 'r') as csv: | |
response = HttpResponse(csv.read(), content_type="text/csv") | |
response["Content-Disposition"] = f'attachment; filename={csv_array[0]}' |