38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import requests
|
|
from .djangoapi import django_crud_api
|
|
class fet2020postapi(django_crud_api):
|
|
def __init__(self,endpoint="http://localhost:8106/api/posts/"):
|
|
super().__init__(endpoint=endpoint)
|
|
|
|
def read_post(self, slug=None,legacy_id=None):
|
|
return self.find_one({'slug':slug,'legacy_id':legacy_id})
|
|
|
|
def update_or_write_by_legacy_id(self,d):
|
|
if not 'legacy_id' in d:
|
|
raise AttributeError('legacy_id muss angegeben werden')
|
|
p=self.read_post(legacy_id=d['legacy_id'])
|
|
if p is None:
|
|
p=self.create(d)
|
|
else:
|
|
p=self.update(p['slug'], d)
|
|
return p
|
|
def push(self,d):
|
|
return self.update_or_write_by_legacy_id(d)
|
|
|
|
class fet2020memberapi(django_crud_api):
|
|
def __init__(self, endpoint= "http://localhost:8103/api/members/"):
|
|
super().__init__(endpoint=endpoint)
|
|
|
|
def read_post(self, slug=None,legacy_id=None):
|
|
return self.find_one({'nickname':slug,'legacy_id':legacy_id})
|
|
|
|
def update_or_write_by_legacy_id(self,d):
|
|
if not 'legacy_id' in d:
|
|
raise AttributeError('legacy_id muss angegeben werden')
|
|
p=self.read_post(legacy_id=d['legacy_id'])
|
|
if p is None:
|
|
p=self.create(d)
|
|
else:
|
|
p=self.update(p['slug'], d)
|
|
return p
|
|
|