def map(request, images, lat, lng): gmap = maps.Map( opts={ 'center': maps.LatLng(float(lat), float(lng)), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 2, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) for image in images: location = image.location if not image.has_latlng(): continue lat, lng = location.lat, location.lng if not lat or not lng: continue marker = maps.Marker(opts={ 'map': gmap, 'title': image.title, 'position': maps.LatLng(lat, lng) }) maps.event.addListener(marker, 'click', 'myobj.markerOver') #maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<a href="' + reverse('image', args=(image.pk, )) + '"><h1 class="marker_title">' + image.title + '</h1><img class="marker_image" src="/' + image.image.url + '"></a>', 'disableAutoPan': False }) info.open(gmap, marker) return gmap
def oferta_detalhe(request, cidade_slug, oferta_slug): cidade = Cidade.objects.get(slug=cidade_slug) cidades_disponiveis = Cidade.objects.all() try: user_msg = request.GET.get('user_msg', None) except: user_msg = None oferta = get_object_or_404(Oferta, slug=oferta_slug) if not oferta.esta_expirado(): tempo_restante = oferta.publicado_em.strftime( "%d,%m,%Y") #+ ' 11:59 PM' else: tempo_restante = -1 #Mapa gmap = maps.Map( opts={ 'center': maps.LatLng(oferta.latitude, oferta.longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 15, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU #'style': maps.MapTypeControlStyle }, }) marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(oferta.latitude, oferta.longitude), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<h3>' + oferta.anunciante.nome + '</h3>' + '<p>Rua: ' + oferta.anunciante.endereco + '</p>' + '<p>Telefone: ' + oferta.anunciante.telefone + '</p>', 'disableAutoPan': False }) info.open(gmap, marker) context = { 'form': MapForm(initial={'map': gmap}), 'user_msg': user_msg, 'oferta': oferta, 'tempo_restante': tempo_restante, 'cidades_disponiveis': cidades_disponiveis, } return render_to_response('oferta_detalhes.html', context)
def cupon_detalhes(request, cidade_slug, cupon_slug): cidade = get_object_or_404(Localizacao, slug=cidade_slug) cidades_disponiveis = Localizacao.objects.filter(ativo=True) cupom = get_object_or_404(Cupon, slug=cupon_slug) #cidade_cliente=_cidade_cliente(request) cidade_cliente = 'goiania' #pega a mensagem da url try: user_msg = request.GET.get('user_msg', None) except: user_msg = None #Mapa gmap = maps.Map( opts={ 'center': maps.LatLng(cupom.latitude, cupom.longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 15, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(cupom.latitude, cupom.longitude), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<h3>' + cupom.anunciante.nome + '</h3>' + '<p>Rua: ' + cupom.anunciante.endereco + '</p>' + '<p>Telefone: ' + cupom.anunciante.telefone + '</p>', 'disableAutoPan': False }) info.open(gmap, marker) form_busca = FormBuscar() context = { 'form': MapForm(initial={'map': gmap}), 'user_msg': user_msg, 'cupom': cupom, # 'porcentagem_vendido': porcentagem_vendido, # 'desconto': desconto, 'form_busca': form_busca, 'cidade_cliente': cidade_cliente, 'cidades_disponiveis': cidades_disponiveis, } return render_to_response('oferta/oferta_detalhes.html', context)
def mapview(request, template_name='bikematchapp/mapview.html'): gmap = maps.Map( opts={ 'center': maps.LatLng(34.122605, -118.309708), #USC is 34.0205N, 118.2856W 'mapTypeId': maps.MapTypeId.ROADMAP, #'size': maps.Size(800,600), 'zoom': 11, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) for profile in Profile.objects.all(): if profile.location: if profile.profile_pic_small.url: image = os.path.join(profile.profile_pic_small_border.url) else: image = os.path.join(settings.STATIC_URL, "images", "bike_blue.png") marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(profile.location.latitude, profile.location.longitude), 'icon': image, 'profile_username': profile.user.username }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') maps.event.addListener(marker, 'click', 'myobj.onClick') contentString = '<div class="row"><div class="span2"><img src="%s"/></div><div class="span2"><p><strong>%s</strong></p><p>%s</p></div></div>' % ( escape(profile.profile_pic_med.url), escape( profile.name), escape(profile.about[:60] + "..")) info = maps.InfoWindow({ 'content': contentString, }) info.open(gmap, marker) return render_to_response(template_name, {'form': MapForm(initial={'map': gmap})}, context_instance=RequestContext(request))
def oferta_detalhe(request, cidade_slug, oferta_slug): try: user_msg = request.GET.get('user_msg', None) except: user_msg = None oferta = get_object_or_404(Oferta, slug=oferta_slug) if not oferta.esta_expirado(): tempo_restante = oferta.publicado_em.strftime( "%Y,%m,%d") #+ ' 11:59 PM' else: tempo_restante = -1 #Mapa gmap = maps.Map( opts={ 'center': maps.LatLng(oferta.latitude, oferta.longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 15, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU #'style': maps.MapTypeControlStyle }, }) marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(oferta.latitude, oferta.longitude), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({'content': 'Hello!', 'disableAutoPan': True}) info.open(gmap, marker) context = { 'form': MapForm(initial={'map': gmap}), 'user_msg': user_msg, 'oferta': oferta, 'tempo_restante': tempo_restante, } return render_to_response('oferta_detalhes.html', context)
def get_map(request, latitude=Substation.get_center_latitude(), longitude=Substation.get_center_longitude(), zoom=8): gmap = maps.Map( opts={ 'center': maps.LatLng(latitude, longitude), 'mapTypeId': maps.MapTypeId.HYBRID, 'zoom': zoom, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DEFAULT }, }) substations = Substation.objects.all() substation_url = 'http://' + request.get_host() + '/substation/' for substation in substations: marker = maps.Marker( opts={ 'map': gmap, 'position': maps.LatLng(substation.position.latitude, substation.position.longitude), }) marker.setTitle(substation_url + str(substation.pk)) maps.event.addListener(marker, 'click', 'marker.markerClick') maps.event.addListener(marker, 'mouseover', 'marker.markerOver') maps.event.addListener(marker, 'mouseout', 'marker.markerOut') info = maps.InfoWindow({ 'content': substation.name, 'disableAutoPan': True }) info.open(gmap, marker) return gmap
def generate_map(latitude, longitude): if not latitude or not longitude: return None gmap = maps.Map( opts={ 'center': maps.LatLng(latitude, longitude), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 12, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) marker = maps.Marker(opts={ 'map': gmap, 'position': maps.LatLng(latitude, longitude), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({'content': 'Hello!', 'disableAutoPan': False}) info.open(gmap, marker) return MapForm(initial={'map': gmap})
def get_map(self): gmap = maps.Map() for form_object in self.object_list: if form_object.show_on_map: try: lng, lat = getattr(form_object, form_object.location_field()).coords marker = maps.Marker(opts={ 'map': gmap, 'position': maps.LatLng(lat, lng), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<a href="{url}">{text}</a>'.format( text=form_object.__unicode__().encode('utf-8'), url=reverse('web_update', kwargs={ 'model_name': form_object.model_name(), 'pk': form_object.pk })), 'disableAutoPan': True }) info.open(gmap, marker) except (TypeError, AttributeError ): #no coordinates field or it has invalid value continue class MapForm(Form): map = Field(widget=GoogleMap(attrs={'width': 800, 'height': 550})) return MapForm(initial={'map': gmap})
def dana(request, **kwargs): tmpl = 'core/dana.html' #Contains counts of #encounters/x, x is location, concept, etc. numencs = {} #Contains counts of #subjects/x, x is location, concept, etc. All x except location are associated with subject via the encounters numsubjs = {} #Contains counts of #x and #x that have actually happened in the trial so far nums = {'enum':Encounter.objects.all().count()} numencs['e_in_s'] = Subject.objects.annotate(revcount = Count('encounter')).order_by('-revcount') nums['snum'] = numencs['e_in_s'].count() nums['snum_in_e'] = numencs['e_in_s'].exclude(revcount=0).count() numencs['e_in_p'] = Procedure.objects.annotate(revcount = Count('encounter')).order_by('-revcount') numencs['e_in_cc'] = Concept.objects.annotate(revcount = Count('encounter')).order_by('-revcount') numencs['e_in_o'] = Observer.objects.annotate(revcount = Count('encounter')).order_by('-revcount') nums['onum_in_e'] = numencs['e_in_o'].exclude(revcount=0).count() nums['onum'] = numencs['e_in_o'].count() numsubjs['s_in_l'] = Location.objects.annotate(revcount = Count('subject')).order_by('-revcount') numsubjs['o_s_in_e'] = Observer.objects.annotate(scount = Count('encounter__subject__uuid', distinct = True)).order_by('-scount') numsubjs['p_s_in_e'] = Procedure.objects.annotate(scount = Count('encounter__subject__uuid', distinct = True)).order_by('-scount') numsubjs['cc_s_in_e'] = Concept.objects.annotate(scount = Count('encounter__subject__uuid', distinct = True)).order_by('-scount') numencs['e_in_l'] = Location.objects.annotate(revcount = Count('subject__encounter')).order_by('-revcount') #All EncounterTasks that have an associated concept datesas = EncounterTask.objects.exclude(concept = '').prefetch_related() #structures that will contain sorted counts of late, ontime, early, and missing encounters basedict = {'conc': [], 'proc': [], 'loc': [], 'subj': [], 'obs': [], 'days': [], 'count': 0} timely = {'late': deepcopy(basedict), 'ontime': deepcopy(basedict), 'early': deepcopy(basedict), 'missing': deepcopy(basedict)} #function that returns whether an encounter was late, ontime, or early, and by how much def checklate(a,b): ch = (a-b).days if ch > 0: return (ch, 'late') elif ch < -1: return (abs(ch), 'early') else: return (abs(ch), 'ontime') #Adds values to appropriate list def sorttimes(entry, delay, late, timely): timely[late]['conc'].append(entry.concept) timely[late]['proc'].append(entry.procedure) timely[late]['loc'].append(entry.subject.location) timely[late]['subj'].append(entry.subject) timely[late]['obs'].append(entry.observer) timely[late]['days'].append(delay) timely[late]['count'] += 1 upcomingcount = 0 #for each EncounterTask, finds and processes corresponding encounters for x in datesas: f = Encounter.objects.filter(subject = x.subject).filter(concept = x.concept) #checks if nonextant encounters were already due. If so, they are missing. If not, they are upcoming if f.count() == 0: delay, late = checklate(datetime.today().date(), x.due_on.date()) if late == 'late': timely['missing']['conc'].append(x.concept) timely['missing']['proc'].append(x.procedure) timely['missing']['loc'].append(x.subject.location) timely['missing']['subj'].append(x.subject) timely['missing']['obs'].append(x.assigned_to) timely['missing']['days'].append(delay) timely['missing']['count'] += 1 else: upcomingcount += 1 else: #processes existing encounters for entry in f: delay, late = checklate(entry.modified.date(), x.due_on.date()) sorttimes(entry, delay, late, timely) #actually perform sorted counts on the entries that have been assigned to each category danacounts = {} for x in timely: danacounts[x] = {} for y in timely[x]: if y != 'count': danacounts[x][y] = Counter(timely[x][y]).most_common() #function that takes in a uuid and returns a hex color of the form XXXXXX def chwtocolor(uuid): return uuid.replace('-','').upper()[2:8] #Sets the basic map options gmap = maps.Map(opts = { 'center': maps.LatLng(19.3, -72.7), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 9, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) chwscolors = {} for x in Observer.objects.all(): chwscolors[x.uuid] = {'color': chwtocolor(x.uuid), 'chw': x} markers = [] pinImages = [] infos = [] content = [] mycounter = -1 obswithgps = Observation.objects.filter(node = '1a') #Places a map pin with correct observer color for every location observation for obj in obswithgps: mycounter += 1 a,b,c = map(float, obj.value_text.strip('()').replace(',','').split()) pinImages.append(maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|" + chwscolors[obj.encounter.observer.uuid]['color'], maps.Size(21, 34), maps.Point(0,0), maps.Point(10, 34))) markers.append(maps.Marker(opts = { 'map': gmap, 'position': maps.LatLng(a, b), 'icon': pinImages[mycounter], })) #Adds popup textboxes with info to describe the pinned encounter maps.event.addListener(markers[mycounter], 'mouseover', 'myobj.markerOver') maps.event.addListener(markers[mycounter], 'mouseout', 'myobj.markerOut') content.append('<p>' + str(obj.encounter.observer) + ' visited ' + str(obj.encounter.subject) + '</br>for ' + str(obj.encounter.concept) + ' on ' + str(obj.encounter.modified.date()) + '</p>') infos.append(maps.InfoWindow({ 'content': content[mycounter], 'disableAutoPan': True })) infos[mycounter].open(gmap, markers[mycounter]) return render_to_response(tmpl, context_instance=RequestContext(request, {'chwscolors': chwscolors.values(), 'nums': nums, 'numencs': numencs, 'numsubjs': numsubjs, 'form': MapForm(initial={'map': gmap}), 'upcomingcount': upcomingcount, 'danacounts': danacounts, 'timely': timely}))
def contato(request, cidade_slug): cidade = get_object_or_404(Cidade, slug=cidade_slug) cidades_disponiveis = Cidade.objects.all() #Mapa gmap = maps.Map( opts={ 'center': maps.LatLng('-34', '20'), 'mapTypeId': maps.MapTypeId.ROADMAP, 'zoom': 15, 'mapTypeControlOptions': { 'style': maps.MapTypeControlStyle.DROPDOWN_MENU }, }) marker = maps.Marker(opts={ 'map': gmap, 'position': maps.LatLng('-34', '20'), }) maps.event.addListener(marker, 'mouseover', 'myobj.markerOver') maps.event.addListener(marker, 'mouseout', 'myobj.markerOut') info = maps.InfoWindow({ 'content': '<h3>' + 'Clipper Magazine' + '</h3>' + '<p>Rua: ' + 'etc etc' + '</p>' + '<p>Telefone: ' + '62 888992212' + '</p>', 'disableAutoPan': False }) info.open(gmap, marker) #formulario de contato if request.POST: postdata = request.POST.copy() form_contato = Contato_Form(postdata) if form_contato.is_valid(): cad_contato = Contato() cad_contato.nome = form_contato.cleaned_data['nome'] cad_contato.empresa = form_contato.cleaned_data['empresa'] cad_contato.email = form_contato.cleaned_data['email'] cad_contato.telefone = cad_contato.cleaned_data['telefone'] cad_contato.mensagem = form_contato.cleaned_data['mensagem'] cad_contato.save() mensagem_site = form_contato.cleaned_data['mensagem'] mensagem = "Ola\nO %s Mandou a seguinte mensagem:\n%s" % ( cad_contato.nome, mensagem_site) email = EmailMessage(cad_contato.mensagem, mensagem, to=['*****@*****.**']) email.send() if request.is_ajax(): return render_to_response('contato/sucesso.html') else: return redirect('contato_sucesso') else: form_contato = Contato_Form() if request.session.get('email_cadastrado', False): email_cadastrado = True email_form = None else: email_cadastrado = False email_form = EmailForm() email_duplicado = False if request.POST: postdata = request.POST.copy() email_form = EmailForm(postdata) if email_form.is_valid(): cad_email = EmailInscricao() cad_email.email = email_form.cleaned_data['email'] cad_email.cidade = email_form.cleaned_data['cidade'] cad_email.save() email_cadastrado = True context = { 'form_mapa': MapForm(initial={'map': gmap}), 'email_form': email_form, 'email_cadastrado': email_cadastrado, 'form_contato': form_contato, 'cidades_disponiveis': cidades_disponiveis, 'cidade': cidade, } return render_to_response('contato/contato.html', context, context_instance=RequestContext(request))