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
try: | |
import urllib2 #urllib is in python 2.7 and later standard libraries | |
except: | |
print('You need to install the URLLIB2') | |
#Download web files. Takes a url and writes the file into the specified folder. | |
url = 'http://www.blog.pythonlibrary.org/wp-content/uploads/2012/06/wxDbViewer.zip' #URL to download data from | |
def Json_Query(url): |
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
import zipfile | |
import os | |
#Extracts files on a zip file into a given directory, if no directory is given, | |
#it extracts the files into the zip file directory. | |
def unzip_file(zip_file, my_path=None): | |
zip_file = zipfile.ZipFile(zip_file) #open the zip file | |
if my_path != None: #if directory is given, and doesn't exist, create directory. | |
if not os.path.isdir(my_path): |
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
> I'm getting an error while trying to access the review page after uploading files. I get a list index out of range error. I'm guessing that this is happening because the script can't access any of the items I uploaded to the webpage, maybe the database is empty? How do you think I might be able to solve this? Here's the error: | |
> IndexError at /webfinches/review/ | |
> | |
> list index out of range | |
> | |
> Request Method: GET | |
> Request URL: http://127.0.0.1:8000/webfinches/review/ | |
> Django Version: 1.4 | |
> Exception Type: IndexError | |
> Exception Value: |
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
def review(request): | |
"""A view for uploading new data. | |
""" | |
user=User.objects.get(username='carlos') | |
if request.method == 'POST': # someone is giving us data | |
formset = LayerReviewFormSet(request.POST, request.FILES) | |
for form in formset: | |
print 'reviewing form' | |
else: # we are asking them to review data | |
# get the last upload of this user |
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 forms.py | |
class LayerReviewForm(forms.ModelForm): | |
"""For editing and configuring the layer information for each layer.""" | |
class Meta: | |
model = DataLayer | |
fields = ['name', 'notes', 'srs','geometry_type'] | |
#from views.py | |
@login_required | |
def review(request): |
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
import shapefile | |
import zipfile | |
import os | |
shpTypeDict = { | |
"0":"Null Shape", | |
"1":"Point", | |
"3":"Polyline", | |
"5":"Polygon", | |
"8":"MultiPoint", |
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
import shapefile | |
import zipfile | |
import os | |
def get_geometry_type(zip_file): | |
shpTypeDict = { | |
"0":"Null Shape", | |
"1":"Point", | |
"3":"Polyline", | |
"5":"Polygon", |
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 models.py | |
shpTypeDict = { | |
"0":"Null Shape", | |
"1":"Point", | |
"3":"Polyline", | |
"5":"Polygon", | |
"8":"MultiPoint", | |
"11":"PointZ", | |
"13":"PolylineZ", | |
"15":"PolygonZ", |
OlderNewer