mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
Lots of pylint and pep8 fixes in nearly every file.
This commit is contained in:
@@ -4,7 +4,7 @@ from tastypie import fields
|
||||
from pinry.pins.models import Pin
|
||||
|
||||
|
||||
class PinResource(ModelResource):
|
||||
class PinResource(ModelResource): # pylint: disable-msg=R0904
|
||||
thumbnail = fields.CharField(readonly=True)
|
||||
|
||||
class Meta:
|
||||
@@ -13,4 +13,5 @@ class PinResource(ModelResource):
|
||||
include_resource_uri = False
|
||||
|
||||
def dehydrate_thumbnail(self, bundle):
|
||||
return Pin.objects.only('image').get(pk=bundle.data['id']).image.url_200x1000
|
||||
pin = Pin.objects.only('image').get(pk=bundle.data['id'])
|
||||
return pin.image.url_200x1000
|
||||
|
||||
@@ -7,5 +7,5 @@ register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
def bootstrap_field(field):
|
||||
template = loader.get_template('core/templatetags/bootstrap_field.html')
|
||||
return template.render(Context({'field': field}))
|
||||
t = loader.get_template('core/templatetags/bootstrap_field.html')
|
||||
return t.render(Context({'field': field}))
|
||||
|
||||
@@ -3,6 +3,9 @@ from django.test.client import Client
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
# pylint: disable-msg=E1103
|
||||
|
||||
|
||||
class HomeTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.template.response import TemplateResponse
|
||||
from django.http import HttpResponseRedirect, Http404, HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth import logout
|
||||
@@ -10,12 +10,14 @@ from django.contrib import messages
|
||||
def home(request):
|
||||
return HttpResponseRedirect(reverse('pins:recent-pins'))
|
||||
|
||||
|
||||
def register(request):
|
||||
if request.method == 'POST':
|
||||
form = UserCreationForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, 'Thank you for registering, you can now login.')
|
||||
messages.success(request, 'Thank you for registering, you can now '
|
||||
'login.')
|
||||
return HttpResponseRedirect(reverse('core:login'))
|
||||
else:
|
||||
form = UserCreationForm()
|
||||
|
||||
@@ -13,7 +13,8 @@ class PinForm(forms.ModelForm):
|
||||
image_file_types = ['png', 'gif', 'jpeg', 'jpg']
|
||||
file_type = data.split('.')[-1]
|
||||
if file_type.lower() not in image_file_types:
|
||||
raise forms.ValidationError("Requested URL is not an image file. Only images are currently supported.")
|
||||
raise forms.ValidationError("Requested URL is not an image file. "
|
||||
"Only images are currently supported.")
|
||||
|
||||
# Check if pin already exists
|
||||
try:
|
||||
@@ -26,7 +27,9 @@ class PinForm(forms.ModelForm):
|
||||
elif protocol == 'https':
|
||||
opp_data = data.replace('https://', 'http://')
|
||||
else:
|
||||
raise forms.ValidationError("Currently only support HTTP and HTTPS protocols, please be sure you include this in the URL.")
|
||||
raise forms.ValidationError("Currently only support HTTP and "
|
||||
"HTTPS protocols, please be sure "
|
||||
"you include this in the URL.")
|
||||
|
||||
try:
|
||||
Pin.objects.get(url=opp_data)
|
||||
|
||||
@@ -16,11 +16,12 @@ class Pin(models.Model):
|
||||
def __unicode__(self):
|
||||
return self.url
|
||||
|
||||
def save(self):
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.image:
|
||||
temp_img = NamedTemporaryFile()
|
||||
temp_img.write(urllib2.urlopen(self.url).read())
|
||||
temp_img.flush()
|
||||
# pylint: disable-msg=E1101
|
||||
self.image.save(self.url.split('/')[-1], File(temp_img))
|
||||
super(Pin, self).save()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
|
||||
urlpatterns = patterns('pinry.pins.views',
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib import messages
|
||||
|
||||
from .models import Pin
|
||||
from .forms import PinForm
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user