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
# -*- coding: utf-8 -*- | |
import scrapy | |
class OlxSpider(scrapy.Spider): | |
name = "olx" | |
allowed_domains = ["pe.olx.com.br"] | |
start_urls = ( | |
'http://pe.olx.com.br/imoveis/aluguel', | |
) |
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
# -*- coding: utf-8 -*- | |
import scrapy | |
class OlxSpider(scrapy.Spider): | |
name = "olx" | |
allowed_domains = ["pe.olx.com.br"] | |
start_urls = ( | |
'http://pe.olx.com.br/imoveis/aluguel', | |
) |
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
# -*- coding: utf-8 -*- | |
import scrapy | |
class OlxSpider(scrapy.Spider): | |
name = "olx" | |
allowed_domains = ["pe.olx.com.br"] | |
start_urls = ( | |
'http://pe.olx.com.br/imoveis/aluguel', | |
) |
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 django.conf import settings | |
from django.http import Http404 | |
class MeuMiddleware(object): | |
def process_request(self, request): | |
if request.META["REMOTE_ADDR"] in settings.IPS_PERMITIDOS: | |
pass | |
else: | |
raise Http404 |
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
# -*- coding: utf-8 -*- | |
import rethinkdb as r | |
class RethinkdbPipeline(object): | |
conn = None | |
rethinkdb_settings = {} |
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
MyObject.objects.filter(Q(start_date__gt=ed | Q(ends_date__lt=sd)) |
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 MeuForm(forms.Form): | |
request = None | |
def __init__(self, request, *args, **kwargs): | |
super(MeuForm, self).__init__(*args, **kwargs) | |
# é importante que na view você não esquece de passar a request para o form se não vai dar erro | |
self.request = request | |
def clean(self): |
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 django.template.defaultfilters import filesizeformat | |
def clean_file(self): | |
if self.cleaned_data['file']: | |
size = self.cleaned_data['file'].size | |
max_size = settings.MAX_GROUP_FILE_SIZE | |
if size > max_size: | |
raise forms.ValidationError(_(u'O tamanho máximo do arquivo deve ser de %s') % filesizeformat(max_size)) | |
return self.cleaned_data['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
from django import forms | |
from minhaapp.models import MeuModel | |
class MeuForm(forms.ModelForm): | |
def __init__(self, *args, **kwargs): | |
super(MeuForm, self).__init__(*args, **kwargs) | |
if self.instance: | |
for key, value in self.instance.context(): |
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
# -*- coding: utf-8 -*- | |
import os | |
from django.db import models | |
from django.utils.translation import ugettext_lazy as _ | |
from django.contrib.auth.models import User | |
from django.core.files.storage import FileSystemStorage | |
from django.conf import settings |