本文整理汇总了Python中models.Note.get_serializable方法的典型用法代码示例。如果您正苦于以下问题:Python Note.get_serializable方法的具体用法?Python Note.get_serializable怎么用?Python Note.get_serializable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Note
的用法示例。
在下文中一共展示了Note.get_serializable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import get_serializable [as 别名]
def create(request):
# TODO Receive a `timestamp` parameter and return all the
# notes that is modified after `timestamp`. Because
# in rare cases uses open the same page multiple times
# , and if we just return the note just added we would
# miss some notes submitted in other pages.
if request.method == 'POST':
form = NewNoteForm(request.POST)
if form.is_valid():
note = Note(author=request.user,
content=form.cleaned_data['content'])
note.save()
data = [note.get_serializable()]
return HttpResponse(simplejson.dumps(data),
mimetype='application/json')
return HttpResponse('false', mimetype='application/json')
示例2: NoteTest
# 需要导入模块: from models import Note [as 别名]
# 或者: from models.Note import get_serializable [as 别名]
class NoteTest(TestCase):
def setUp(self):
self.user = User.objects.create_user('tester',
'tester')
self.note = Note(author=self.user, content='#test#')
self.note.save()
def test_author(self):
self.assertEqual(self.note.author, self.user)
self.assertEqual(self.user.notes.get(), self.note)
def test_get_serializable(self):
note_dict = self.note.get_serializable()
self.assertEqual(note_dict['id'], self.note.id)
self.assertEqual(note_dict['content'], self.note.content.html)
from django.utils.dateformat import format
self.assertEqual(note_dict['modified'],
format(self.note.modified, 'n月j日 G:s'))
self.assertEqual(note_dict['timestamp'],
self.note.modified.strftime('%Y-%m-%d %H:%M:%S.%f'))
def test_update_tags(self):
orig_tags = self.note.tags.all()
self.assertTrue(Tag.objects.get(content='test') in orig_tags)
self.note.content = '#new test# ok #a third one#'
self.note.save()
new_tags = self.note.tags.all()
self.assertFalse(Tag.objects.get(content='test') in new_tags)
self.assertTrue(Tag.objects.get(content='new test') in new_tags)
self.assertTrue(Tag.objects.get(content='a third one') in new_tags)
def test_content_conversion(self):
list_url = reverse('note.views.list')
self.note.content = '#Tag:># message #Tag2#'
self.note.save()
self.assertEqual(self.note.content.html,
'<a href="'+list_url+
'?tags=Tag%3A%3E">#Tag:>#</a> message <a href="'+
list_url+'?tags=Tag2">#Tag2#</a>')