示例#1
0
    def create_instance(self, body_data):
        """
        重载修改后:
        *.将password字段加密

        :param body_data: 创建对象时的传入数据
        :return: instance: 创建操作后的对象
        """
        password = generate_password_hash(body_data["password"],
                                          method="pbkdf2:sha256")
        body_data["password"] = password
        body_data["creator_id"] = g.login_user.id
        if "img_url" not in body_data:
            body_data[
                "img_url"] = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png"
        # 判断该模型是否支持所有输入属性
        for item in body_data:
            if not hasattr(self.model, item):
                del body_data[item]
        # 创建对象
        user = self.model(**body_data)
        db.session.add(user)
        db.session.commit()

        # 创建空间
        space_data = {
            "name": user.username + "'s private space",
            "space_type": "private",
            "own_user_id": user.id
        }
        space = Space(**space_data)
        db.session.add(space)
        db.session.commit()

        # 创建桶
        bucket_data = {
            "name": space.name + "'s 1st bucket",
            "space_id": space.id
        }
        bucket = Bucket(**bucket_data)
        db.session.add(bucket)
        db.session.commit()

        # 创建空间根目录
        bucket_data = {
            "object_name": space.name + "'s root",
            "object_type": "folder",
            "object_size": 0,
            "creator_id": user.id,
            "bucket_id": bucket.id
        }
        folder_root = File(**bucket_data)
        db.session.add(folder_root)
        db.session.commit()

        # 关联空间与根目录
        space.root_folder = folder_root
        db.session.commit()

        return user
示例#2
0
def handle_spaces():
    if request.method == 'GET':
        return jsonify(Space.getAllSerialized()), 200
    if request.method == 'POST':
        body = request.get_json()
        newSpace = Space.newInstance(body)
        newSpace.addCommit()
        return toJson(newSpace), 201
示例#3
0
文件: views.py 项目: Athrun1027/Nemi
    def create_instance(self, body_data):
        """
        重载修改后:
        *.将password字段加密

        :param body_data: 创建对象时的传入数据
        :return: instance: 创建操作后的对象
        """
        body_data["creator_id"] = g.login_user.id
        # 判断该模型是否支持所有输入属性
        for item in body_data:
            if not hasattr(self.model, item):
                del body_data[item]
        # 创建对象
        group = self.model(**body_data)
        group.users = [g.login_user, ]
        db.session.add(group)
        db.session.commit()

        # 创建空间
        space_data = {
            "name": group.name + "'s private space",
            "space_type": "group",
            "own_group_id": group.id
        }
        space = Space(**space_data)
        db.session.add(space)
        db.session.commit()

        # 创建桶
        bucket_data = {
            "name": space.name + "'s 1st bucket",
            "space_id": space.id
        }
        bucket = Bucket(**bucket_data)
        db.session.add(bucket)
        db.session.commit()

        # 创建空间根目录
        bucket_data = {
            "object_name": space.name + "'s root",
            "object_type": "folder",
            "object_size": 0,
            "creator_id": g.login_user.id,
            "bucket_id": bucket.id
        }
        folder_root = File(**bucket_data)
        db.session.add(folder_root)
        db.session.commit()

        # 关联空间与根目录
        space.root_folder = folder_root
        db.session.commit()

        return group
示例#4
0
	def add_synonyms(self, kSynonyms, sSpace = 'global'):
		
		try:
			oSpace = Space.objects.get(name=sSpace)
		except Space.DoesNotExist:
			oSpace = Space(name='global')
			oSpace.save()
			


		for sWord, kSyns in kSynonyms.iteritems():

			try:
				oWord = Word.objects.get(name=sWord, space=oSpace)
			except Word.DoesNotExist:
				oWord	= Word(name=sWord, space=oSpace)
				oWord.save()
				
			for sSyn, kProps in kSyns.iteritems():
				
				try:
					oSyn = Word.objects.get(name=sSyn, space=oSpace)
				except Word.DoesNotExist:
					oSyn = Word(name=sSyn, space=oSpace)
					oSyn.save()
					
				try:
					oRelation = Relation.objects.get(rel_one=oWord, rel_two=oSyn)
					oRelation.karma += kProps['weight']
					oRelation.save()
					
				except Relation.DoesNotExist:
					
					try:
						oRelation = Relation.objects.get(rel_two=oWord, rel_one=oSyn)
						oRelation.karma += kProps['weight']
						oRelation.save()
						
					except Relation.DoesNotExist:
						oRelation = Relation(rel_one=oWord, rel_two=oSyn, karma=kProps['weight'], space=oSpace)
						oRelation.save()
示例#5
0
 def post(self):
     if not (session and session.get('uid')):
         return jsonify({'error': 'Not logged in'})
     node = Node(title=request.form['title'])
     node.url = request.form['url']
     node.score = 1
     node.save()
     space = Space.objects(id=ObjectId(request.form['sid']))[0]
     space.nodes.append(node)
     space.save(cascade=True)
     
 	return jsonify({'success':1})
示例#6
0
def OnBlipSubmitted(properties, context):
  """Invoked when any blip we are interested in is submitted.
  
  """
  blip_id = properties['blipId']
  blip = context.GetBlipById(blip_id)
  
  if blip.GetDocument().GetText().lower().strip() == "#spaces":
      spaces = ""
      for space in Space.all():
          spaces = spaces + space.name + "\n"
      blip.CreateChild().GetDocument().SetText(spaces)
示例#7
0
def OnRobotAdded(properties, context):
  """Invoked when the robot has been added.
  
  """
  version = "4"
  
  root_wavelet = context.GetRootWavelet()
  
  # Create a new space
  name = root_wavelet.GetTitle()
  
  # search for existing
  for space in Space.all():
      if space.name == name:
          root_wavelet.CreateBlip().GetDocument().SetText("MASQ-it v" + version + "! MASQ space '" + name + "' already exists.")
          break
  else:
      new_space = Space(name = name)
      new_space.put() 
      
      root_wavelet.CreateBlip().GetDocument().SetText("MASQ-it v" + version + "! MASQ space '" + name + "' is now created.") 
示例#8
0
def newspace():
    user = User.query.filter_by(userId=get_jwt_identity()).first()
    if not user.role.has_permission(Permission.SELL):
        return jsonify(
            {'error':
             'You don\'t have permission to perform such action'}), 401
    data = request.get_json(force=True)
    new_space = Space(store_name=data['storeName'],
                      description=data['description'],
                      telephone=data['storeTel'],
                      email=data['storeEmail'],
                      farm_address=data['farmAddress'],
                      logo=data['logoUrl'])
    db.session.add(new_space)
    try:
        new_space.farmer = user
        db.session.flush()
        db.session.commit()
    except IntegrityError:
        db.session.rollback()
        return jsonify({'error': 'Store Name is already taken'}), 401
    return jsonify({'msg': 'New store created successfully!'}), 200
示例#9
0
    def on_post(self, req, resp):
        # TODO validate json paylaod
        data = req.json
        try:
            space = Space(office_id=data['office_id'],
                          basic_units=json.dumps(data['basic_units']),
                          owner_name=data.get('owner_name'),
                          owner_id=data.get('owner_id'),
                          team=data.get('team'),
                          space_type=data.get('space_type'),
                          project=data.get('project'))
            req.db.save(space)

            resp.json = self._space_to_json(space)
            resp.status = falcon.HTTP_CREATED
        except (TypeError, JSONDecodeError) as e:
            raise falcon.HTTPBadRequest(e)
示例#10
0
def dispatch(request):
  print 'in dispatch'
  s = Space(tok_session_id = TokBox.generate_session_id(), url_id=uuid.uuid4())
  s.save()

  return redirect('/%s/' % str(s.url_id))
示例#11
0
from models import Space

print "Content-Type: text/plain"
print ""
print "Hello, world!"

space = Space(name="SomeSpace")
space.put()

for space in Space.all():
    print space.name, ","
示例#12
0
def dispatch(request):
    print 'in dispatch'
    s = Space(tok_session_id=TokBox.generate_session_id(), url_id=uuid.uuid4())
    s.save()

    return redirect('/space/%s/' % str(s.url_id))