Skip to content

Instantly share code, notes, and snippets.

Moacir Moda moacirmoda

View GitHub Profile
View rides.py
from rider.models import *
rides_with_ck_ids = CheckRide.objects.all().values_list('ride_id', flat=True)
rides_ids = Ride.objects.all().values_list('id', flat=True)
rides_without_ck_ids = []
for id in rides_ids:
if id not in rides_with_ck_ids:
rides_without_ck_ids.append(id)
View mixin_sample.py
class Foo:
def bar(self):
print(1)
class Mixin:
def bar(self):
print(2)
class New(Foo, Mixin):
pass
View duplicados.py
# demandas duplicadas
from api.models import *
from datetime import timedelta
ids_duplicated = []
for diligencia in Diligencia.objects.all().order_by('-id'):
if diligencia.id in ids_duplicated:
continue
user = diligencia.user
View gist:cf89f8e58b1f987020796005f35cf7d3
1 sudo apt update
2 sudo apt install apt-transport-https ca-certificates curl software-properties-common
3 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
5 sudo apt update
6 apt-cache policy docker-ce
7 sudo apt install docker-ce
8 sudo systemctl status docker
9 sudo apt-get install git -y
10 git clone git@github.com:codevance/consulta_cnpj.git git
View request.xml
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<ns0:User xmlns:ns0="http://www.b2breservas.com.br/b2bws/types/">xxx</ns0:User>
<ns1:Password xmlns:ns1="http://www.b2breservas.com.br/b2bws/types/">xxx</ns1:Password>
</soap-env:Header>
<soap-env:Body>
<ns0:OTA_PingRQ EchoToken="1234" Version="3.000" xmlns:ns0="http://www.opentravel.org/OTA/2003/05/alpha">
<ns0:EchoData>1</ns0:EchoData>
</ns0:OTA_PingRQ>
</soap-env:Body>
View sample.py
from django import models
from django.test import TestCase
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30, null=True)
age = models.PositiveIntegerField()
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
View sample.py
from django.test import TestCase
from myapp.models import Person
class PersonTestCase(TestCase):
def test_should_return_attributes(self):
self.assertTrue(hasattr(Person, 'first_name'))
self.assertTrue(hasattr(Person, 'last_name'))
self.assertTrue(hasattr(Person, 'age'))
def test_should_create_item(self):
View sample.py
from django.test import TestCase
from myapp.models import Person
class PersonTestCase(TestCase):
def test_should_return_attributes(self):
self.assertTrue(hasattr(Person, 'first_name'))
self.assertTrue(hasattr(Person, 'last_name'))
self.assertTrue(hasattr(Person, 'age'))
View sample.py
try:
Person.objects.get(id=1)
except Person.DoesNotExists:
print('não existe')
View sample.py
try:
Person.objects.get(id=1)
except ObjectDoesNotExists:
print('não existe')
You can’t perform that action at this time.