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
| ARG PYTHON_VERSION='3.8' | |
| # set base image (host OS) | |
| FROM python:3.8 | |
| ENV PYTHONUNBUFFERED 1 | |
| # set the working directory in the container | |
| WORKDIR /code |
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
| """ | |
| Respondendo a questões feitas no grupo da live de Python. | |
| """ | |
| class Teste: | |
| bananas_cls = 5 # Variável de classe | |
| def __init__(self): | |
| """Método que inicia a instância.""" | |
| self.bananas_self = 10 # Variável de instância |
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
| # https://github.com/aykut/django-bulk-update | |
| from django_bulk_update.helper import bulk_update | |
| from minhaapp.models import MeuModelo | |
| queryset_meumodelo = MeuModelo.objects.all() | |
| # limpa os dados | |
| for meumodelo_obj in queryset_meumodelo: |
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
| // Bootstrap datepicker | |
| $('.input-daterange input').each(function() { | |
| $(this).datepicker('clearDates'); | |
| }); | |
| // Set up your table | |
| table = $('#my-table').DataTable({ | |
| paging: false, | |
| info: 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 MyModelAdd(CreateView): | |
| model = MyModel | |
| def get_form(self): | |
| type_form = self.request.GET.get('type') | |
| if type_form == 'pf': | |
| self.form_class = PFForm | |
| else: | |
| self.form_class = PJForm | |
| return super(MyModelAdd, self).get_form() |
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 ast import literal_eval | |
| def convert_to_type(input_data): | |
| try: | |
| return literal_eval(input_data) | |
| except (ValueError, SyntaxError): | |
| return input_data |
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
| def add_q_object(self, keyword, q_object, query_parm): | |
| for key in keyword: | |
| kwargs = {query_parm: key.strip()} | |
| q_object.add(Q(**kwargs), q_object.OR) | |
| def filter_applicants(self, _queryset=None): | |
| my_applicants = _queryset |
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
| """ | |
| Django ORM Optimization Tips | |
| Caveats: | |
| * Only use optimizations that obfuscate the code if you need to. | |
| * Not all of these tips are hard and fast rules. | |
| * Use your judgement to determine what improvements are appropriate for your code. | |
| """ | |
| # --------------------------------------------------------------------------- |
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
| """ | |
| This should be a separate file, i usually install it on the maind django project folder. | |
| """ | |
| from threading import local | |
| from django.utils.deprecation import MiddlewareMixin | |
| _user = local() |
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 flask import Flask | |
| from flask_restful import Api, Resource, reqparse | |
| app = Flask(__name__) | |
| api = Api(app) | |
| transactions = [ | |
| { |