2
0
mirror of https://github.com/ComradCollective/Comrad synced 2024-11-11 13:10:45 +00:00

doing the R of CRUD for posts

This commit is contained in:
quadrismegistus 2020-08-10 21:38:00 +01:00
parent e1a10687a0
commit 4a0db2357b
7 changed files with 143 additions and 24 deletions

View File

@ -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

View File

@ -89,5 +89,8 @@ MyLayout:
AddPostScreen:
id: add_post_screen
ViewPostScreen:
id: view_post_screen
MessagesScreen:
NotificationsScreen:

View File

@ -36,10 +36,15 @@ 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
class MyLabel(MDLabel): 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)
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))
self.root.ids.add_post_screen.ids.post_status.text='Post created'
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__':

View File

@ -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,7 +62,7 @@
MDLabel:
id: post_status
text:""
text:"" #self.add_post_screen.post_id
theme_text_color: 'Error'
pos_hint:{'center_x':.5}

View File

@ -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 AddPostScreen(ProtectedScreen):
post_id = ObjectProperty()
pass
class ViewPostScreen(ProtectedScreen): 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

View File

@ -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

View File

@ -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)
@app.route('/api/post/<int:post_id>',methods=['GET'])
def post(post_id=None):
post = Post()
post.content = data.get('content','')
post.img_src = data.get('img_src','')
G.push(post)
#print(dir(post.__ogm__.node))
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
post_id=str(post.__ogm__.node.identity)
# print('RECEIVED:',files['file'])
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
post=posts[0]
print(post.data)
return str(post_id),status.HTTP_200_OK
### READ