Пример #1
0
 def load(cls, key):
     entity = Address.get(key)
     address = AddressBean(entity.contact_ref)
     address.entity = entity
     # properties follow
     address.adr = entity.adr
     address.landline_phone = entity.landline_phone
     address.location_lock = entity.location_lock
     address.lon = entity.location.lon
     address.lat = entity.location.lat
     address.map_zoom = entity.map_zoom
     address.adr_zoom = entity.adr_zoom
     return address
Пример #2
0
 def put(self):
     try:
         self.entity.adr = self.adr
         self.entity.landline_phone = self.landline_phone
         self.entity.location = location=db.GeoPt(lon=self.lon, lat=self.lat)
         self.entity.location_lock = self.location_lock
         self.entity.map_zoom = self.map_zoom
         self.entity.adr_zoom = self.adr_zoom
         self.entity.put()
     except AttributeError:
         # prepare database object for new person
         self.entity = Address(contact_ref=self.contact_ref, adr=self.adr,
                               landline_phone=self.landline_phone,
                               location=db.GeoPt(lon=self.lon, lat=self.lat), location_lock=self.location_lock,
                               map_zoom=self.map_zoom, adr_zoom=self.adr_zoom)
         self.entity.put()
     update_index(self.entity)
Пример #3
0
class AddressBean(Take2Bean):
    @classmethod
    def new(cls,contact_ref):
        return AddressBean(contact_ref)

    @classmethod
    def load(cls, key):
        entity = Address.get(key)
        address = AddressBean(entity.contact_ref)
        address.entity = entity
        # properties follow
        address.adr = entity.adr
        address.landline_phone = entity.landline_phone
        address.location_lock = entity.location_lock
        address.lon = entity.location.lon
        address.lat = entity.location.lat
        address.map_zoom = entity.map_zoom
        address.adr_zoom = entity.adr_zoom
        return address

    @classmethod
    def edit(cls,contact_ref,request):
        key = request.get('Address_key', None)
        if key:
            address = cls.load(key)
        else:
            address = AddressBean(contact_ref)
        # properties follow
        address.adr = request.get('adr', "").split("\n")
        address.landline_phone = request.get('landline_phone', "")
        address.location_lock = True if request.get('location_lock', None) else False
        lat_raw = request.get("lat", "")
        address.lat = 0.0 if len(lat_raw) == 0 else float(lat_raw)
        lon_raw = request.get("lon", "")
        address.lon = 0.0 if len(lon_raw) == 0 else float(lon_raw)
        address.map_zoom = int(request.get('map_zoom', "8"))
        address.adr_zoom = [line.strip() for line in request.get("adr_zoom", "").split(",")]
        return address

    def __init__(self,contact_ref):
        super(AddressBean,self).__init__(contact_ref)
        # properties follow
        self.adr = []
        self.landline_phone = ""
        self.location_lock = False
        self.lon = 0.0
        self.lat = 0.0
        self.map_zoom = 8
        self.adr_zoom = []

    def validate(self):
        adr = "".join(self.adr)
        if len(adr) < 3 and self.lat == 0.0 and self.lon == 0.0:
            return ['Please enter an address']

    def get_template_values(self):
        super(AddressBean,self).get_template_values()
        # properties follow
        self.template_values['adr'] = "\n".join(self.adr)
        self.template_values['landline_phone'] = self.landline_phone
        self.template_values['lat'] = self.lat
        self.template_values['lon'] = self.lon
        self.template_values['location_lock'] = self.location_lock
        self.template_values['map_zoom'] = str(self.map_zoom)
        if self.adr_zoom:
            self.template_values['adr_zoom'] = ", ".join(self.adr_zoom)
        return self.template_values

    def put(self):
        try:
            self.entity.adr = self.adr
            self.entity.landline_phone = self.landline_phone
            self.entity.location = location=db.GeoPt(lon=self.lon, lat=self.lat)
            self.entity.location_lock = self.location_lock
            self.entity.map_zoom = self.map_zoom
            self.entity.adr_zoom = self.adr_zoom
            self.entity.put()
        except AttributeError:
            # prepare database object for new person
            self.entity = Address(contact_ref=self.contact_ref, adr=self.adr,
                                  landline_phone=self.landline_phone,
                                  location=db.GeoPt(lon=self.lon, lat=self.lat), location_lock=self.location_lock,
                                  map_zoom=self.map_zoom, adr_zoom=self.adr_zoom)
            self.entity.put()
        update_index(self.entity)