@@ -0,0 +1,976 @@
+# -*- coding: utf-8 -*-%0A# https://docs.mongodb.com/ecosystem/use-cases/storing-comments/%0Aimport datetime%0Aimport random%0Aimport string%0Afrom bson import ObjectId%0Afrom pymongo import IndexModel, ASCENDING, DESCENDING%0A%0A%0Adef comment(fid, text, parent_slug=None, user=None, ts=None):%0A    if ts is None:%0A        ts = datetime.datetime.now()%0A    slug_part = u''.join(%0A        %5Bunicode((string.ascii_letters + string.digits)%5Bx%5D, 'utf-8') for x in random.sample(range(0, 62), 4)%5D)%0A    slug = parent_slug + u'/' + slug_part if parent_slug else slug%0A    return %7B%0A        u'_id': ObjectId(),%0A        u'fid': fid,%0A        u'user': %7B%0A            u'sid': user.sid,%0A            u'name': user.name,%0A            u'avator': user.avator%0A        %7D,%0A        u'text': text,%0A        u'slug': slug,%0A        u'ts': ts%0A    %7D%0A%0AMONGO_INDEXES = %5B%0A    IndexModel(%5B(u'fid', ASCENDING), (u'slug', ASCENDING)%5D, name=u'by_slug'),%0A    IndexModel(%5B(u'fid', ASCENDING), (u'ts', DESCENDING)%5D, name=u'by_timestamp'),%0A%5D

Comment Moded Added