def create_update_map(request, pk=None): if pk: map_obj = Map.objects.get(pk=pk) else: map_obj = None if request.method == 'POST': form = MapForm(request.POST, prefix='map', instance=map_obj) maplayers_formset = MapInlineFormset(request.POST, prefix='layers', instance=map_obj) if form.is_valid() and maplayers_formset.is_valid(): form.save() maplayers_formset.instance = form.instance maplayers_formset.save() return HttpResponseRedirect(reverse('map-list')) else: form = MapForm(prefix='map', instance=map_obj) maplayers_formset = MapInlineFormset(prefix='layers', instance=map_obj) return render_to_response('core/generic_form.html', { 'form': form, 'layer_formset': maplayers_formset, 'custom_form': 'core/map_create.html', 'object': map_obj, }, context_instance=RequestContext(request))
def addMapView(request, eventid): event = EventModel.getEvent(eventid) user=request.user if memberCheck(request.user, event) == False: return render(request, 'invite/notMember.html', {'menu' : getMenuInfo(request), 'title' : "Not Member"}) creator = isCreator(request.user, event) coplanner = isCoplanner(request.user, event) if creator == False: if coplanner == False: return render(request, 'events/notPermission.html', \ {'menu' : getMenuInfo(request), 'title' : 'Not Permission'}) if request.method == 'GET': mapform=MapForm() context = {'menu' : getMenuInfo(request), 'title' : "Add Map", \ 'cur_path' : request.get_full_path(), 'event' : event, 'mapform':mapform, } return render(request, 'maps/addMap.html', context) if request.method == 'POST': mapform=MapForm(request.POST) if mapform.is_valid(): gmap=Gmap(event=event,location=request.POST['location']) gmap.save() return HttpResponseRedirect(reverse('events:tools:maps:maps', kwargs={'eventid':eventid,}))
def create_update_map(request, job_id, map_id): if map_id: map_obj = Map.objects.get(pk=map_id) else: map_obj = None if request.method == 'POST': form = MapForm(request.POST, prefix='map', instance=map_obj) maplayers_formset = MapInlineFormset(request.POST, prefix='layers', instance=map_obj) if form.is_valid() and maplayers_formset.is_valid(): form.save() maplayers_formset.instance = form.instance maplayers_formset.save() return HttpResponseRedirect(reverse('job-detail', kwargs = {'pk': job_id})) else: form = MapForm(prefix='map', instance=map_obj) maplayers_formset = MapInlineFormset(prefix='layers', instance=map_obj) # form = [f for f in form if f.name not in ['zoom', 'projection', 'center_x', 'center_y']] return render_to_response('core/generic_form.html', { 'form': form, 'layer_formset': maplayers_formset, 'custom_form': 'core/map_create.html', 'object': map_obj, }, context_instance=RequestContext(request))
def map_create(request): form = MapForm(request.POST or None, request.FILES or None) if form.is_valid(): instance = form.save(commit=False) instance.save() messages.success(request, "Successfully Created") return redirect('mlist') context = { 'form': form, } return render(request, 'aquarium/generic_form.html', context)
def map_update(request, id=None): instance = get_object_or_404(Map, id=id) form = MapForm(request.POST or None, request.FILES or None, instance=instance) if form.is_valid(): instance = form.save(commit=False) instance.save() messages.success(request, "Successfully Updated") return redirect('mlist') context = { 'form': form, } return render(request, 'aquarium/generic_form.html', context)
def create_update_map(request, pk=None): if pk: map_obj = Map.objects.get(pk=pk) else: map_obj = None if request.method == 'POST': form = MapForm(request.POST, prefix='map', instance=map_obj) maplayers_formset = MapInlineFormset(request.POST, prefix='layers', instance=map_obj) if form.is_valid() and maplayers_formset.is_valid(): form.save() maplayers_formset.save() return HttpResponseRedirect(reverse('job-list')) else: form = MapForm(prefix='map', instance=map_obj) maplayers_formset = MapInlineFormset(prefix='layers', instance=map_obj) return render_to_response('core/generic_form.html', { 'form': form, 'layer_formset': maplayers_formset, 'custom_form': 'core/map_create.html', 'object': map_obj, }, context_instance=RequestContext(request))
def create_update_map(request, job_id, map_id): if map_id: map_obj = Map.objects.get(pk=map_id) else: map_obj = None if request.method == 'POST': form = MapForm(request.POST, prefix='map', instance=map_obj) maplayers_formset = MapInlineFormset(request.POST, prefix='layers', instance=map_obj) if form.is_valid() and maplayers_formset.is_valid(): form.save() maplayers_formset.instance = form.instance maplayers_formset.save() return HttpResponseRedirect( reverse('job-detail', kwargs={'pk': job_id})) else: form = MapForm(prefix='map', instance=map_obj) maplayers_formset = MapInlineFormset(prefix='layers', instance=map_obj) # form = [f for f in form if f.name not in ['zoom', 'projection', 'center_x', 'center_y']] return render_to_response('core/generic_form.html', { 'form': form, 'layer_formset': maplayers_formset, 'custom_form': 'core/map_create.html', 'object': map_obj, }, context_instance=RequestContext(request))
def create_map(request): if request.method == 'POST': map = MapForm(request.POST, prefix='map') layer_formset = MapInlineFormset(request.POST, prefix='layers') if map.is_valid() and layer_formset.is_valid(): # do something with the cleaned_data on the formsets. m = map.save(commit=False) layer_formset.instance = m m.save() layer_formset.save() return HttpResponseRedirect(reverse('job-list')) else: map = MapForm(prefix='map') layer_formset = MapInlineFormset(prefix='layers') print layer_formset.management_form.as_p return render_to_response('core/generic_form.html', { 'form': map, 'layer_formset': layer_formset, 'custom_form': 'core/map_create.html', },context_instance=RequestContext(request))
def coordinates(): form = MapForm() cities = mongo.db.cities data_city = [] lat = [] lon = [] name = [] pop = [] if (request.method == 'POST'): if ((request.form['latitude']) and (request.form['longitude'])): for city in cities.find().sort("population",-1): lati,longi = str(city['location']['coordinates']).split(',') lati = lati.replace("[", "") longi = longi.replace("]", "") lati = float(lati) longi = float(longi) data_city.append({'name':city['name'],'lat':lati, 'lon':longi, 'pop':city['population']}) for city in data_city: if ((city['lat'] == float(request.form['latitude'])) and (city['lon']==float(request.form['longitude']))): lat.append(city['lat']) lon.append(city['lon']) name.append(str(city['name']+","+str(city['pop']))) pop.append(city['pop']) break data = pd.DataFrame({'lat':lat, 'lon':lon, 'name':name,'pop':pop}) m = folium.Map(location=[20, 0], tiles="Mapbox Bright", zoom_start=2) for i in range(0,len(data)): folium.Circle([data.iloc[i]['lon'], data.iloc[i]['lat']], popup=data.iloc[i]['name'],radius=data.iloc[i]['pop']*10,color='crimson',fill=True,fill_color='crimson').add_to(m) m.save('templates/map5.html') return render_template('visualize2.html',form=form,map='map5.html') else: error = "Enter valid points!" return render_template('visualize2.html',form=form,error=error) return render_template('visualize2.html', form=form)
def create_form(self, resource=None, edit_form=False): """Return form with fields loaded from DB. :param object resource: Optional map object :param bool edit_form: Set if edit form """ form = MapForm(self.config_models, obj=resource) if edit_form: # select responsible contact form.responsible.data = self.ContactsHelper.resource_contact_id( resource.gdi_oid, self.ContactsHelper.ROLE_RESPONSIBLE) # add map layers for resource on edit for map_layer in resource.map_layers: ows_layer = map_layer.owslayer form.sublayers.append_entry({ 'layer_id': ows_layer.gdi_oid, 'layer_name': ows_layer.name, 'layer_transparency': map_layer.layer_transparency, 'layer_active': map_layer.layer_active, 'layer_order': map_layer.layer_order }) if resource.thumbnail_image: # set that thumbnail image is present form.thumbnail_present = True # select background layer form.background_layer.data = resource.gdi_oid_default_bg_layer # add permissions for resource on edit roles = self.PermissionsHelper.resource_roles(resource.gdi_oid) for role in roles: form.permissions.append_entry({ 'role_id': role.id, 'role_name': role.name, 'read': True }) # load related resources from DB session = self.session() query = session.query(self.BackgroundLayer) \ .order_by(self.BackgroundLayer.name) background_layers = query.all() session.close() # set choices for responsible select field form.responsible.choices = [(0, "")] + \ self.ContactsHelper.person_choices() # reorder fields by layer_order form.sublayers.entries.sort(key=lambda f: int(f.layer_order.data)) # set choices for map layer select field form.layer.choices = self.wms_layer_choices() # set choices for background layer select field form.background_layer.choices = [(0, "")] + [ (bg_layer.gdi_oid, bg_layer.name) for bg_layer in background_layers ] # collect role ids from permissions subform role_permission_ids = [ int(permission.data['role_id']) for permission in form.permissions ] # set choices for role permission select field # skip roles from permissions subform roles = self.PermissionsHelper.roles() form.role.choices = [(role.id, role.name) for role in roles if role.id not in role_permission_ids] return form