Esempio n. 1
0
 def index(self):
     from pylons import config
     import os,re
     rg = re.compile('^(?P<id>[0-9]*) \t(?P<city_name>[^\t]*)\t(?P<mahoz>[^\t]*)\t(?P<population>[0-9,]*)')
     rt=''
     fname = os.path.join(config['pylons.paths']['root'],'towns.txt')
     rt+='reading from %s\n'%fname
     f = open(fname)
     for line in f:
         res = rg.search(line)
         if not res:
             rt+='cannot parse "%s"\n'%line
             continue
         ct = City()
         ct.name=res.group('city_name').strip()
         if meta.Session.query(City).filter_by(name=ct.name).all():
             rt+='city %s ALREADY EXISTS! skipping\n'%ct.name
             continue
         ct.population = int(re.compile('([,]+)').sub('',res.group('population').strip()))
         if request.params.get('getlonlat'):
             lonlat = search_city(ct.name)
             if lonlat['successful']:
                 ct.lon = lonlat['result']['center']['lon']
                 ct.lat = lonlat['result']['center']['lat']
         meta.Session.add(ct)
         rt+='inserted city %s'%ct.name
     meta.Session.commit()
     c.output=rt
     return render('/parse_towns.html')
Esempio n. 2
0
    def index(self):
        self.getdata()
        for en in c.existings:
            singular = re.sub('^existing_','',en)
            inserted = re.sub('^existing_','inserted_',en)
            plural = singular+'s'
            if not getattr(c,en+'_id'): setattr(c,en+'_id',None)
            if len(getattr(c,plural)):
                setattr(c,'start_marking_'+singular,False)
                if not getattr(c,en):
                    setattr(c,en,getattr(c,plural)[0])
                    setattr(c,en+'_id',getattr(c,plural)[0].id)
            else:
                setattr(c,'start_marking_'+singular,True)
                setattr(c,en,None)
            #raise Exception('checking for c.%s - %s'%(inserted,getattr(c,inserted)))
            if getattr(c,inserted):
                #raise Exception('setting existing to val of inserted. plus ive got %s'%len(getattr(c,plural)))
                setattr(c,en+'_id',getattr(c,inserted).id)
                setattr(c,en,getattr(c,inserted))

        if not type(self).update_mode:  c.act = Activity()
        #raise Exception('existing area_id is %s'%c.existing_area_id)
        #assume a2 is israel
        if c.user.country<>['il','a2']:
            c.initial_coords=search_country_google(c.user.country)
            #raise Exception('got %s for %s'%(c.initial_coords,c.user.country))
        rt= render('/%s_signup.html'%type(self).tpl_postfix)
        return rt
Esempio n. 3
0
    def matches_map(self, id):
        c.weekdays = weekdays
        self.load_matches(id)

        if request.params.get("justadded") and not len(c.service_matches):
            return redirect(url.current(action="index", id=id, justadded=True))
        act = meta.Session.query(Activity).get(id)
        if not act:
            abort(404)
        c.act = act
        c.activities = [cm.activity for cm in c.service_matches]
        c.title = _(u"התאמות שירות ל%s") % act
        self.justadded(c.act)
        if request.params.get("print", False):
            return render("/%s_matches_map_print.html" % act.activity_type)
        else:
            return render("/%s_matches_map.html" % act.activity_type)
Esempio n. 4
0
    def index(self):
        c.pd = request.params.get('poly_data')
        if c.pd:
            parsed = self.parse_polydata(c.pd)
            import string
            c.autodraw_coords= '['+string.join(['new OpenLayers.Geometry.Point(%f,%f)'%(float(pdi[0]),float(pdi[1])) for pdi in parsed],',')+']'

        return render('/maptest.html')
Esempio n. 5
0
 def index(self):
     c.nomapjs=True
     if request.params.get('exc',False):
         raise Exception('test exception!')
     #raise Exception('%s'%request.environ['pylons.routes_dict'])
     #raise Exception(_('lang'))
     c.animation=False
     c.activities = meta.Session.query(Activity).all()[0:8]
     #set_lang('he')
     #raise Exception(_('Courier signup'))
     
     c.freemap_url=None; c.use_google_maps=False
     return render('/main-intro.html')
Esempio n. 6
0
 def document(self):
     resp = request.environ.get('pylons.original_response')
     from greencouriers.lib.base import render
     from pylons import tmpl_context as c
     c.code = str(resp.status_int)
     return render('/error.html')
     """Render the error document"""
     content = literal(resp.body) or cgi.escape(request.GET.get('message'))
     page = error_document_template % \
         dict(prefix=request.environ.get('SCRIPT_NAME', ''),
              code=cgi.escape(request.GET.get('code', str(resp.status_int))),
              message=content)
     return page
Esempio n. 7
0
 def matches_map(self,id):
     self.load_matches(id)
     act = meta.Session.query(Activity).get(id)
     c.act = act
     c.activities = [cm.activity for cm in c.service_matches]
     included=[]
     for sm in c.activities:
         matches = meta.Session.query(CourierMatch).filter_by(src=sm.id).all()
         for mt in matches:
             mt.activity = meta.Session.query(Activity).get(mt.tgt)
             if not mt.activity in included:
                 c.service_matches+=[mt]
                 included.append(mt.activity)
     c.activities+=included
     c.title=u'התאמות שירות ל%s'%act
     self.justadded(c.act)
     return render('/%s_matches_map.html'%act.activity_type)
Esempio n. 8
0
    def index(self, id):
        if id == "TOKEN":
            abort(404)
        c.b = meta.Session.query(Activity).get(id)
        if not c.b:
            abort(404)
        if c.b.activity_type != type(self).activity_type:
            raise Exception("is not a business!")
        c.weekdays = weekdays
        self.load_matches(id)
        # now, make sure we notified everyone about the matches :D
        self.justadded(c.b)
        load_user()

        if c.user and self._can_comment(c.user.id, c.service_matches):
            c.can_comment = True
        return render("/business.html")
Esempio n. 9
0
    def index(self):
        if c.user.country<>'il':
            from greencouriers.controllers.signup import search_country_google
            c.initial_coords=search_country_google(c.user.country)
        from pylons.i18n.translation import get_lang
        #raise Exception('just changed: %s ; user lang: %s ; environ lang: %s'%(request.params.get('just_changed'),c.user.lang,request.environ['pylons.routes_dict']['_lang']))
        if request.GET.get('just_changed')=='True':
            if c.user.lang!=request.environ['pylons.routes_dict']['_lang']:
                #raise Exception('redirecting to lang %s '%c.user.lang)
                redirect(url.current(_lang=c.user.lang))
                return None
        if request.params.get('from_main'):
            acts = meta.Session.query(Activity).filter_by(user_id=c.user.id).all()
            if len(acts)==1:
                return redirect(url.current(controller=acts[0].activity_type,action='matches_map',id=acts[0].id))
        from pylons.i18n.translation import lazify
        c.user_country = meta.Session.query(Country).filter_by(iso=c.user.country.upper()).one()

        c.activities = meta.Session.query(Activity).filter_by(user_id=c.user.id).all()
        return render('/my-account.html')
Esempio n. 10
0
    def lonlat(self,id=None):
        cities = meta.Session.query(City)
        if id:
            cities=cities.filter_by(id=id)
        else:
            from sqlalchemy import or_
            cities = cities.filter(or_(City.lon==None,City.lat==None,City.extent_top==None))

        cities = cities.all()
        rt=''
        for ct in cities:
            lonlat = search_city(ct.name.encode('utf8'))
            if lonlat['successful'] and lonlat['result']:
                ct.lon = lonlat['result']['center']['lon']
                ct.lat = lonlat['result']['center']['lat']            
                ct.extent_top = lonlat['result']['extent']['top']
                ct.extent_bottom = lonlat['result']['extent']['bottom']
                ct.extent_left = lonlat['result']['extent']['left']
                ct.extent_right = lonlat['result']['extent']['right']
                meta.Session.commit()
            else:
                rt+="cannot get loc result for town '%s' - %s\n"%(ct.name,lonlat['reason'])
        c.output=rt
        return render('/parse_towns.html')
Esempio n. 11
0
 def arbitrary_map(self):
     acts = request.params.getall('act')
     c.activities = [meta.Session.query(Activity).get(actid) for actid in acts]
     return render('/arbitrary_map.html')
Esempio n. 12
0
 def render(self):
     self.query_res = self.query.all()
     c.dg = self
     return render('/data_grid.html')
Esempio n. 13
0
 def index(self):
     c.activities_table = ActivitiesTable()
     return render('/activities_admin.html')
Esempio n. 14
0
 def change_name(self):
     return render('/change_name_form.html')
Esempio n. 15
0
 def contact(self):
     return render('/contact.html')
Esempio n. 16
0
 def businesses_map(self):
     c.activities = meta.Session.query(Activity).filter_by(activity_type='business').all()
     return render('/businesses_map.html')
Esempio n. 17
0
 def map(self):
     c.activities = meta.Session.query(Activity).all()
     return render('/all_map.html')
Esempio n. 18
0
    def index(self):
        return 'foo'
        rt=''
        businesses = meta.Session.query(Activity).filter_by(activity_type='business').all()
        couriers = meta.Session.query(Activity).filter_by(activity_type='courier').all()
        rt+="scanning %d businesses\n"%len(businesses)
        rt+="and %d couriers\n"%len(couriers)
        for b in businesses:
            if len(b.area.points)<3:
                rt+="skipping business %d because of insufficient points (%d)\n"%(b.id,len(b.area.points))
                continue
            bpoints = [(p.pos_lon,p.pos_lat) for p in b.area.points]
            bpoly = Polygon(bpoints)
            business_area=bpoly.area
            business_marker=Point(b.marker.points[0].pos_lon,b.marker.points[0].pos_lat)
            for bf in ['marker','area']:
                for cr in couriers:
                    if cr.area==b.area:
                        rt+="skipping activities %d and %d for they use the same area\n"%(b.area.id,cr.area.id) 
                        continue
                    #let's see if we have a match.
                    if cr.area.id>getattr(b,bf).id:
                        area1_id = cr.area.id
                        area2_id = getattr(b,bf).id
                    else:
                        area2_id = cr.area.id
                        area1_id = getattr(b,bf).id
                    try:
                        isr=meta.Session.query(IntersectionResult).filter_by(area1_id=area1_id,area2_id=area2_id).one()
                        rt+=". "
                        continue
                    except NoResultFound:
                        isr=IntersectionResult()
                        isr.area1_id=area1_id
                        isr.area2_id=area2_id

                    cpoints = [(p.pos_lon,p.pos_lat) for p in cr.area.points]
                    cpoly = Polygon(cpoints)
                    courier_area=cpoly.area
                    #check if areas overlap or contain each other
                    if bf=='area':
                        try:
                            un = bpoly.union(cpoly)
                        except:
                            rt+="exception between business %d and courier %d\n"%(b.id,cr.id)
                            rt+="courier is %s\n"%cpoly
                        joint_area=un.area
                        area_diff = abs(courier_area + business_area - joint_area)
                        if area_diff>0.0001:
                            isr.result='match'
                            rt+="WE HAVE A MATCH (%f)! business %d (area %d) and courier %d (area %d)\n"%(abs(area_diff),b.id,b.area.id,cr.id,cr.area.id)
                        else:
                            isr.result='mismatch'
                    #check if business location within couriers area
                    elif bf=='marker':
                        if cpoly.contains(business_marker):
                            isr.result='match'
                            rt+='COURIER AREA %s contains business mark %s\n'%(courier_area,business_marker)
                        else:
                            isr.result='mismatch'
                    else:
                        raise Exception('unknown bf %s'%bf)
                    
                    meta.Session.add(isr)
                    if not request.params.get('nocommit'):
                        meta.Session.commit()

        c.output=rt
        return render('/intersections.html')
Esempio n. 19
0
 def marking(self):
     return render('/help_marking.html')
Esempio n. 20
0
 def faq(self):
     return render('/faq.html')
Esempio n. 21
0
 def index(self):
     c.cities = meta.Session.query(City).filter(City.lon!=None).filter(City.lat!=None).all()
     return render('/display_cities.html')
Esempio n. 22
0
        else:
            msg['Reply-to'] = Header(u'%s <%s>'%(self.form_result.get('name'),self.form_result.get('reply_address')),'utf-8')

        msg['From']=Header(u'*****@*****.**','utf-8')
        msg['To']=Header(u'%s <%s>'%('Guy Romm','*****@*****.**'),'utf-8') #em.email
        part1 = MIMEText((u"%s\n%s"%(txtpref,self.form_result.get('message'))).encode('utf-8'), 'plain','utf-8')        
        msg.attach(part1)
        try:
            s = smtplib.SMTP('localhost')
            s.sendmail('*****@*****.**', '*****@*****.**', msg.as_string())
            c.message=_(u'ההודעה נשלחה בהצלחה!')
        except Exception,e:
            c.message=_(u'ארעה שגיאה בשליחת ההודעה אליך. אנא פנה לתמיכה ([email protected]) %s'%e)
        finally:
            if 's' in locals(): s.quit()
        return render('/contacted_succesfully.html')
    def about(self):
        return render('/about.html')
    def faq(self):
        return render('/faq.html')
    def arbitrary_map(self):
        acts = request.params.getall('act')
        c.activities = [meta.Session.query(Activity).get(actid) for actid in acts]
        return render('/arbitrary_map.html')
    def couriers_map(self):
        c.activities = meta.Session.query(Activity).filter_by(activity_type='courier').all()
        return render('/couriers_map.html')
    def businesses_map(self):
        c.activities = meta.Session.query(Activity).filter_by(activity_type='business').all()
        return render('/businesses_map.html')
    def map(self):
Esempio n. 23
0
 def language_country_settings(self):
     c.freemap_url=None; c.use_google_maps=False
     return render('/language_country.html')
Esempio n. 24
0
 def fb_login(self):
     return render('/fb_login.html')
Esempio n. 25
0
 def about(self):
     return render('/about.html')
Esempio n. 26
0
 def couriers_map(self):
     c.activities = meta.Session.query(Activity).filter_by(activity_type='courier').all()
     return render('/couriers_map.html')