doing the R of CRUD for posts

p2p
quadrismegistus 4 years ago
parent e1a10687a0
commit 4a0db2357b

@ -6,3 +6,80 @@ got back from post: 53
content: eeee
img_src: []
got back from post: 54
my post id is: None
my post id is: None
view
view
my post id is: None
my post id is: None
my post id is: None
my post id is: 10
my post id is: 10
my post id is: None
my post id is: None
my post id is: None
my post id is: None
content: eeee
img_src: []
my post id is: None
content: eeee
img_src: []
got back from post: 61
my post id is: 61
content: eee
img_src: []
got back from post: 62
my post id is: 62
content: eeeee
img_src: []
got back from post: 63
content: eeee
img_src: []
got back from post: 64
content: ee
img_src: []
got back from post: 65
<Screen name='view'>
content: eee
img_src: []
got back from post: 66
<__main__.MainApp object at 0x7f27f52db868>
content: ee
img_src: []
got back from post: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
content: ee
img_src: []
got back from post: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
content: ee
img_src: []
got back from post: 76
content: eeeeee
img_src: []
got back from post: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
content: eeeeee
img_src: []
got back from post: 89
content: eeeeeeeee
img_src: []
got back from post: 99
content: eeeee
img_src: []
got back from post: 106
content: eeeeeeee
img_src: []
got back from post: 110
content: eee
img_src: []
got back from post: 120

@ -88,6 +88,9 @@ MyLayout:
AddPostScreen:
id: add_post_screen
ViewPostScreen:
id: view_post_screen
MessagesScreen:
NotificationsScreen:

@ -36,9 +36,14 @@ def log(x):
class MyLayout(MDBoxLayout):
scr_mngr = ObjectProperty(None)
post_id = ObjectProperty()
def change_screen(self, screen, *args):
self.scr_mngr.current = screen
def view_post(self,post_id):
self.post_id=post_id
self.change_screen('view')
class MyBoxLayout(MDBoxLayout): pass
@ -71,7 +76,7 @@ def get_tor_python_session():
with tor_requests.get_session() as s:
return s
from kivymd.font_definitions import theme_font_styles
class MainApp(MDApp):
title = 'Komrade'
#api = 'http://localhost:5555/api'
@ -183,9 +188,15 @@ class MainApp(MDApp):
jsond={'img_src':server_filename, 'content':content}
r = sess.post(url_post, json=jsond)
log('got back from post: ' + r.text)
self.root.ids.add_post_screen.ids.post_status.text='Post created'
post_id = r.text
if post_id.isdigit():
self.root.ids.add_post_screen.ids.post_status.text='Post created'
self.root.view_post(int(post_id))
def get_post(self,post_id):
with self.get_session() as sess:
r = sess.get(self.api+'/post/'+str(post_id))
print(r.text)
if __name__ == '__main__':

@ -1,5 +1,6 @@
#:import AddPostScreen screens.post.post.AddPostScreen
#:import ViewPostScreen screens.post.post.ViewPostScreen
#:import PostCard screens.feed.feed.PostCard
<AddPostScreen>:
@ -41,6 +42,7 @@
FileChoose:
id: file_chooser_button
text: "upload"
#text: app.root.ids.scr_mngr.etc
on_release: self.choose()
#app.register(username.text, password.text)
theme_text_color: "Custom"
@ -60,10 +62,10 @@
MDLabel:
id: post_status
text:""
text:"" #self.add_post_screen.post_id
theme_text_color: 'Error'
pos_hint:{'center_x':.5}
<ViewPostScreen>:
name: 'view'
name: 'view'

@ -1,8 +1,10 @@
from screens.base import ProtectedScreen
from plyer import filechooser
from kivymd.uix.button import MDRectangleFlatButton, MDIconButton
from kivy.properties import ListProperty
from kivy.properties import ListProperty,ObjectProperty
from kivy.app import App
from main import log
from screens.feed.feed import *
@ -35,6 +37,23 @@ class FileChoose(MDRectangleFlatButton):
#App.get_running_app().root.ids.result.text = str(self.selection)
class AddPostScreen(ProtectedScreen): pass
class ViewPostScreen(ProtectedScreen): pass
class AddPostScreen(ProtectedScreen):
post_id = ObjectProperty()
pass
class ViewPostScreen(ProtectedScreen):
post_id = ObjectProperty()
def on_enter(self):
ln='woops'
post = PostCard(
author='Marx Zuckerberg',
title='',
img_src='avatar.jpg',
content=ln.strip())
print(post)
self.add_widget(post)
pass

@ -3,6 +3,10 @@ from py2neo import *
from py2neo.ogm import *
G = Graph(password='drive your plow over the bones of the dead')
Nodes = NodeMatcher(G)
Edges = RelationshipMatcher(G)
class MyGraphObject(GraphObject):
@property

@ -118,25 +118,28 @@ def upload_file():
@app.route('/api/post',methods=['POST'])
def create_post():
data=request.json
# print(dir(request))
#files = request.files
#print(request.json)
print(data)
#print(request.files)
post = Post()
post.content = data.get('content','')
post.img_src = data.get('img_src','')
G.push(post)
#print(dir(post.__ogm__.node))
post_id=str(post.__ogm__.node.identity)
@app.route('/api/post/<int:post_id>',methods=['GET'])
def post(post_id=None):
if request.method == 'POST':
data=request.json
print(data)
post = Post()
post.content = data.get('content','')
post.img_src = data.get('img_src','')
G.push(post)
post_id=str(post.__ogm__.node.identity)
print('created new post!',post_id)
return post_id,status.HTTP_200_OK
print('got post id!',post_id)
posts = list(Post.match(G,post_id))
if not posts:
return str(post_id),status.HTTP_204_NO_CONTENT
# print('RECEIVED:',files['file'])
return post_id,status.HTTP_200_OK
post=posts[0]
print(post.data)
return str(post_id),status.HTTP_200_OK
### READ

Loading…
Cancel
Save