def publish(): name = request.POST.get("name",None) title = request.POST.get("title",None) cat = request.POST.get("cat",'') tag = request.POST.get("tag",'') private = request.POST.get("private",'') print '---------',private,type(private) content = request.POST.get("content",'').strip() head = '''--- layout: post title: %s category: %s tags: [%s] --- '''%(title, cat, tag) import datetime m_date = datetime.datetime.now().strftime('%Y-%m-%d') path = 'raw/entry/%s-%s.md'%(m_date, name) m_file = open(path, 'w+') m_file.write('%s\n%s'%(head,content) ) m_file.close() if private: entryService.add_entry(False, path, True) entryService.update_urls() entryService.private_list.append(path) entryService.save_private() else: entryService.add_entry(True, path) return {'code': 0, 'msg': '发布成功'}
def publish(): name = request.POST.get("name", None) title = request.POST.get("title", None) cat = request.POST.get("cat", '') tag = request.POST.get("tag", '') private = request.POST.get("private", '') print '---------', private, type(private) content = request.POST.get("content", '').strip() head = '''--- layout: post title: %s category: %s tags: [%s] --- ''' % (title, cat, tag) import datetime m_date = datetime.datetime.now().strftime('%Y-%m-%d') path = 'raw/entry/%s-%s.md' % (m_date, name) m_file = open(path, 'w+') m_file.write('%s\n%s' % (head, content)) m_file.close() if private: entryService.add_entry(False, path, True) entryService.update_urls() entryService.private_list.append(path) entryService.save_private() else: entryService.add_entry(True, path) return {'code': 0, 'msg': '发布成功'}
def DeletePost(): session = get_current_session() username = session.get('username','') if not username: return {'code': -2, 'msg': '未登录'} raw_url = request.POST.get("raw_url",'') entry_url = raw_url.replace(config.raw_url, config.entry_url).replace(config.raw_suffix, config.url_suffix) entry = entryService.find_by_url(entryService.types.entry, entry_url).entry entryService.delete_entry(entry.path) os.remove(entry.path) if entry.private: try: print 'deeeee',entry.path entryService.private_list.remove(entry.path) except:pass entryService.save_private() return {'code': 0, 'msg': '删除成功'}
def DeletePost(): session = get_current_session() username = session.get('username', '') if not username: return {'code': -2, 'msg': '未登录'} raw_url = request.POST.get("raw_url", '') entry_url = raw_url.replace(config.raw_url, config.entry_url).replace( config.raw_suffix, config.url_suffix) entry = entryService.find_by_url(entryService.types.entry, entry_url).entry entryService.delete_entry(entry.path) os.remove(entry.path) if entry.private: try: print 'deeeee', entry.path entryService.private_list.remove(entry.path) except: pass entryService.save_private() return {'code': 0, 'msg': '删除成功'}