Permalink
Browse files

fixed pylint/pep8 warnings

  • Loading branch information...
1 parent f09ad8b commit dfd3c9c2716c27b6772b3dd8f8f2f78c831210e1 @trey0 trey0 committed Sep 19, 2011
@@ -5,15 +5,16 @@
# __END_LICENSE__
import re
-import sys
from django.db.models import Q
from geocamUtil import TimeUtil
+
class BadQuery(Exception):
pass
+
class SearchAbstract:
# override these settings in derived classes
getAllFeatures = None
@@ -35,7 +36,7 @@ def filterFieldBefore(self, query, clause, field, term, negated):
except ValueError, msg:
raise BadQuery("Oops, %s in clause '%s' of search '%s'"
% (msg, clause, query))
- return Q(**{self.timeField+'__lte': utcDT})
+ return Q(**{self.timeField + '__lte': utcDT})
def filterFieldAfter(self, query, clause, field, term, negated):
if negated:
@@ -47,7 +48,7 @@ def filterFieldAfter(self, query, clause, field, term, negated):
except ValueError, msg:
raise BadQuery("Oops, %s in clause '%s' of search '%s'"
% (msg, clause, query))
- return Q(**{self.timeField+'__gte': utcDT})
+ return Q(**{self.timeField + '__gte': utcDT})
def filterFieldDefault(self, query, clause, field, term, negated):
if field == None:
@@ -66,7 +67,7 @@ def filterFieldDefault(self, query, clause, field, term, negated):
qfilter = Q()
for f in fields:
dbField = self.flookup[f]
- qAdd = Q(**{dbField+'__icontains': term})
+ qAdd = Q(**{dbField + '__icontains': term})
if negated:
qfilter = qfilter & ~qAdd
else:
@@ -75,12 +76,12 @@ def filterFieldDefault(self, query, clause, field, term, negated):
def filterField(self, query, clause, field, term, negated):
if field:
- filterFuncName = 'filterField'+field.capitalize()
+ filterFuncName = 'filterField' + field.capitalize()
if hasattr(self, filterFuncName):
filterFunc = getattr(self, filterFuncName)
return filterFunc(query, clause, field, term, negated)
return self.filterFieldDefault(query, clause, field, term, negated)
-
+
def filterClause(self, query, clause):
if clause.startswith('-'):
negated = True
@@ -132,7 +133,7 @@ def treeToFilter(self, query, queryTree):
termFilter = termFilter & clauseFilter
queryFilter = queryFilter | termFilter
return queryFilter
-
+
def searchFeatures0(self, startSet, query):
queryTree = self.parseQuery(query)
queryFilter = self.treeToFilter(query, queryTree)
@@ -142,4 +143,4 @@ def searchFeatures(self, startSet, query):
result = startSet
if query:
result = self.searchFeatures0(result, query)
- return result.distinct().order_by('-'+self.timeField)
+ return result.distinct().order_by('-' + self.timeField)
@@ -8,11 +8,12 @@
from geocamLens.SearchAbstract import SearchAbstract
+
class SearchSimple(SearchAbstract):
def getAllFeatures(self):
return PointFeature.objects.filter(processed=True)
fields = ('name', 'user', 'notes', 'tags', 'uuid')
- timeField = 'timestamp' # FIX: handle features with non-zero time extent
+ timeField = 'timestamp' # FIX: handle features with non-zero time extent
# pairs (user-facing-field-name, django-field-name)
fieldAliases = (('user', 'author__username'),)
@@ -14,6 +14,7 @@
from geocamUtil import MimeMultipartFormData
+
class UploadClient:
def __init__(self, url, userName='root', password=''):
self.url = url
@@ -44,7 +45,7 @@ def uploadImage(self, imageName, attributes, downsampleFactor=1):
if downsampleFactor != 1:
im = PIL.Image.open(imageName)
w, h = im.size
- thRes = (w//downsampleFactor, h//downsampleFactor)
+ thRes = (w // downsampleFactor, h // downsampleFactor)
im.thumbnail(thRes, PIL.Image.ANTIALIAS)
fd, tmpName = tempfile.mkstemp('uploadImageThumb.jpg')
os.close(fd)
@@ -56,7 +57,7 @@ def uploadImage(self, imageName, attributes, downsampleFactor=1):
imageData = file(imageName, 'r').read()
#cookieProcessor = urllib2.HTTPCookieProcessor()
- opener = urllib2.build_opener() # (cookieProcessor)
+ opener = urllib2.build_opener() # (cookieProcessor)
headers = {'User-Agent': 'GeoCam Upload Tester'}
multipart = MimeMultipartFormData.MimeMultipartFormData()
@@ -83,7 +84,7 @@ def uploadTrack(self, url, trackName, attributes=None):
attributes = dict(trackUploadProtocolVersion='1.0')
#cookieProcessor = urllib2.HTTPCookieProcessor()
- opener = urllib2.build_opener() # (cookieProcessor)
+ opener = urllib2.build_opener() # (cookieProcessor)
headers = {'User-Agent': 'GeoCam Upload Tester'}
url = '%s/track' % self.url
@@ -18,10 +18,12 @@
CACHED_CSS = None
+
class BogusRequest:
def build_absolute_uri(self, text):
return text
+
class ViewKml(object):
def kmlGetStartSessionKml(self, request, sessionId):
urlPath = urlresolvers.reverse('geocamLens_kmlGetSessionResponse',
@@ -106,14 +108,14 @@ def kmlGetInitialKml(self, request, sessionId):
</Link>
</NetworkLink>
""" % dict(updateUrl=updateUrl))
-
+
result += ("""
%(allFeaturesFolder)s
</Document>
""" % dict(allFeaturesFolder=allFeaturesFolder))
return result
-
+
def kmlGetUpdateKml(self, request, sessionId):
# FIX: implement me -- can use old version of geocam for reference
return ''
@@ -6,28 +6,19 @@
# Create your views here.
-import math
import sys
-import datetime
import os
-import shutil
-import urllib
import tempfile
-import shutil
import PIL.Image
-import tagging
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import render_to_response
-from django.utils.safestring import mark_safe
from django.template import RequestContext
from django.contrib.auth.models import User
from geocamUtil import anyjson as json
from geocamUtil.icons import cacheIcons
-from geocamUtil.middleware.SecurityMiddleware import requestIsSecure
from geocamUtil.models.UuidField import makeUuid
-from geocamUtil.FileUtil import mkdirP
from geocamLens.models import Image
from geocamLens.forms import UploadImageForm, EditImageForm
@@ -38,6 +29,7 @@
cacheIcons(os.path.join(settings.MEDIA_ROOT, 'geocamLens', 'icons', 'map'))
cacheIcons(os.path.join(settings.MEDIA_ROOT, 'geocamLens', 'icons', 'mapr'))
+
class ViewLensAbstract(ViewKml):
# override in derived classes
search = None
@@ -54,17 +46,17 @@ def getMatchingFeatures(self, request):
def dumps(self, obj):
if 1:
- return json.dumps(obj, indent=4, sort_keys=True) # pretty print for debugging
+ return json.dumps(obj, indent=4, sort_keys=True) # pretty print for debugging
else:
- return json.dumps(obj, separators=(',',':')) # compact
+ return json.dumps(obj, separators=(',', ':')) # compact
def getFeaturesGeoJson(self, request):
try:
matches = self.getMatchingFeatures(request)
errorMessage = None
except BadQuery, e:
errorMessage = e.message
-
+
numFeaturesParam = request.GET.get('n')
if numFeaturesParam:
if numFeaturesParam == 'all':
@@ -116,9 +108,9 @@ def getExportSettings(self):
for f in exportedVars))
return json.dumps(exportDict)
- def editImage0(self, request, id, template):
- img = self.defaultImageModel.objects.get(id=id)
- ajax = request.POST.has_key('ajax')
+ def editImage0(self, request, imgId, template):
+ img = self.defaultImageModel.objects.get(id=imgId)
+ ajax = 'ajax' in request.POST
if request.method == 'POST':
form = EditImageForm(request.POST, instance=img)
if form.is_valid():
@@ -140,13 +132,13 @@ def editImage0(self, request, id, template):
(template,
dict(img=img,
form=form),
- context_instance = RequestContext(request)))
-
- def editImage(self, request, id):
- return self.editImage0(request, id, 'editImage.html')
+ context_instance=RequestContext(request)))
- def editImageWrapper(self, request, id):
- return self.editImage0(request, id, 'editImageWrapper.html')
+ def editImage(self, request, imgId):
+ return self.editImage0(request, imgId, 'editImage.html')
+
+ def editImageWrapper(self, request, imgId):
+ return self.editImage0(request, imgId, 'editImageWrapper.html')
def uploadImageAuth(self, request):
return self.uploadImage(request, request.user.username)
@@ -185,7 +177,7 @@ def uploadImage(self, request, userName):
newVersion = img.version + 1
else:
# create Image db record
- img = self.defaultImageModel()
+ img = self.defaultImageModel() # pylint: disable-msg=E1102
img.readImportVals(storePath=tempStorePath,
uploadImageFormData=form.cleaned_data)
@@ -196,7 +188,7 @@ def uploadImage(self, request, userName):
im = PIL.Image.open(tempStorePath, 'r')
newRes = im.size
del im
-
+
if sameUuid:
oldRes = (img.widthPixels, img.heightPixels)
if newRes > oldRes:
@@ -238,7 +230,7 @@ def uploadImage(self, request, userName):
userAgent = request.META.get('HTTP_USER_AGENT', '')
# swfupload user can't see errors in form response, best return an error code
if 'Flash' in userAgent:
- return http.HttpResponseBadRequest('<h1>400 Bad Request</h1>')
+ return HttpResponseBadRequest('<h1>400 Bad Request</h1>')
else:
form = UploadImageForm()
#print 'form:', form
@@ -250,8 +242,8 @@ def uploadImage(self, request, userName):
print >>sys.stderr, 'upload image end'
return resp
- def viewPhoto(self, request, id):
+ def viewPhoto(self, request, imgId):
# this is not very efficient
- img = Image.objects.get(id=id)
+ img = Image.objects.get(id=imgId)
imgData = file(img.getImagePath(), 'r').read()
return HttpResponse(imgData, mimetype='image/jpeg')
@@ -4,14 +4,10 @@
# All Rights Reserved.
# __END_LICENSE__
-import os
-
-from geocamUtil.icons import cacheIcons
-
from geocamLens.ViewLensAbstract import ViewLensAbstract
from geocamLens.models import Photo
from geocamLens.SearchSimple import SearchSimple
-from geocamLens import settings
+
class ViewLensSimple(ViewLensAbstract):
search = SearchSimple()
@@ -22,12 +22,13 @@
'serial': 1
}
+
def get_version():
"""
Return the formatted version information
"""
vers = ["%(major)i.%(minor)i" % __version_info__, ]
-
+
if __version_info__['micro']:
vers.append(".%(micro)i" % __version_info__)
if __version_info__['releaselevel'] != 'final':
View
@@ -6,7 +6,7 @@
from django.contrib import admin
-from geocamLens.models import *
+from geocamLens.models import * # pylint: disable-msg=W0401
admin.site.register(Snapshot)
admin.site.register(GoogleEarthSession)
View
@@ -6,14 +6,13 @@
import datetime
-from django.core.exceptions import ValidationError
from django import forms
-from django.contrib.auth.models import User
from geocamUtil.forms.UuidField import UuidField
from geocamLens.models import Photo
+
# the field names in this form are currently retained for backward compatibility with old versions
# of GeoCam Mobile
class UploadImageForm(forms.Form):
@@ -33,6 +32,7 @@ class UploadImageForm(forms.Form):
uuid = UuidField(required=False)
folder = forms.CharField(max_length=32, required=False)
+
class EditImageForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(EditImageForm, self).__init__(*args, **kwargs)
@@ -44,4 +44,3 @@ def __init__(self, *args, **kwargs):
class Meta:
model = Photo
fields = ('notes', 'tags', 'latitude', 'longitude', 'altitude', 'altitudeRef', 'yaw', 'yawRef', 'icon')
-
Oops, something went wrong.

0 comments on commit dfd3c9c

Please sign in to comment.