当前位置: 首页>>代码示例>>Python>>正文


Python Place.description方法代码示例

本文整理汇总了Python中models.Place.description方法的典型用法代码示例。如果您正苦于以下问题:Python Place.description方法的具体用法?Python Place.description怎么用?Python Place.description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Place的用法示例。


在下文中一共展示了Place.description方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_places

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import description [as 别名]
def import_places(temp_file, extra_params, name, description=None, private=False, 
                  user=None, existing='update', encoding='utf-8', 
                  error_cb=None, progress_cb=None, context=None,
                  format='CSV'):
    log.debug('Processing file %s with this extra params %s', temp_file, extra_params)
    errors=[]
    def add_error(line, msg):
        errors.append(_('Line %d - %s') % (line, msg))
        if error_cb:
            error_cb(line, msg)
    file_reader=fmt.get_fmt_descriptor(format).reader(temp_file, extra_params)
    exists=PlacesGroup.objects.filter(name=name, private=False).exclude(created_by=user).count()
    if exists:
        add_error(0, _('Collection with same name was created by other user'))
        return
    group, created= PlacesGroup.objects.get_or_create_ns(name=name, created_by=user)
    if created:
        group.description=description
        group.private=private
        group.save(user=user)
    elif existing=='remove':
        group.places.all().delete()
    num_lines = file_reader.count()
    with file_reader:  
        line=0    
        while True:
            line+=1
            log.debug('Processing line %d', line)
            try:
                l=file_reader.next()
            except StopIteration:
                break
            except LineError, e:
                add_error(line, e.message)
                continue
            except Exception, e:
                add_error(line, _('File reading error (%s)')% str(e))
                traceback.print_exc()
                break
            
            place_name=l['name']
            try:
                place=Place.objects.get(name=place_name, group=group)
            except Place.DoesNotExist:
                place=None
            if place and existing=='skip':
                log.debug('Skipping line %d as existing', line)
            if existing=='update' or not place:
                try:
                    with transaction.atomic():
                        if not place:
                            place=Place(name=place_name, group=group)
                        address=None
                        if l.get('address'):
                            address=Address(**l['address'])
                        place.description=l.get('description')
                        place.url=l.get('url')
                        if l.get('position'):
                            pos=l['position']      
                            place.position=Point(*pos, srid=4326)  
                        else:
                            #geocode from address
                            try:
                                new_address,point=geocode.get_coordinates_remote(address, context=context)
                            except geocode.NotFound:
                                raise LineError( _('Cannot get location for address %s')% unicode(address)) 
                            except remote.TimeoutError:
                                raise LineError(_('Geocoding process is not responding'))
                            except remote.RemoteError, e:
                                raise LineError( _('Geocoding process error (%s)')% str(e))
#                             except geocode.ServiceError, e:
#                                 raise LineError( _('Geocoding Error (%s)')% str(e))
#                             except ValueError,e:
#                                 raise LineError(_('Data Error (%s)')% str(e))
                            place.position=point
                        try:
                            if address:
                                address.save(user=user)
                                place.address=address
                            place.save(user=user)
                        except MaxObjectsLimitReached:
                            add_error(line, _('Reached limit of records per user'))   
                            break
                        except Exception, e:
                            raise LineError( _('Error saving line (%s)')%str(e))
开发者ID:izderadicka,项目名称:myplaces,代码行数:87,代码来源:implaces.py


注:本文中的models.Place.description方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。