Commits

Colin Copeland committed 4831dd9

import view

Comments (0)

Files changed (4)

lib/copelco/apps/estate/forms.py

         model = House
         exclude = ('coords',)
 
+
+class ImportForm(forms.Form):
+    source = forms.CharField(widget=forms.Textarea)
+

lib/copelco/apps/estate/urls.py

     url(r'^map/$', views.house_map, name='house-map'),
     url(r'^map/markers/$', views.markers, name='house-markers'),
     url(r'^map/info/$', views.info, name='house-info'),
+    url(r'^map/import/$', views.import_house, name='house-import'),
 )

lib/copelco/apps/estate/views.py

+import urllib2
+
 from django.shortcuts import render, get_object_or_404
 from django.utils import simplejson
 from django.http import HttpResponse
 from django.core import serializers
 
+from BeautifulSoup import BeautifulSoup
 
 from copelco.apps.estate.models import House, Location, PlaceDistance
+from copelco.apps.estate.forms import ImportForm
 
 
 def house_map(request):
     context = {'address': house.address, 'distances': distances,
                'photos': photos}
     return HttpResponse(simplejson.dumps(context), mimetype='application/json')
+
+
+def import_house(request):
+    form = ImportForm(request.POST or None)
+    if form.is_valid():
+        opener = urllib2.build_opener()
+        opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)')]
+        response = opener.open(form.cleaned_data['url'])
+        soup = BeautifulSoup(response)
+        print soup
+    context = {'form': form}
+    return render(request, 'estate/import.html', context)
+

requirements/apps.txt

 googlemaps==1.0.2
 django-imagekit==0.3.5
 django-storages==1.1.1
+BeautifulSoup==3.2.0