Exemplo n.º 1
0
    def openCapsule(self, request):
        """request to open the capsule,
		if capsule is not for anonymous on first run will be assigned to
		the user and only the owener can request the opening
		"""
        TSCid = request.TSCid
        user = TSCEndpoint.get_current_user()

        (rc, response) = TSCController.openCapsule(TSCid, request.lat,
                                                   request.lng,
                                                   request.password, user)
        # assign the capsule if not anonymous and not yet assigned
        if rc == TSCController.TSCCTRL_BADTSCID:
            raise endpoints.NotFoundException('Bad tscid!')
        elif rc == TSCController.TSCCTRL_BADUSER:
            raise endpoints.BadRequestException("Can't find a user")
        elif rc == TSCController.TSCCTRL_ASSIGNED:
            return TSCResponseMessage(TSCid=TSCid,
                                      status=TSCController.TSCCTRL_OK,
                                      statusMessage='Assigned!',
                                      content='',
                                      items=[])
        # anything which does not fit into the above cases
        elif rc != TSCController.TSCCTRL_OK:
            return TSCResponseMessage(TSCid=TSCid,
                                      status=rc,
                                      statusMessage='TSCController rc',
                                      content='',
                                      items=[])

        return TSCResponseMessage(TSCid=TSCid,
                                  status=TSCController.TSCCTRL_KO
                                  if response.code != TimespaceCapsule.TSC_OK
                                  else TSCController.TSCCTRL_OK,
                                  statusMessage="disclose code: " +
                                  TimespaceCapsule.MESSAGE[response.code],
                                  content=response.data,
                                  items=[])
Exemplo n.º 2
0
	def openCapsule(self, request):
		"""request to open the capsule,
		if capsule is not for anonymous on first run will be assigned to
		the user and only the owener can request the opening
		"""
		TSCid = request.TSCid
		user = TSCEndpoint.get_current_user()

		( rc, response ) = TSCController.openCapsule(TSCid, request.lat, request.lng, request.password, user)
		# assign the capsule if not anonymous and not yet assigned
		if rc == TSCController.TSCCTRL_BADTSCID:
			raise endpoints.NotFoundException('Bad tscid!')
		elif rc == TSCController.TSCCTRL_BADUSER:
				raise endpoints.BadRequestException("Can't find a user")
		elif rc == TSCController.TSCCTRL_ASSIGNED:
			return TSCResponseMessage(
				TSCid = TSCid,
				status = TSCController.TSCCTRL_OK,
				statusMessage = 'Assigned!',
				content = '',
				items = [] )
		# anything which does not fit into the above cases
		elif rc != TSCController.TSCCTRL_OK:
			return TSCResponseMessage(
				TSCid = TSCid,
				status = rc,
				statusMessage = 'TSCController rc',
				content = '',
				items = [] )

		return TSCResponseMessage(
			TSCid = TSCid,
			status = TSCController.TSCCTRL_KO
				if response.code != TimespaceCapsule.TSC_OK
				else TSCController.TSCCTRL_OK,
			statusMessage = "disclose code: "+ TimespaceCapsule.MESSAGE[response.code],
			content = response.data,
			items = [] )