def test_CreateData(self): Project.drop_collection() p = Project("unittest", "projet de test unitaire") p.save() print(p.id) #t1 = Task("writeData", "ecriture des données") #t2 = Task("readData", "ecriture des données") #t1.save() #t2.save() p = Project.objects(name='unittest').first() #p.tasks.append(Task("writeData", "ecriture des données")) #p.tasks = Task(name="writeData", description="ecriture des données") #p.tasks.append() p.save()
def addProject(): projectId = request.args.get('projectId') projectResult = None pForm = ProjectForm() if request.method == 'POST': print('****'+pForm.pId.data+'******') if pForm.pId.data is not None and pForm.pId.data != '': #Update case projectResult = Project.objects(id=pForm.pId.data).first() #you need to update the objet and update to escape some cache pbs strange ... projectResult.name = pForm.name.data projectResult.description = pForm.description.data projectResult.tlosEstimate = pForm.tlosEstimate.data projectResult.update(description=pForm.description.data, tlosEstimate=pForm.tlosEstimate.data) #create case else: p = Project(pForm.name.data, pForm.description.data, pForm.tlosEstimate.data) p.save() else: if projectId is not None: projectResult = Project.objects(id=ObjectId(projectId)).first() if projectResult.tlosEstimate == None: projectResult.tlosEstimate = 0 return render_template('/addProject.html', form=pForm, p=projectResult)
def createProject(): p = Project("unittest", "projet de test unitaire") p.tasks.append(Task(name="conception", description="concpetion du projet")) p.tasks.append(Task(name="implementation", description="implementation du projet")) p.tasks.append(Task(name="test", description="test du projet")) p.save() p = Project("tiers lieu", "projet de test unitaire") p.tasks.append(Task(name="conception", description="concpetion du projet")) p.tasks.append(Task(name="implementation", description="implementation du projet")) p.tasks.append(Task(name="test", description="test du projet")) p.save() p = Project("maker space", "projet de test unitaire") p.tasks.append(Task(name="conception", description="concpetion du projet")) p.tasks.append(Task(name="implementation", description="implementation du projet")) p.tasks.append(Task(name="test", description="test du projet")) p.save()
from datalib import Project, Task from mongoengine import connect def createProject(): p = Project("unittest", "projet de test unitaire") p.tasks.append(Task(name="conception", description="concpetion du projet")) p.tasks.append(Task(name="implementation", description="implementation du projet")) p.tasks.append(Task(name="test", description="test du projet")) p.save() p = Project("tiers lieu", "projet de test unitaire") p.tasks.append(Task(name="conception", description="concpetion du projet")) p.tasks.append(Task(name="implementation", description="implementation du projet")) p.tasks.append(Task(name="test", description="test du projet")) p.save() p = Project("maker space", "projet de test unitaire") p.tasks.append(Task(name="conception", description="concpetion du projet")) p.tasks.append(Task(name="implementation", description="implementation du projet")) p.tasks.append(Task(name="test", description="test du projet")) p.save() if __name__ == '__main__': connect('tlos_mgt', host="mongodb://*****:*****@ds047124.mongolab.com:47124/tlos_mgt") Project.drop_collection() createProject()
def post(self): projectList = Project.objects() data = [{"id":str(p.id),"name": p.name, "description": p.description, "TlosEstimate": str(p.tlosEstimate), "nbrTask": len(p.tasks)} for p in projectList] dic = {"current": 1, "rowCount": 10, "rows": data, "total": 1} return jsonify(dic)