def test_book_autodelete(self): note1 = TextNote(text='text') note1.save() note2 = TextNote(text='text') note2.save() book = Book(title='title') book.save() book.note.add(*[note1, note2]) note1.delete() self.assertTrue(Book.objects.all()) note2.delete() self.assertFalse(Book.objects.all())
class CustomInclusionTagTest(TestCase): """Test for custom tag, that renders text note with given id""" def setUp(self): self.note = TextNote(text="Text note") self.note.save() self.id = str(self.note.id) self.TEMPLATE = Template("{% load custom_tag %} \ {% custom_tag "+self.id+" %}") def test_note_shows_up(self): rendered = self.TEMPLATE.render(Context({})) self.assertIn(self.note.text, rendered) def tearDown(self): self.note.delete() self.note = None
def submit_data_for_problem(request, problem_id): print request.POST problem = Problem.objects.get(id=problem_id) objId=None if request.POST['type'] == 'note': problem = Problem.objects.get(id=problem_id) note = TextNote(by=UserProfile.objects.get(user=request.user).role, note=request.POST['data']) note.save() problem.notes.add(note) problem.save() elif request.POST['type'] == 'note_for_goal': goal = Goal.objects.get(id=problem_id) note = TextNote(by=UserProfile.objects.get(user=request.user).role, note=request.POST['data']) note.save() goal.notes.add(note) goal.save() elif request.POST['type'] == 'mark_parent': problem = Problem.objects.get(id=problem_id) if (request.POST['data'] == 'none'): problem.parent = None else: problem.parent = Problem.objects.get(id=request.POST['data']) problem.save() else: problem = Problem.objects.get(id=problem_id) model = get_model('emr', request.POST['type'].capitalize()) m = model(patient=problem.patient, problem=problem) setattr(m,request.POST['type'], request.POST['data'] ) m.save() objId = m.id if objId: return HttpResponse(objId) else: return HttpResponse('saved')
def submit_data_for_problem(request, problem_id): print request.POST if request.POST['type'] == 'note': problem = Problem.objects.get(id=problem_id) note = TextNote(by=UserProfile.objects.get(user=request.user).role, note=request.POST['data']) note.save() problem.notes.add(note) problem.save() elif request.POST['type'] == 'problem_parent': problem = Problem.objects.get(id=problem_id) if (request.POST['data'] == 'none'): problem.parent = None else: problem.parent = Problem.objects.get(id=request.POST['data']) problem.save() elif request.POST['type'] == 'problem_start_date': print 'problem_start_date: '+str(request.POST) problem = Problem.objects.get(id=problem_id) from datetime import datetime if not request.POST['data'].index('/') == 2: problem.start_date = datetime.strptime('0' + request.POST['data'], "%m/%d/%Y") else: problem.start_date = datetime.strptime(request.POST['data'], "%m/%d/%Y") problem.save() elif request.POST['type'] == 'note_for_goal': goal = Goal.objects.get(id=problem_id) note = TextNote(by=UserProfile.objects.get(user=request.user).role, note=request.POST['data']) note.save() goal.notes.add(note) goal.save() elif request.POST['type'] == 'mark_parent': problem = Problem.objects.get(id=problem_id) if (request.POST['data'] == 'none'): problem.parent = None else: problem.parent = Problem.objects.get(id=request.POST['data']) problem.save() else: problem = Problem.objects.get(id=problem_id) model = get_model('emr', request.POST['type'].capitalize()) m = model(patient=problem.patient, problem=problem) setattr(m,request.POST['type'], request.POST['data'] ) m.save() return HttpResponse(m.id) return HttpResponse('saved')
from models import Notebook, TextNote, VideoNote bio = Notebook("Bio 201 Notes") bio.notes.append(TextNote("This is the first day of Bio 201")) bio.notes.append(TextNote("Final exam is 95%.")) bio.notes.append(VideoNote("https://www.youtube.com/watch?v=PKffm2uI4dk")) bio.display() bio.save("bio201.txt") bio.load("bio201.txt") print(bio.to_json())
def setUp(self): self.note = TextNote(text="Text note") self.note.save() self.id = str(self.note.id) self.TEMPLATE = Template("{% load custom_tag %} \ {% custom_tag "+self.id+" %}")