Ejemplo n.º 1
0
	def json(self, argv):
		self.manager 	= MovieManager(self.site, self.module)
		action 			= self.site.get_argument('action', None)
		if action == 'setting':
			post_id 	= self.site.get_argument('post', None)
			if post_id:
				if type(post_id) == str and re.match(r'[a-z0-9]{24}', post_id):
					post_id 		= ObjectId(post_id)

				mv_setting = self.site.get_argument('setting', None)

				if mv_setting == "complete":
					mv_setting = "mvc"
				elif mv_setting == "remove":
					mv_setting = "mvd"
				result = yield self.manager.set_user_view_post(post_id, mv_setting)
				if result:
					return '{"error":0,"success":1}'
		else:
			post_id 	= self.site.get_argument('post', None)
			if not post_id:
				posts_view 	= yield self.manager.get_user_view_post()
				if posts_view:
					post_id = []
					for p in posts_view:
						if 'post_id' in p:
							post_id.append(p['post_id'])
			###
			posts = yield self.post_json(post_id)
			posts_argv 	= []
			for post in posts:
				posts_argv.append(self.post_argv(post))
					
			return {"post": posts_argv}
		return '{"error":1,"success":0}'
Ejemplo n.º 2
0
def adjust_id(query):
    """
    We need to adjust input query who has '_id' as a string to ObjectId
    used in MongoDB.
    """
    spec = query['spec']
    if  '_id' in spec:
        val = spec['_id']
        if  isinstance(val, str):
            newval = ObjectId(val)
            spec['_id'] = newval
        elif isinstance(val, unicode):
            newval = ObjectId(unicode.encode(val))
            spec['_id'] = newval
        elif isinstance(val, list):
            newval = []
            for item in val:
                if  isinstance(item, str):
                    newval.append(ObjectId(item))
                elif isinstance(item, unicode):
                    newval.append(ObjectId(unicode.encode(item)))
                else:
                    raise Exception('Wrong type for id, %s=%s' \
                        % (item, type(item)))
            spec['_id'] = newval
        query['spec'] = spec
    return query
Ejemplo n.º 3
0
def adjust_id(query):
    """
    We need to adjust input query who has '_id' as a string to ObjectId
    used in MongoDB.
    """
    spec = query['spec']
    if '_id' in spec:
        val = spec['_id']
        if isinstance(val, str):
            newval = ObjectId(val)
            spec['_id'] = newval
        elif isinstance(val, unicode):
            newval = ObjectId(unicode.encode(val))
            spec['_id'] = newval
        elif isinstance(val, list):
            newval = []
            for item in val:
                if isinstance(item, str):
                    newval.append(ObjectId(item))
                elif isinstance(item, unicode):
                    newval.append(ObjectId(unicode.encode(item)))
                else:
                    raise Exception('Wrong type for id, %s=%s' \
                        % (item, type(item)))
            spec['_id'] = newval
        query['spec'] = spec
    return query
Ejemplo n.º 4
0
    def test_deepcopy(self):
        deepcopy = two.propcache.deepcopy

        val = None
        self.assertTrue(deepcopy(val) is val)
        val = True
        self.assertTrue(deepcopy(val) is val)
        val = 5
        self.assertTrue(deepcopy(val) is val)
        val = -2.5
        self.assertTrue(deepcopy(val) is val)
        val = ObjectId()
        self.assertTrue(deepcopy(val) is val)

        val = []
        res = deepcopy(val)
        self.assertFalse(val is res)
        self.assertEqual(val, res)
        val.append(1)
        self.assertNotEqual(val, res)

        val = {}
        res = deepcopy(val)
        self.assertFalse(val is res)
        self.assertEqual(val, res)

        val = [1, [2, {}], {'x': 'y', 'z': [1, 2]}]
        res = deepcopy(val)
        self.assertFalse(val is res)
        self.assertEqual(val, res)
        self.assertTrue(val[0] is res[0])
        self.assertFalse(val[1] is res[1])
        self.assertEqual(val[1], res[1])
        self.assertFalse(val[2] is res[2])
        self.assertEqual(val[2], res[2])
        self.assertFalse(val[2]['z'] is res[2]['z'])
        self.assertEqual(val[2]['z'], res[2]['z'])

        loopobj = []
        loopobj.append(loopobj)
        with self.assertRaises(TypeError):
            deepcopy(loopobj)

        loopobj = {}
        loopobj['key'] = loopobj
        with self.assertRaises(TypeError):
            deepcopy(loopobj)
Ejemplo n.º 5
0
    def test_deepcopy(self):
        deepcopy = two.propcache.deepcopy
        
        val = None
        self.assertTrue(deepcopy(val) is val)
        val = True
        self.assertTrue(deepcopy(val) is val)
        val = 5
        self.assertTrue(deepcopy(val) is val)
        val = -2.5
        self.assertTrue(deepcopy(val) is val)
        val = ObjectId()
        self.assertTrue(deepcopy(val) is val)

        val = []
        res = deepcopy(val)
        self.assertFalse(val is res)
        self.assertEqual(val, res)
        val.append(1)
        self.assertNotEqual(val, res)
        
        val = {}
        res = deepcopy(val)
        self.assertFalse(val is res)
        self.assertEqual(val, res)

        val = [1, [2, {}], {'x':'y', 'z':[1,2]}]
        res = deepcopy(val)
        self.assertFalse(val is res)
        self.assertEqual(val, res)
        self.assertTrue(val[0] is res[0])
        self.assertFalse(val[1] is res[1])
        self.assertEqual(val[1], res[1])
        self.assertFalse(val[2] is res[2])
        self.assertEqual(val[2], res[2])
        self.assertFalse(val[2]['z'] is res[2]['z'])
        self.assertEqual(val[2]['z'], res[2]['z'])

        loopobj = []
        loopobj.append(loopobj)
        with self.assertRaises(TypeError):
            deepcopy(loopobj)
            
        loopobj = {}
        loopobj['key'] = loopobj
        with self.assertRaises(TypeError):
            deepcopy(loopobj)