def put(self):
        agent = self.__get_agent(create=True)
        if self.registrationId:
            p,created = models.ActivityState.objects.get_or_create(state_id=self.stateId,agent=agent,activity_id=self.activity_id,registration_id=self.registrationId)
        else:
            p,created = models.ActivityState.objects.get_or_create(state_id=self.stateId,agent=agent,activity_id=self.activity_id)
        
        if self.content_type != "application/json":
            try:
                state = ContentFile(self.state.read())
            except:
                try:
                    state = ContentFile(self.state)
                except:
                    state = ContentFile(str(self.state))

            if not created:
                etag.check_preconditions(self.req_dict,p)
                p.state.delete() # remove old state file
            self.save_state(p, created, state)
        else:
            if not created:
                etag.check_preconditions(self.req_dict, p)
            the_state = self.state
            p.json_state = the_state
            p.content_type = self.content_type
            p.etag = etag.create_tag(the_state)
            if self.updated:
                p.updated = self.updated
            p.save()
Beispiel #2
0
    def put(self):
        agent = self.__get_agent(create=True)
        try:
            state = ContentFile(self.state.read())
        except:
            try:
                state = ContentFile(self.state)
            except:
                state = ContentFile(str(self.state))

        if self.registrationId:
            p,created = models.activity_state.objects.get_or_create(state_id=self.stateId,agent=agent,activity=self.activity,registration_id=self.registrationId)
        else:
            p,created = models.activity_state.objects.get_or_create(state_id=self.stateId,agent=agent,activity=self.activity)
        if not created:
            etag.check_preconditions(self.req_dict,p)
            p.state.delete() # remove old state file
        p.content_type = self.content_type
        p.etag = etag.create_tag(state.read())
        if self.updated:
            p.updated = self.updated
        state.seek(0)
        if created:
            p.save()

        fn = "%s_%s_%s" % (p.agent_id,p.activity_id, self.req_dict.get('filename', p.id))
        p.state.save(fn, state)
Beispiel #3
0
    def put_profile(self, request_dict):
        profile_id = request_dict['params']['profileId']

        p,created = AgentProfile.objects.get_or_create(profileId=profile_id,agent=self.Agent)

        if "application/json" not in request_dict['headers']['CONTENT_TYPE']:
            try:
                profile = ContentFile(request_dict['profile'].read())
            except:
                try:
                    profile = ContentFile(request_dict['profile'])
                except:
                    profile = ContentFile(str(request_dict['profile']))
        

            if not created:
                etag.check_preconditions(request_dict,p, required=True)
                p.profile.delete()
            self.save_profile(p, created, profile, request_dict)
        else:
            if not created:
                etag.check_preconditions(request_dict, p, required=True)
            the_profile = request_dict['profile']
            p.json_profile = the_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(the_profile)

            if 'headers' in request_dict and ('updated' in request_dict['headers'] and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
            p.save()
Beispiel #4
0
    def put_profile(self, request_dict):
        profile_id = request_dict['params']['profileId']
        if not uri.validate_uri(profile_id):
            err_msg = 'Profile ID %s is not a valid URI' % profile_id
            raise ParamError(err_msg)

        p, created = AgentProfile.objects.get_or_create(profileId=profile_id,
                                                        agent=self.Agent)

        if request_dict['headers']['CONTENT_TYPE'] != "application/json":
            try:
                profile = ContentFile(request_dict['profile'].read())
            except:
                try:
                    profile = ContentFile(request_dict['profile'])
                except:
                    profile = ContentFile(str(request_dict['profile']))

            if not created:
                etag.check_preconditions(request_dict, p, required=True)
                p.profile.delete()
            self.save_profile(p, created, profile, request_dict)
        else:
            if not created:
                etag.check_preconditions(request_dict, p, required=True)
            the_profile = request_dict['profile']
            p.json_profile = ast.literal_eval(the_profile)
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(the_profile)

            if 'headers' in request_dict and (
                    'updated' in request_dict['headers']
                    and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            p.save()
Beispiel #5
0
    def post_profile(self, request_dict):
        post_profile = request_dict['profile']

        profile_id = request_dict['params']['profileId']

        p, created = AgentProfile.objects.get_or_create(profileId=profile_id,agent=self.Agent)
        
        if created:
            p.json_profile = post_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(post_profile)

            if 'headers' in request_dict and ('updated' in request_dict['headers'] and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
        else:
            etag.check_preconditions(request_dict,p, required=True)
            orig_prof = ast.literal_eval(p.json_profile)
            post_profile = ast.literal_eval(post_profile)
            if not isinstance(post_profile, dict):
                raise ParamError("The document was not able to be parsed into a JSON object.")
            else:
                merged = json.dumps(dict(orig_prof.items() + post_profile.items()))
            p.json_profile = merged
            p.etag = etag.create_tag(merged)
            p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)

        p.save()
    def put(self):
        agent = self.__get_agent()
        if self.registration:
            p,created = models.ActivityState.objects.get_or_create(state_id=self.stateId,agent=agent,activity_id=self.activity_id,registration_id=self.registration)
        else:
            p,created = models.ActivityState.objects.get_or_create(state_id=self.stateId,agent=agent,activity_id=self.activity_id)
        
        if "application/json" not in self.content_type:
            try:
                state = ContentFile(self.state.read())
            except:
                try:
                    state = ContentFile(self.state)
                except:
                    state = ContentFile(str(self.state))

            if not created:
                etag.check_preconditions(self.req_dict,p)
                p.state.delete() # remove old state file
            p.content_type = self.content_type
            self.save_state(p, created, state)
        else:
            if not created:
                etag.check_preconditions(self.req_dict, p)
            the_state = self.state
            p.json_state = the_state
            p.content_type = self.content_type
            p.etag = etag.create_tag(the_state)
            if self.updated:
                p.updated = self.updated
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
            p.save()
Beispiel #7
0
    def post_profile(self, request_dict):
        post_profile = request_dict['profile']
        profile_id = request_dict['params']['profileId']

        p, created = AgentProfile.objects.get_or_create(profileId=profile_id,
                                                        agent=self.Agent)

        if created:
            p.json_profile = post_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(post_profile)

            if 'headers' in request_dict and (
                    'updated' in request_dict['headers']
                    and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
        else:
            etag.check_preconditions(request_dict, p, required=True)
            orig_prof = json.loads(p.json_profile)
            post_profile = json.loads(post_profile)
            if not isinstance(post_profile, dict):
                raise ParamError(
                    "The document was not able to be parsed into a JSON object."
                )
            else:
                merged = json.dumps(
                    dict(orig_prof.items() + post_profile.items()))
            p.json_profile = merged
            p.etag = etag.create_tag(merged)
            p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)

        p.save()
    def post_profile(self, request_dict):
        post_profile = request_dict['profile']
        
        profile_id = request_dict['params']['profileId']

        # get / create  profile
        p, created = models.ActivityProfile.objects.get_or_create(activityId=request_dict['params']['activityId'],  profileId=request_dict['params']['profileId'])
        
        if created:
            p.json_profile = post_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(post_profile)
            
            #Set updated
            if 'headers' in request_dict and ('updated' in request_dict['headers'] and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
        else:
            etag.check_preconditions(request_dict,p, required=True)
            orig_prof = json.loads(p.json_profile)
            post_profile = json.loads(post_profile)
            if not isinstance(post_profile, dict):
                raise ParamError("The document was not able to be parsed into a JSON object.")
            else:
                # json.dumps changes the format of the string rep of the dict
                merged = json.dumps(dict(orig_prof.items() + post_profile.items()))
            p.json_profile = merged
            p.etag = etag.create_tag(merged)
            p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)

        p.save()
Beispiel #9
0
    def put(self):
        agent = self.__get_agent(create=True)
        try:
            state = ContentFile(self.state.read())
        except:
            try:
                state = ContentFile(self.state)
            except:
                state = ContentFile(str(self.state))

        if self.registrationId:
            p, created = models.activity_state.objects.get_or_create(
                state_id=self.stateId,
                agent=agent,
                activity=self.activity,
                registration_id=self.registrationId)
        else:
            p, created = models.activity_state.objects.get_or_create(
                state_id=self.stateId, agent=agent, activity=self.activity)
        if not created:
            etag.check_preconditions(self.req_dict, p)
            p.state.delete()  # remove old state file
        p.content_type = self.content_type
        p.etag = etag.create_tag(state.read())
        if self.updated:
            p.updated = self.updated
        state.seek(0)
        if created:
            p.save()

        fn = "%s_%s_%s" % (p.agent_id, p.activity_id,
                           self.req_dict.get('filename', p.id))
        p.state.save(fn, state)
Beispiel #10
0
    def put_profile(self, request_dict):
        profile_id = request_dict['params']['profileId']
        if not uri.validate_uri(profile_id):
            err_msg = 'Profile ID %s is not a valid URI' % profile_id
            raise ParamError(err_msg)

        p,created = AgentProfile.objects.get_or_create(profileId=profile_id,agent=self.Agent)

        if request_dict['headers']['CONTENT_TYPE'] != "application/json":
            try:
                profile = ContentFile(request_dict['profile'].read())
            except:
                try:
                    profile = ContentFile(request_dict['profile'])
                except:
                    profile = ContentFile(str(request_dict['profile']))
        

            if not created:
                etag.check_preconditions(request_dict,p, required=True)
                p.profile.delete()
            self.save_profile(p, created, profile, request_dict)
        else:
            if not created:
                etag.check_preconditions(request_dict, p, required=True)
            the_profile = request_dict['profile']
            p.json_profile = the_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(the_profile)

            if 'headers' in request_dict and ('updated' in request_dict['headers'] and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            p.save()
    def put_profile(self, request_dict):
        #Parse out profile from request_dict
        try:
            profile = ContentFile(request_dict['profile'].read())
        except:
            try:
                profile = ContentFile(request_dict['profile'])
            except:
                profile = ContentFile(str(request_dict['profile']))

        #Check if activity exists
        try:
            # Always want global version
            activity = models.activity.objects.get(activity_id=request_dict['activityId'],
                global_representation=True)
        except models.activity.DoesNotExist:
            err_msg = 'There is no activity associated with the id: %s' % request_dict['activityId']
            log_message(self.log_dict, err_msg, __name__, self.put_profile.__name__, True)
            update_parent_log_status(self.log_dict, 404)
            raise IDNotFoundError(err_msg)

        user = get_user_from_auth(request_dict.get('auth', None))
        #Get the profile, or if not already created, create one
        p,created = models.activity_profile.objects.get_or_create(profileId=request_dict['profileId'],activity=activity, user=user)
        
        if created:
            log_message(self.log_dict, "Created Activity Profile", __name__, self.put_profile.__name__)
        else:
            #If it already exists delete it
            etag.check_preconditions(request_dict,p, required=True)
            p.profile.delete()
            log_message(self.log_dict, "Retrieved Activity Profile", __name__, self.put_profile.__name__)
        
        #Save profile content type based on incoming content type header and create etag
        p.content_type = request_dict['CONTENT_TYPE']
        p.etag = etag.create_tag(profile.read())
        
        #Set updated
        if request_dict['updated']:
            p.updated = request_dict['updated']
        
        #Go to beginning of file
        profile.seek(0)
        
        #If it didn't exist, save it
        if created:
            p.save()

        #Set filename with the activityID and profileID and save
        fn = "%s_%s" % (p.activity_id,request_dict.get('filename', p.id))
        p.profile.save(fn, profile)

        log_message(self.log_dict, "Saved Activity Profile", __name__, self.put_profile.__name__)
Beispiel #12
0
    def put_profile(self, request_dict):
        #Parse out profile from request_dict
        try:
            profile = ContentFile(request_dict['profile'].read())
        except:
            try:
                profile = ContentFile(request_dict['profile'])
            except:
                profile = ContentFile(str(request_dict['profile']))

        #Check if activity exists
        try:
            activity = models.activity.objects.get(
                activity_id=request_dict['activityId'])
        except models.activity.DoesNotExist:
            raise IDNotFoundError(
                'There is no activity associated with the id: %s' %
                request_dict['activityId'])

        #Get the profile, or if not already created, create one
        p, created = models.activity_profile.objects.get_or_create(
            profileId=request_dict['profileId'], activity=activity)

        #If it already exists delete it
        if not created:
            etag.check_preconditions(request_dict, p, required=True)
            p.profile.delete()

        #Save profile content type based on incoming content type header and create etag
        p.content_type = request_dict['CONTENT_TYPE']
        p.etag = etag.create_tag(profile.read())

        #Set updated
        if request_dict['updated']:
            p.updated = request_dict['updated']

        #Go to beginning of file
        profile.seek(0)

        #If it didn't exist, save it
        if created:
            p.save()

        #Set filename with the activityID and profileID and save
        fn = "%s_%s" % (p.activity_id, request_dict.get('filename', p.id))
        p.profile.save(fn, profile)
Beispiel #13
0
    def put_profile(self, request_dict):
        #Parse out profile from request_dict
        profile_id = request_dict['params']['profileId']

        #Get the profile, or if not already created, create one
        p, created = models.ActivityProfile.objects.get_or_create(
            profileId=profile_id,
            activityId=request_dict['params']['activityId'])

        if "application/json" not in request_dict['headers']['CONTENT_TYPE']:
            try:
                profile = ContentFile(request_dict['profile'].read())
            except:
                try:
                    profile = ContentFile(request_dict['profile'])
                except:
                    profile = ContentFile(str(request_dict['profile']))

            if not created:
                #If it already exists delete it
                etag.check_preconditions(request_dict, p, required=True)
                if p.profile:
                    try:
                        p.profile.delete()
                    except OSError:
                        # probably was json before
                        p.json_profile = {}

            self.save_profile(p, created, profile, request_dict)
        else:
            if not created:
                etag.check_preconditions(request_dict, p, required=True)
            the_profile = request_dict['profile']
            p.json_profile = the_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(the_profile)

            #Set updated
            if 'headers' in request_dict and (
                    'updated' in request_dict['headers']
                    and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
            p.save()
Beispiel #14
0
    def put_profile(self, request_dict):
        try:
            profile = ContentFile(request_dict['profile'].read())
        except:
            try:
                profile = ContentFile(request_dict['profile'])
            except:
                profile = ContentFile(str(request_dict['profile']))
        
        profile_id = request_dict['params']['profileId']
        if not uri.validate_uri(profile_id):
            err_msg = 'Profile ID %s is not a valid URI' % profile_id
            raise ParamError(err_msg)

        p,created = AgentProfile.objects.get_or_create(profileId=profile_id,agent=self.Agent)
        if not created:
            etag.check_preconditions(request_dict,p, required=True)
            p.profile.delete()
        self.save_profile(p, created, profile, request_dict)
Beispiel #15
0
    def put(self):
        agent = self.__get_agent(create=True)
        try:
            state = ContentFile(self.state.read())
        except:
            try:
                state = ContentFile(self.state)
            except:
                state = ContentFile(str(self.state))

        if self.registrationId:
            p,created = models.ActivityState.objects.get_or_create(state_id=self.stateId,agent=agent,activity_id=self.activity_id,registration_id=self.registrationId)
        else:
            p,created = models.ActivityState.objects.get_or_create(state_id=self.stateId,agent=agent,activity_id=self.activity_id)
        
        if not created:
            etag.check_preconditions(self.req_dict,p)
            p.state.delete() # remove old state file
        self.save_state(p, created, state)
Beispiel #16
0
    def put_profile(self, request_dict):
        #Parse out profile from request_dict
        try:
            profile = ContentFile(request_dict['profile'].read())
        except:
            try:
                profile = ContentFile(request_dict['profile'])
            except:
                profile = ContentFile(str(request_dict['profile']))

        #Check if activity exists
        try:
            activity = models.activity.objects.get(activity_id=request_dict['activityId'])
        except models.activity.DoesNotExist:
            raise IDNotFoundError('There is no activity associated with the id: %s' % request_dict['activityId'])

        #Get the profile, or if not already created, create one
        p,created = models.activity_profile.objects.get_or_create(profileId=request_dict['profileId'],activity=activity)
        
        #If it already exists delete it
        if not created:
            etag.check_preconditions(request_dict,p, required=True)
            p.profile.delete()
        
        #Save profile content type based on incoming content type header and create etag
        p.content_type = request_dict['CONTENT_TYPE']
        p.etag = etag.create_tag(profile.read())
        
        #Set updated
        if request_dict['updated']:
            p.updated = request_dict['updated']
        
        #Go to beginning of file
        profile.seek(0)
        
        #If it didn't exist, save it
        if created:
            p.save()

        #Set filename with the activityID and profileID and save
        fn = "%s_%s" % (p.activity_id,request_dict.get('filename', p.id))
        p.profile.save(fn, profile)
    def put_profile(self, request_dict):
        # Parse out profile from request_dict
        profile_id = request_dict["params"]["profileId"]
        if not uri.validate_uri(profile_id):
            err_msg = "Profile ID %s is not a valid URI" % profile_id
            raise ParamError(err_msg)

        # Get the profile, or if not already created, create one
        p, created = models.ActivityProfile.objects.get_or_create(
            profileId=profile_id, activityId=request_dict["params"]["activityId"]
        )

        if request_dict["headers"]["CONTENT_TYPE"] != "application/json":
            try:
                profile = ContentFile(request_dict["profile"].read())
            except:
                try:
                    profile = ContentFile(request_dict["profile"])
                except:
                    profile = ContentFile(str(request_dict["profile"]))

            if not created:
                # If it already exists delete it
                etag.check_preconditions(request_dict, p, required=True)
                if p.profile:
                    p.profile.delete()

            self.save_profile(p, created, profile, request_dict)
        else:
            if not created:
                etag.check_preconditions(request_dict, p, required=True)
            the_profile = request_dict["profile"]
            p.json_profile = the_profile
            p.content_type = request_dict["headers"]["CONTENT_TYPE"]
            p.etag = etag.create_tag(the_profile)

            # Set updated
            if "headers" in request_dict and (
                "updated" in request_dict["headers"] and request_dict["headers"]["updated"]
            ):
                p.updated = request_dict["headers"]["updated"]
            p.save()
Beispiel #18
0
    def put_profile(self, request_dict):
        #Parse out profile from request_dict
        profile_id = request_dict['params']['profileId']
        if not uri.validate_uri(profile_id):
            err_msg = 'Profile ID %s is not a valid URI' % profile_id
            raise ParamError(err_msg)

        #Get the profile, or if not already created, create one
        p, created = models.ActivityProfile.objects.get_or_create(
            profileId=profile_id,
            activityId=request_dict['params']['activityId'])

        if request_dict['headers']['CONTENT_TYPE'] != "application/json":
            try:
                profile = ContentFile(request_dict['profile'].read())
            except:
                try:
                    profile = ContentFile(request_dict['profile'])
                except:
                    profile = ContentFile(str(request_dict['profile']))

            if not created:
                #If it already exists delete it
                etag.check_preconditions(request_dict, p, required=True)
                if p.profile:
                    p.profile.delete()

            self.save_profile(p, created, profile, request_dict)
        else:
            if not created:
                etag.check_preconditions(request_dict, p, required=True)
            the_profile = request_dict['profile']
            p.json_profile = the_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(the_profile)

            #Set updated
            if 'headers' in request_dict and (
                    'updated' in request_dict['headers']
                    and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            p.save()
    def put_profile(self, request_dict):
        #Parse out profile from request_dict
        profile_id = request_dict['params']['profileId']

        #Get the profile, or if not already created, create one
        p,created = models.ActivityProfile.objects.get_or_create(profileId=profile_id,activityId=request_dict['params']['activityId'])
        
        if "application/json" not in request_dict['headers']['CONTENT_TYPE']:
            try:
                profile = ContentFile(request_dict['profile'].read())
            except:
                try:
                    profile = ContentFile(request_dict['profile'])
                except:
                    profile = ContentFile(str(request_dict['profile']))

            if not created:
                #If it already exists delete it
                etag.check_preconditions(request_dict,p, required=True)
                if p.profile:
                    try:
                        p.profile.delete()
                    except OSError:
                        # probably was json before
                        p.json_profile = {}
            
            self.save_profile(p, created, profile, request_dict)
        else:
            if not created:
                etag.check_preconditions(request_dict, p, required=True)
            the_profile = request_dict['profile']
            p.json_profile = the_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(the_profile)
            
            #Set updated
            if 'headers' in request_dict and ('updated' in request_dict['headers'] and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
            p.save()
    def put(self):
        agent = self.__get_agent()
        if self.registration:
            p, created = models.ActivityState.objects.get_or_create(
                state_id=self.stateId,
                agent=agent,
                activity_id=self.activity_id,
                registration_id=self.registration)
        else:
            p, created = models.ActivityState.objects.get_or_create(
                state_id=self.stateId,
                agent=agent,
                activity_id=self.activity_id)

        if "application/json" not in self.content_type:
            try:
                state = ContentFile(self.state.read())
            except:
                try:
                    state = ContentFile(self.state)
                except:
                    state = ContentFile(str(self.state))

            if not created:
                etag.check_preconditions(self.req_dict, p)
                p.state.delete()  # remove old state file
            p.content_type = self.content_type
            self.save_state(p, created, state)
        else:
            if not created:
                etag.check_preconditions(self.req_dict, p)
            the_state = self.state
            p.json_state = the_state
            p.content_type = self.content_type
            p.etag = etag.create_tag(the_state)
            if self.updated:
                p.updated = self.updated
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
            p.save()
Beispiel #21
0
    def put(self):
        agent = self.__get_agent(create=True)
        if self.registrationId:
            p, created = models.ActivityState.objects.get_or_create(
                state_id=self.stateId,
                agent=agent,
                activity_id=self.activity_id,
                registration_id=self.registrationId)
        else:
            p, created = models.ActivityState.objects.get_or_create(
                state_id=self.stateId,
                agent=agent,
                activity_id=self.activity_id)

        if self.content_type != "application/json":
            try:
                state = ContentFile(self.state.read())
            except:
                try:
                    state = ContentFile(self.state)
                except:
                    state = ContentFile(str(self.state))

            if not created:
                etag.check_preconditions(self.req_dict, p)
                p.state.delete()  # remove old state file
            self.save_state(p, created, state)
        else:
            if not created:
                etag.check_preconditions(self.req_dict, p)
            the_state = ast.literal_eval(
                self.state) if type(self.state) != dict else self.state

            p.json_state = the_state
            p.content_type = self.content_type
            p.etag = etag.create_tag(json.dumps(the_state))
            if self.updated:
                p.updated = self.updated
            p.save()
Beispiel #22
0
    def put_profile(self, request_dict):
        try:
            profile = ContentFile(request_dict['profile'].read())
        except:
            try:
                profile = ContentFile(request_dict['profile'])
            except:
                profile = ContentFile(str(request_dict['profile']))

        p,created = agent_profile.objects.get_or_create(profileId=request_dict['profileId'],agent=self.agent)
        if not created:
            etag.check_preconditions(request_dict,p, required=True)
            p.profile.delete()
        p.content_type = request_dict['CONTENT_TYPE']
        p.etag = etag.create_tag(profile.read())
        if request_dict['updated']:
            p.updated = request_dict['updated']
        profile.seek(0)
        if created:
            p.save()

        fn = "%s_%s" % (p.agent_id,request_dict.get('filename', p.id))
        p.profile.save(fn, profile)
Beispiel #23
0
    def put_profile(self, request_dict):
        profile_id = request_dict['params']['profileId']
        p, created = AgentProfile.objects.get_or_create(profileId=profile_id,
                                                        agent=self.Agent)

        if "application/json" not in request_dict['headers']['CONTENT_TYPE']:
            try:
                profile = ContentFile(request_dict['profile'].read())
            except:
                try:
                    profile = ContentFile(request_dict['profile'])
                except:
                    profile = ContentFile(str(request_dict['profile']))

            if not created:
                etag.check_preconditions(request_dict, p, required=True)
                try:
                    p.profile.delete()
                except OSError:
                    # p was probably json before.. gotta clear that field
                    p.json_profile = {}
            self.save_profile(p, created, profile, request_dict)
        else:
            if not created:
                etag.check_preconditions(request_dict, p, required=True)
            the_profile = request_dict['profile']
            p.json_profile = the_profile
            p.content_type = request_dict['headers']['CONTENT_TYPE']
            p.etag = etag.create_tag(the_profile)

            if 'headers' in request_dict and (
                    'updated' in request_dict['headers']
                    and request_dict['headers']['updated']):
                p.updated = request_dict['headers']['updated']
            else:
                p.updated = datetime.datetime.utcnow().replace(tzinfo=utc)
            p.save()
Beispiel #24
0
    def put(self):
        agent = self.__get_agent(create=True)
        try:
            state = ContentFile(self.state.read())
        except:
            try:
                state = ContentFile(self.state)
            except:
                state = ContentFile(str(self.state))

        if self.registrationId:
            p,created = models.activity_state.objects.get_or_create(state_id=self.stateId,agent=agent,activity=self.activity,registration_id=self.registrationId, user=self.user)
        else:
            p,created = models.activity_state.objects.get_or_create(state_id=self.stateId,agent=agent,activity=self.activity, user=self.user)
        
        if created:
            log_message(self.log_dict, "Created Activity State", __name__, self.put.__name__)
        elif not created:
            etag.check_preconditions(self.req_dict,p)
            p.state.delete() # remove old state file
            log_message(self.log_dict, "Retrieved Activity State", __name__, self.put.__name__)

        # if not created:
        #     etag.check_preconditions(self.req_dict,p)
        #     p.state.delete() # remove old state file
        p.content_type = self.content_type
        p.etag = etag.create_tag(state.read())
        if self.updated:
            p.updated = self.updated
        state.seek(0)
        if created:
            p.save()

        fn = "%s_%s_%s" % (p.agent_id,p.activity_id, self.req_dict.get('filename', p.id))
        p.state.save(fn, state)

        log_message(self.log_dict, "Saved Activity State", __name__, self.put.__name__)
Beispiel #25
0
    def put_profile(self, request_dict):
        try:
            profile = ContentFile(request_dict['profile'].read())
        except:
            try:
                profile = ContentFile(request_dict['profile'])
            except:
                profile = ContentFile(str(request_dict['profile']))

        p, created = agent_profile.objects.get_or_create(
            profileId=request_dict['profileId'], agent=self.agent)
        if not created:
            etag.check_preconditions(request_dict, p, required=True)
            p.profile.delete()
        p.content_type = request_dict['CONTENT_TYPE']
        p.etag = etag.create_tag(profile.read())
        if request_dict['updated']:
            p.updated = request_dict['updated']
        profile.seek(0)
        if created:
            p.save()

        fn = "%s_%s" % (p.agent_id, request_dict.get('filename', p.id))
        p.profile.save(fn, profile)
    def put_profile(self, request_dict):
        #Parse out profile from request_dict
        try:
            profile = ContentFile(request_dict['profile'].read())
        except:
            try:
                profile = ContentFile(request_dict['profile'])
            except:
                profile = ContentFile(str(request_dict['profile']))

        profile_id = request_dict['params']['profileId']
        if not uri.validate_uri(profile_id):
            err_msg = 'Profile ID %s is not a valid URI' % profile_id
            raise ParamError(err_msg)

        #Get the profile, or if not already created, create one
        p,created = models.ActivityProfile.objects.get_or_create(profileId=request_dict['params']['profileId'],activityId=request_dict['params']['activityId'])
        
        if not created:
            #If it already exists delete it
            etag.check_preconditions(request_dict,p, required=True)
            p.profile.delete()
        
        self.save_profile(p, created, profile, request_dict)