コード例 #1
0
 def get(self):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 记事本'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         template_values['member'] = member
         #q = db.GqlQuery("SELECT * FROM Note WHERE member = :1 ORDER BY last_modified DESC", member)
         q = Note.selectBy(member=member).orderBy('-last_modified')
         try:
             notes_count = q.count()
         except:
             #q = db.GqlQuery("SELECT * FROM Note WHERE member = :1 ORDER BY created DESC", member)
             q = Note.selectBy(member=member).orderBy('-created')
             notes_count = q.count()
         if (notes_count > 0):
             template_values['notes'] = q
         if browser['ios']:
             path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile')
         else:
             path = os.path.join(os.path.dirname(__file__), 'tpl',
                                 'desktop')
         t = self.get_template(path, 'notes_home.html')
         self.finish(t.render(template_values))
     else:
         self.redirect('/signin')
コード例 #2
0
ファイル: notes.py プロジェクト: coderyy/v2ex-tornado-2
 def get(self):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 记事本'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         template_values['member'] = member
         #q = db.GqlQuery("SELECT * FROM Note WHERE member = :1 ORDER BY last_modified DESC", member)
         q = Note.selectBy(member=member).orderBy('-last_modified')
         try:
             notes_count = q.count()
         except:
             #q = db.GqlQuery("SELECT * FROM Note WHERE member = :1 ORDER BY created DESC", member)
             q = Note.selectBy(member=member).orderBy('-created')
             notes_count = q.count()
         if (notes_count > 0):
             template_values['notes'] = q
         if browser['ios']:
             path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile')
         else:
             path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop')
         t=self.get_template(path, 'notes_home.html')
         self.finish(t.render(template_values))
     else:
         self.redirect('/signin')
コード例 #3
0
ファイル: notes.py プロジェクト: coderyy/v2ex-tornado-2
 def post(self):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 新建记事'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         template_values['member'] = member
         # Verification: content
         note_content = self.request.arguments['content'][0].strip()
         note_content_length = len(note_content)
         if note_content_length > 0:
             note = Note()
             #q = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'note.max')
             q = Counter.selectBy(name='note.max')
             if (q.count() == 1):
                 counter = q[0]
                 counter.value = counter.value + 1
             else:
                 counter = Counter()
                 counter.name = 'note.max'
                 counter.value = 1
             #q2 = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'note.total')
             q2 = Counter.selectBy(name='note.max')
             if (q2.count() == 1):
                 counter2 = q2[0]
                 counter2.value = counter2.value + 1
             else:
                 counter2 = Counter()
                 counter2.name = 'note.total'
                 counter2.value = 1
             note.num = counter.value
             note.title = note_content.split("\n")[0][0:60].strip()
             note.content = note_content
             note.body = "\n".join(note_content.split("\n")[1:]).strip()
             note.length = len(note_content)
             note.member_num = member.num
             note.member = member
             note.sync()
             counter.sync()
             counter2.sync()
             store.commit()  #jon add
             self.redirect('/notes/' + str(note.num))
         else:
             template_values['note_content'] = note_content
             if browser['ios']:
                 path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile')
             else:
                 path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop')
             t=self.get_template(path,'notes_new.html')
             self.finish(t.render(template_values))
     else:
         self.redirect('/signin')
コード例 #4
0
ファイル: notes.py プロジェクト: JmmBite-Python/v2ex
 def post(self):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values["site"] = site
     template_values["system_version"] = SYSTEM_VERSION
     template_values["page_title"] = site.title + u" › 新建记事"
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values["l10n"] = l10n
     if member:
         template_values["member"] = member
         # Verification: content
         note_content = self.request.get("content").strip()
         note_content_length = len(note_content)
         if note_content_length > 0:
             note = Note()
             q = db.GqlQuery("SELECT * FROM Counter WHERE name = :1", "note.max")
             if q.count() == 1:
                 counter = q[0]
                 counter.value = counter.value + 1
             else:
                 counter = Counter()
                 counter.name = "note.max"
                 counter.value = 1
             q2 = db.GqlQuery("SELECT * FROM Counter WHERE name = :1", "note.total")
             if q2.count() == 1:
                 counter2 = q2[0]
                 counter2.value = counter2.value + 1
             else:
                 counter2 = Counter()
                 counter2.name = "note.total"
                 counter2.value = 1
             note.num = counter.value
             note.title = note_content.split("\n")[0][0:60].strip()
             note.content = note_content
             note.body = "\n".join(note_content.split("\n")[1:]).strip()
             note.length = len(note_content)
             note.member_num = member.num
             note.member = member
             note.put()
             counter.put()
             counter2.put()
             self.redirect("/notes/" + str(note.num))
         else:
             template_values["note_content"] = note_content
             if browser["ios"]:
                 path = os.path.join(os.path.dirname(__file__), "tpl", "mobile", "notes_new.html")
             else:
                 path = os.path.join(os.path.dirname(__file__), "tpl", "desktop", "notes_new.html")
             output = template.render(path, template_values)
             self.response.out.write(output)
     else:
         self.redirect("/signin")
コード例 #5
0
ファイル: notes.py プロジェクト: cwyark/v2ex
 def post(self):
     site = GetSite()
     user_agent = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 新建记事'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         template_values['member'] = member
         # Verification: content
         note_content = self.request.get('content').strip()
         note_content_length = len(note_content)
         if note_content_length > 0:
             note = Note()
             q = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'note.max')
             if (q.count() == 1):
                 counter = q[0]
                 counter.value = counter.value + 1
             else:
                 counter = Counter()
                 counter.name = 'note.max'
                 counter.value = 1
             q2 = db.GqlQuery('SELECT * FROM Counter WHERE name = :1', 'note.total')
             if (q2.count() == 1):
                 counter2 = q2[0]
                 counter2.value = counter2.value + 1
             else:
                 counter2 = Counter()
                 counter2.name = 'note.total'
                 counter2.value = 1
             note.num = counter.value
             note.title = note_content.split("\n")[0][0:60].strip()
             note.content = note_content
             note.body = "\n".join(note_content.split("\n")[1:]).strip()
             note.length = len(note_content)
             note.member_num = member.num
             note.member = member
             note.put()
             counter.put()
             counter2.put()
             self.redirect('/notes/' + str(note.num))
         else:
             template_values['note_content'] = note_content
             path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop', 'notes_new.html')
             output = template.render(path, template_values)
             self.response.out.write(output)
     else:
         self.redirect('/signin')
コード例 #6
0
ファイル: notes.py プロジェクト: coderyy/v2ex-tornado-2
 def get(self, num):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 记事本 › 编辑'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     template_values['xsrf'] = self.xsrf_form_html()
     if member:
         #q = db.GqlQuery("SELECT * FROM Note WHERE num = :1", int(num))
         q = Note.selectBy(num=int(num))
         if q.count() > 0:
             note = q[0]
             if note.member.num == member.num:
                 template_values['member'] = member
                 template_values['note'] = note
                 template_values['note_content'] = note.content
                 if browser['ios']:
                     path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile')
                 else:
                     path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop')
                 t=self.get_template(path,'notes_edit.html')
                 self.finish(t.render(template_values))
             else:
                 self.redirect('/notes')
         else:
             self.redirect('/notes')
     else:
         self.redirect('/signin')
コード例 #7
0
 def get(self, num):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 记事本 › 编辑'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     template_values['xsrf'] = self.xsrf_form_html()
     if member:
         #q = db.GqlQuery("SELECT * FROM Note WHERE num = :1", int(num))
         q = Note.selectBy(num=int(num))
         if q.count() > 0:
             note = q[0]
             if note.member.num == member.num:
                 template_values['member'] = member
                 template_values['note'] = note
                 template_values['note_content'] = note.content
                 if browser['ios']:
                     path = os.path.join(os.path.dirname(__file__), 'tpl',
                                         'mobile')
                 else:
                     path = os.path.join(os.path.dirname(__file__), 'tpl',
                                         'desktop')
                 t = self.get_template(path, 'notes_edit.html')
                 self.finish(t.render(template_values))
             else:
                 self.redirect('/notes')
         else:
             self.redirect('/notes')
     else:
         self.redirect('/signin')
コード例 #8
0
 def post(self, num):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 记事本'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         template_values['member'] = member
         # Verification: content
         note_content = self.request.arguments['content'][0].strip()
         note_content_length = len(note_content)
         if note_content_length > 0:
             #q = db.GqlQuery("SELECT * FROM Note WHERE num = :1", int(num))
             q = Note.selectBy(num=int(num))
             if q.count() > 0:
                 note = q[0]
                 template_values['page_title'] = site.title + u' › 记事本 › 编辑'
                 if note.member.num == member.num:
                     note.title = note_content.split("\n")[0][0:60].strip()
                     note.content = note_content
                     note.body = "\n".join(
                         note_content.split("\n")[1:]).strip()
                     note.length = len(note_content)
                     note.edits = note.edits + 1
                     note.sync()
                     store.commit()  #jon add
                     memcache.set('Note_' + str(note.num), note, 86400)
                     self.redirect('/notes/' + str(note.num))
                 else:
                     self.redirect('/notes')
             else:
                 self.redirect('/notes')
         else:
             template_values['note_content'] = note_content
             if browser['ios']:
                 path = os.path.join(os.path.dirname(__file__), 'tpl',
                                     'mobile')
             else:
                 path = os.path.join(os.path.dirname(__file__), 'tpl',
                                     'desktop')
             t = self.get_template(path, 'notes_new.html')
             self.finish(t.render(template_values))
     else:
         self.redirect('/signin')
コード例 #9
0
ファイル: notes.py プロジェクト: coderyy/v2ex-tornado-2
 def post(self, num):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 记事本'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         template_values['member'] = member
         # Verification: content
         note_content = self.request.arguments['content'][0].strip()
         note_content_length = len(note_content)
         if note_content_length > 0:
             #q = db.GqlQuery("SELECT * FROM Note WHERE num = :1", int(num))
             q = Note.selectBy(num=int(num))
             if q.count() > 0:
                 note = q[0]
                 template_values['page_title'] = site.title + u' › 记事本 › 编辑' 
                 if note.member.num == member.num:
                     note.title = note_content.split("\n")[0][0:60].strip()
                     note.content = note_content
                     note.body = "\n".join(note_content.split("\n")[1:]).strip()
                     note.length = len(note_content)
                     note.edits = note.edits + 1
                     note.sync()
                     store.commit()  #jon add
                     memcache.set('Note_' + str(note.num), note, 86400)
                     self.redirect('/notes/' + str(note.num))
                 else:
                     self.redirect('/notes')
             else:
                 self.redirect('/notes')
         else:
             template_values['note_content'] = note_content
             if browser['ios']:
                 path = os.path.join(os.path.dirname(__file__), 'tpl', 'mobile')
             else:
                 path = os.path.join(os.path.dirname(__file__), 'tpl', 'desktop')
             t=self.get_template(path,'notes_new.html')
             self.finish(t.render(template_values))
     else:
         self.redirect('/signin')
コード例 #10
0
ファイル: notes.py プロジェクト: coderyy/v2ex-tornado-2
 def get(self, num):
     site = GetSite()
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 记事本'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         #q = db.GqlQuery("SELECT * FROM Note WHERE num = :1", int(num))
         q = Note.selectBy(num=int(num))
         if q.count() > 0:
             note = q[0]
             if note.member.num == member.num:
                 note.delete()
                 self.redirect('/notes')
             else:
                 self.redirect('/notes')
         else:
             self.redirect('/notes')
     else:
         self.redirect('/signin')
コード例 #11
0
 def get(self, num):
     site = GetSite()
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 记事本'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         #q = db.GqlQuery("SELECT * FROM Note WHERE num = :1", int(num))
         q = Note.selectBy(num=int(num))
         if q.count() > 0:
             note = q[0]
             if note.member.num == member.num:
                 note.delete()
                 self.redirect('/notes')
             else:
                 self.redirect('/notes')
         else:
             self.redirect('/notes')
     else:
         self.redirect('/signin')
コード例 #12
0
ファイル: notes.py プロジェクト: clarkman12345/v2ex
 def post(self):
     site = GetSite()
     browser = detect(self.request)
     template_values = {}
     template_values['site'] = site
     template_values['system_version'] = SYSTEM_VERSION
     template_values['page_title'] = site.title + u' › 新建记事'
     member = CheckAuth(self)
     l10n = GetMessages(self, member, site)
     template_values['l10n'] = l10n
     if member:
         template_values['member'] = member
         # Verification: content
         note_content = self.request.get('content').strip()
         note_content_length = len(note_content)
         if note_content_length > 0:
             note = Note()
             q = db.GqlQuery('SELECT * FROM Counter WHERE name = :1',
                             'note.max')
             if (q.count() == 1):
                 counter = q[0]
                 counter.value = counter.value + 1
             else:
                 counter = Counter()
                 counter.name = 'note.max'
                 counter.value = 1
             q2 = db.GqlQuery('SELECT * FROM Counter WHERE name = :1',
                              'note.total')
             if (q2.count() == 1):
                 counter2 = q2[0]
                 counter2.value = counter2.value + 1
             else:
                 counter2 = Counter()
                 counter2.name = 'note.total'
                 counter2.value = 1
             note.num = counter.value
             note.title = note_content.split("\n")[0][0:60].strip()
             note.content = note_content
             note.body = "\n".join(note_content.split("\n")[1:]).strip()
             note.length = len(note_content)
             note.member_num = member.num
             note.member = member
             note.put()
             counter.put()
             counter2.put()
             self.redirect('/notes/' + str(note.num))
         else:
             template_values['note_content'] = note_content
             if browser['ios']:
                 path = os.path.join(os.path.dirname(__file__), 'tpl',
                                     'mobile', 'notes_new.html')
             else:
                 path = os.path.join(os.path.dirname(__file__), 'tpl',
                                     'desktop', 'notes_new.html')
             output = template.render(path, template_values)
             self.response.out.write(output)
     else:
         self.redirect('/signin')