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
replacer = lambda s: s.replace('Ã', 'Ã').replace('Õ', 'Õ').replace('Á','Á').replace('É', 'É').replace('Í','Í').replace('Ó', 'Ó').replace('Ú', 'Ú').replace('Ç', 'Ç').replace('Â','Â').replace('Ê','Ê').replace('Ô','Ô') |
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
from selenium import webdriver | |
firefox = webdriver.Firefox() | |
firefox.get('http://{sitedafaculdade}.com.br') # acessar o site | |
# encontrar os elementos | |
login = firefox.find_element_by_id('login') # firefox.find_element_by_css_selector('input[name=login]') | |
senha = firefox.find_element_by_id('senha') # firefox.find_element_by_css_selector('input[name=senha]') | |
botao = firefox.find_element_by_css_selector('input[type=submit]') |
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 Product(models.Model): | |
title = models.CharField(max_length=120) | |
is_adult = models.BooleanField(default=False) | |
is_active = models.Bool eanField(default=True) | |
adult_products = Product.objects.filter(is_adult=True) | |
active_products = Product.objects.filter(is_active=True) |
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
print(adult_products.query) | |
""" | |
SELECT `product_product`.`title`, `product_product`.`is_adult`, `product_product`.`is_active` | |
FROM `product_product` WHERE `product_product`.`is_adult` = True | |
""" | |
print(active_products.query) | |
""" | |
SELECT `product_product`.`title`, `product_product`.`is_adult`, `product_product`.`is_active` | |
FROM `product_product` WHERE `product_product`.`is_active` = True |
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
# Intersection queryset method | |
active_adult_products = active_products.intersection(adult_products) | |
# Bitwise operation using & to get the AND behavior | |
active_adult_products = active_products & adult_products |
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
# Union queryset method | |
all_products = active_products.union(adult_products) | |
# Bitwise operation OR | |
all_products = active_products | adult_products |
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
# product/models.py | |
from django.db import models | |
class Category(models.Model): | |
name = models.CharField(max_length=120) | |
is_active = models.BooleanField(default=True) | |
subcategories = models.ManyToManyField('self', symmetrical=False) |
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
from .models import Product | |
def products_list(): | |
product_qs = Product.objects.all() | |
products = [] | |
for product in product_qs: | |
products.append({ |
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
# $ python app/manage.py shell | |
from products.queries import products_list | |
products = products_list() | |
# check the all products were returned | |
assert len(products) == 500 | |
assert list(products[0].keys()) == ['id', 'title', 'category'] |
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
from products.queries import debugger_products_list | |
_ = debugger_products_list() |
OlderNewer