def _send_follow(cls, request_data): """ """ related_docs = [] api = Client.instance().api result_dict = api.traversal.post(data=request_data) results = result_dict['result']['visited'] vertices = results['vertices'] vertices.remove(vertices[0]) for vertice in vertices: collection_name = vertice['_id'].split('/')[0] doc = Document( id=vertice['_id'], key=vertice['_key'], collection=collection_name, api=api, ) del vertice['_id'] del vertice['_key'] del vertice['_rev'] doc.data = vertice related_docs.append(doc) return related_docs
def test_document_access_values_by_attribute_getter(self): doc = Document(id='', key='', collection='', api=client.api) # set this to true so it won't make requests to nothing doc.is_loaded = True doc_attr_value = 'foo_bar' doc.set(key='test', value=doc_attr_value) self.assertEqual(doc.test, doc_attr_value)
def create_document_from_result_dict(result_dict, api): collection_name = result_dict['_id'].split('/')[0] doc = Document( id=result_dict['_id'], key=result_dict['_key'], collection=collection_name, api=api, ) doc.is_loaded = True del result_dict['_id'] del result_dict['_key'] del result_dict['_rev'] for result_key in result_dict: result_value = result_dict[result_key] doc.set(key=result_key, value=result_value) return doc
def follow(cls, start_vertex, edge_collection, direction): """ """ related_docs = [] request_data = { 'startVertex': start_vertex, 'edgeCollection': edge_collection, 'direction': direction, } api = Client.instance().api result_dict = api.traversal.post(data=request_data) results = result_dict['result']['visited'] vertices = results['vertices'] vertices.remove(vertices[0]) for vertice in vertices: collection_name = vertice['_id'].split('/')[0] doc = Document( id=vertice['_id'], key=vertice['_key'], collection=collection_name, api=api, ) del vertice['_id'] del vertice['_key'] del vertice['_rev'] doc.data = vertice related_docs.append(doc) return related_docs
def get(self, request, format='json'): """ API View that receives a GET request. and will return a single random unused external id. """ obj = Collection.get_loaded_collection(name='AwsExternalIds') document = SimpleQuery.get_by_example(obj, example_data={ 'used': False, }, allow_multiple=True) if document: external_id = Document(random.choice(document), '', 'AwsExternalIds', client.api).retrieve()['external_id'] else: external_id = "Not found" return Response(external_id, status=status.HTTP_201_CREATED)
def create(self, validated_data): user = User.objects.create_user( username=validated_data['email'], password=validated_data['password'], email=validated_data['email'], first_name=validated_data['first_name'], last_name=validated_data['last_name'] if 'last_name' in validated_data else '', is_active=False ) try: # Saving data into UserProfile collection UserProfiles.init() obj = UserProfiles() obj.user = int(user.id) obj.country = str(validated_data['country']) obj.state = str(validated_data['state']) obj.phone_number = str(validated_data['phone_number']) obj.role = str(get_default_role().id) obj.save() # Saving company into collection Companies.init() obj = Companies() obj.name = str(validated_data['company']) obj.save() # Assign User to Company collection = Collection.get_loaded_collection(name='UserCompanies') doc = collection.create_document() doc.user = int(user.id) doc.company = str(obj.id) doc.active = True doc.created_on = str(datetime.datetime.now()) doc.save() except Exception as e: # Removing data saved into document if any error occured collection = Collection.get_loaded_collection(name='UserProfiles') obj = SimpleQuery.get_by_example(collection, example_data={ 'user': int(user.id), }) if obj: Document(obj.id, '', 'UserProfiles', client.api).delete() collection = Collection.get_loaded_collection(name='Companies') obj = SimpleQuery.get_by_example(collection, example_data={ 'name': str(validated_data['company']), }) if obj: Document(obj.id, '', 'Companies', client.api).delete() collection = Collection.get_loaded_collection(name='UserCompanies') obj = SimpleQuery.get_by_example(collection, example_data={ 'user': int(user.id), 'company': str(obj.id) }) if obj: Document(obj.id, '', 'UserCompanies', client.api).delete() raise Exception('Error Occured '+str(e)) return user