Skip to content

Commit df8d6f9

Browse files
Rough Spec
The code is linked together, but isn't doing jack right now. I suspect it has to do with the way that things are getting passed into the json. Will need to set up debugging
1 parent 0dd41b0 commit df8d6f9

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/app/CreationModificationDelegate.py

Whitespace-only changes.

lib/app/FileDelegate.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from recipe import Recipe
2+
import hashlib
3+
import os
4+
5+
UPLOAD_FOLDER = os.getcwd() + "pdfs/"
6+
7+
class CreationModificationDelegate:
8+
9+
10+
def addNew(self,properties,file):
11+
hasher = hashlib.md5()
12+
buf=file.read()
13+
hasher.update(buf)
14+
new_name=hasher.hexdigest()+".pdf"
15+
file.save(os.path.join(UPLOAD_FOLDER,new_name))
16+
recipe=Recipe(title=properties["title"],filename=new_name,tags=properties["tags"],ingredients=properties["ingredients"])
17+
recipe.save()
18+
return recipe.toJson()
19+
20+
21+
def remove(self,properties):
22+
name=properties["filename"]
23+
recipe=Recipe.query.fileIs(filename=name).first()
24+
recipe.remove()
25+
return recipe.toJson()
26+
27+
def edit(self,properties,file):
28+
if (file is not None and file.filename != ''):
29+
self.remove(properties)
30+
return self.addNew(properties,file)
31+
else:
32+
recipe = self.editMetaData(properties)
33+
return recipe.toJson()
34+
35+
def editMetaData(self, properties):
36+
recipe = Recipe.query.fileIs(properties["filename"]).first()
37+
recipe.ingredients = properties["ingredients"]
38+
recipe.tags = properties["tags"]
39+
recipe.title = properties["title"]
40+
recipe.save()
41+
return recipe

0 commit comments

Comments
 (0)