Пример #1
0
def active_data_migration(request):
    """瓦片日常活动内容数据迁移"""
    if not request.user.is_staff:
        return render(request, "403.html")
    tiles = Tile.objects.filter(is_tips=0,category_id=9,group__isnull=False)
    i = 0
    for t in tiles:
        try:
            has_migration = TileToActivity.objects.get(tile=t)
        except:
            has_migration = None
            
        if not has_migration:
            active_description = get_active_description(t.description)
            if active_description:
                active = Activity()
                active.creator = t.creator
                active.user = t.user
                active.group_id = t.group_id
                active.description = json.dumps({"events":active_description})
                active.start_time = t.start_time
                active.microsecond = t.microsecond
                active.save()
                migration = TileToActivity()
                migration.tile = t
                migration.active = active
                migration.save()
                i += 1
    message = "actives_count:" + str(i)
    return HttpResponse(message)
Пример #2
0
    def modify(self, request):
        """
        修改一条内容, 针对个人或者班级.

        ``POST`` `tiles/modify/ <http://192.168.1.222:8080/v1/tiles/modify>`_

        :param id:
            瓦片id
            
        :param type_id:
            瓦片类型

        :param uid:
            发布者,默认为匿名用户(uid: -1)

        :param class_id:
            瓦片所属班级,是否属于班级的内容

        :param content:
            内容描述

        :param img:
            二进制图片信息.
        """
        params = request.POST
        id = params.get("id")
        type_id = params.get("type_id","")
        uid = params.get("uid", "")
        class_id = params.get("class_id","")
        content = params.get("content", "")
        category_id = params.get("category_id",type_id)
        img = request.FILES.get('img','')
        video = params.get("video", "")
        title = params.get("title", "")
        print id,'======='
        try:
            tile = Tile.objects.get(pk=id)
        except Tile.DoesNotExist:
            return rc.not_here("tile object is not exist")

        category_id = int(category_id)
        if category_id in (1,2,3):
            category_id = 17

        if type_id:
            try:
                tile_type = TileType.objects.get(pk=type_id)
            except TileType.DoesNotExist:
                return rc.not_here("tile_type object is not exist")
            tile.type_id = type_id
            #return rc.NOT_HERE
        if category_id:
            try:
                tile_category = TileCategory.objects.all_with_deleted().get(pk=category_id)
            except TileCategory.DoesNotExist:
                return rc.not_here("tile_category object is not exist")
            tile.category_id = category_id
            
        if uid:
            try:
                user = User.objects.get(pk=uid)
            except User.DoesNotExist:
                return rc.not_here("user object  is not exist")
            tile.user = user

        if class_id:
            try:
                group = Group.objects.get(pk=class_id)
            except Group.DoesNotExist:
                return rc.not_here("group object  is not exist")
            tile.group = group
        
        if title:
            tile.title = title
        if content:
            tile.description = content
        if img:
            tile.img = img 
        if video:
            tile.video = video
        
        if tile.category_id == 9:
            #if not group:
                #return rc.not_here("group object is not exist for Activity")
            try:
                desc = json.loads(tile.description)
                act = desc['events']
            except:
                return rc.not_here("Activity description object must be json include key events")
            if not act:
                desc = ''
            else:
                i = 0
                for d in act:
                    if not d['content']:
                       i += 1 
                if i == len(act):
                    desc = ''
            if not desc:
                return rc.not_here("Activity description object can not be null")
            try:
                has_migration = TileToActivity.objects.get(tile=tile)
            except:
                has_migration = None
            if has_migration:
                active = has_migration.active
            else:
                active = Activity()
                
            active.user = tile.user
            active.creator = tile.creator
            active.group = tile.group
            active.start_time = tile.start_time
            active.microsecond = tile.microsecond
            active.description = json.dumps({"events":desc['events']})
            active.save()   
            
            if not has_migration:
                migration = TileToActivity()
                migration.tile = tile
                migration.active = active
                migration.save()  
            
        tile.save()
        return tile