This file contains 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
def create_promotional_image(): | |
with open("promo.png", "wb+") as output_file: | |
create_png_from_svg_template( | |
"coupon/test.svg", | |
{"_WIDTH": 400, "_HEIGHT": 200, "_PROMO_CODE": "ABCD1234"}, | |
output_file, | |
) |
This file contains 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
import cairosvg | |
@mock.patch("cairosvg.svg2png", wraps=cairosvg.svg2png) | |
def test_create_png_from_svg_template(self, spy_svg2png): | |
with BytesIO() as output_file: | |
image.create_png_from_svg_template( | |
"utils/tests/svg_template.svg", | |
{"_WIDTH": 159, "_HEIGHT": 161, "_TEXT": "Hello World!"}, | |
output_file, | |
) |
This file contains 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
import io | |
from .models import Coupon | |
from .utils import create_png_from_svg_template | |
def create_promotional_image(coupon_id): | |
coupon = Coupon.objects.get(id=coupon_id) | |
with io.BytesIO() as output_file: | |
create_png_from_svg_template( | |
"coupon/templates/promotional-template.svg", |
This file contains 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
import cairosvg | |
def create_png_from_svg_template(svg_path, replace_keys_dict, output_file): | |
""" | |
Create a png from a svg template, replacing keys in the svg with custom values. | |
Args: | |
svg_path (str): Path to the svg file | |
replace_keys_dict (dict): Keys to search/replace in the svg, e. g. {"code": 1} | |
output_file (file-like obj or str): file-like object or path |
This file contains 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
import lorem | |
from locust import HttpUser, task, between | |
class WebsiteUser(HttpUser): | |
wait_time = between(1, 3) | |
@task(5) | |
def index(self): | |
self.client.get("/tasks/") |
This file contains 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
# Escolha sua branch de origem, de onde os commits serão revertidos | |
git checkout main | |
# Usando o git log, encontre o hash do commit do ponto que você deseja retornar para. | |
git checkout f21306c | |
# Agora vamos fazer uma comparação entre a posição atual do histórico e a main. | |
# Nesse ponto precisamos confirmar se as mudanças exibidas aqui estão corretas ;) | |
# Se não estiverem, você provavelmente está no ponto errado do histórico (veja o git log) | |
git diff main |
This file contains 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
# Escolha sua branch de origem, de onde os commits serão revertidos | |
git checkout main | |
# Use o commando git revert com a opção "-n" pra gerar um único commit | |
# Os ids abaixo podem ser encontrados usando o `git log` | |
git revert -n f21306c..e330c04 # OLD_COMMIT..RECENT_COMMIT | |
# Nesse ponto, você já pode usar os comandos de status e diff pra conferir se a alteração está correta: | |
git status # mostra os nomes dos arquivos alterados | |
git diff # mostra as mudanças efetivas |
This file contains 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 EmbeddedReportResource(PaginatorMixin, APIResource): | |
preparer = EMBEDDED_REPORT_LIST_PREPARER | |
paginate = True | |
page_size = 40 | |
@property | |
def base_query(self): | |
return ( | |
EmbeddedReport.objects.filter(active=True) | |
.select_related("engine") |
This file contains 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 EmbeddedReport(BaseModel, models.Model): | |
... | |
... | |
... | |
def get_report_url_for_business(self, business) | |
map_resource = { | |
"dashboard": { | |
"params": {"dashboard": int(self.reference_id)}, | |
"url_path": "dashboard", | |
}, |
This file contains 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 ReportEngine(BaseModel, models.Model): | |
id = HashedAutoField(primary_key=True) | |
name = models.CharField(max_length=250) | |
type = models.CharField( | |
choices=(("metabase", "Metabase"),), default="metabase", max_length=50 | |
) | |
base_url = models.URLField() | |
integration_api_key = models.CharField(max_length=250) | |
class EmbeddedReport(BaseModel, models.Model): |
NewerOlder