cleanup imports and syntax warnings
This commit is contained in:
parent
7fdae917cf
commit
2d5f924891
46 changed files with 452 additions and 517 deletions
|
|
@ -9,5 +9,3 @@ import models
|
|||
class PlaceAdmin(admin.ModelAdmin):
|
||||
search_fields = ['name']
|
||||
admin.site.register(models.Place, PlaceAdmin)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,28 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
import re
|
||||
|
||||
from ox.utils import json
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Q, Manager
|
||||
|
||||
import models
|
||||
|
||||
|
||||
class PlaceManager(Manager):
|
||||
|
||||
def get_query_set(self):
|
||||
return super(PlaceManager, self).get_query_set()
|
||||
|
||||
def find(self, q='', f="globe", sw_lat=-180.0, sw_lng=-180.0, ne_lat=180.0, ne_lng=180.0):
|
||||
qs = self.get_query_set()
|
||||
qs = qs.filter(Q(
|
||||
Q(Q(sw_lat__gt=sw_lat)|Q(sw_lat__lt=ne_lat)|Q(sw_lng__gt=sw_lng)|Q(sw_lng__lt=ne_lng)) &
|
||||
Q(Q(sw_lat__gt=sw_lat)|Q(sw_lat__lt=ne_lat)|Q(sw_lng__gt=sw_lng)|Q(sw_lng__lt=ne_lng)) &
|
||||
Q(Q(sw_lat__gt=sw_lat)|Q(sw_lat__lt=ne_lat)|Q(sw_lng__lt=ne_lng)|Q(ne_lng__gt=ne_lng)) &
|
||||
Q(Q(ne_lat__gt=sw_lat)|Q(ne_lat__lt=ne_lat)|Q(sw_lng__gt=sw_lng)|Q(sw_lng__lt=ne_lng)) &
|
||||
Q(Q(ne_lat__gt=sw_lat)|Q(ne_lat__lt=ne_lat)|Q(ne_lng__gt=sw_lng)|Q(ne_lng__lt=ne_lng))
|
||||
))
|
||||
if q:
|
||||
qs = qs.filter(name_find__icontains, q)
|
||||
qs = qs.filter(name_find__icontains=q)
|
||||
return qs
|
||||
'''
|
||||
#only return locations that have layers of videos visible to current user
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
from __future__ import division, with_statement
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.conf import settings
|
||||
|
||||
import ox
|
||||
from ox.django import fields
|
||||
|
||||
import managers
|
||||
|
||||
|
||||
class Place(models.Model):
|
||||
'''
|
||||
Places are named locations, they should have geographical information attached to them.
|
||||
|
|
@ -60,7 +60,6 @@ class Place(models.Model):
|
|||
self.lng_center = ox.location.center(self.lng_sw, self.lng_ne)
|
||||
|
||||
#update area
|
||||
self.area = location.area(self.lat_sw, self.lng_sw, self.lat_ne, self.lng_ne)
|
||||
self.area = ox.location.area(self.lat_sw, self.lng_sw, self.lat_ne, self.lng_ne)
|
||||
|
||||
super(Place, self).save(*args, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ Replace these with more appropriate tests for your application.
|
|||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
|
|
@ -20,4 +22,3 @@ Another way to test that 1 + 1 is equal to 2.
|
|||
>>> 1 + 1 == 2
|
||||
True
|
||||
"""}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,37 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import os.path
|
||||
import re
|
||||
from datetime import datetime
|
||||
from urllib2 import unquote
|
||||
import mimetypes
|
||||
|
||||
from django import forms
|
||||
from django.core.paginator import Paginator
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models import Q, Avg, Count, Sum
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404, redirect
|
||||
from django.template import RequestContext
|
||||
from django.conf import settings
|
||||
|
||||
from ox.utils import json
|
||||
|
||||
from ox.django.decorators import login_required_json
|
||||
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
|
||||
from ox.django.http import HttpFileResponse
|
||||
import ox
|
||||
|
||||
import models
|
||||
from api.actions import actions
|
||||
|
||||
'''
|
||||
fixme, require admin
|
||||
'''
|
||||
|
||||
@login_required_json
|
||||
def addPlace(request):
|
||||
#FIXME: require admin
|
||||
'''
|
||||
param data
|
||||
{
|
||||
|
|
@ -56,6 +38,7 @@ def addPlace(request):
|
|||
return render_to_json_response(response)
|
||||
actions.register(addPlace)
|
||||
|
||||
|
||||
@login_required_json
|
||||
def editPlace(request):
|
||||
'''
|
||||
|
|
@ -86,17 +69,19 @@ def editPlace(request):
|
|||
return render_to_json_response(response)
|
||||
actions.register(editPlace)
|
||||
|
||||
|
||||
@login_required_json
|
||||
def removePlace(request):
|
||||
response = json_response(status=501, text='not implemented')
|
||||
return render_to_json_response(response)
|
||||
actions.register(removePlace)
|
||||
|
||||
|
||||
def findPlace(request):
|
||||
'''
|
||||
param data
|
||||
{'query': query, 'sort': array, 'range': array, 'area': array}
|
||||
|
||||
|
||||
query: query object, more on query syntax at
|
||||
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
|
||||
sort: array of key, operator dics
|
||||
|
|
@ -120,7 +105,7 @@ def findPlace(request):
|
|||
Positions
|
||||
param data
|
||||
{'query': query, 'ids': []}
|
||||
|
||||
|
||||
query: query object, more on query syntax at
|
||||
https://wiki.0x2620.org/wiki/pandora/QuerySyntax
|
||||
ids: ids of places for which positions are required
|
||||
|
|
@ -129,8 +114,7 @@ Positions
|
|||
response = json_response(status=200, text='ok')
|
||||
response['data']['places'] = []
|
||||
#FIXME: add coordinates to limit search
|
||||
for p in Places.objects.find(data['query']):
|
||||
for p in models.Place.objects.find(data['query']):
|
||||
response['data']['places'].append(p.json())
|
||||
return render_to_json_response(response)
|
||||
actions.register(findPlace)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue