def create_menu(request): user = have_permission(request) if user: menu = Menu() menu.author = user menu.save() return menu_edit(request, menu) return False
def detail(request, pk): post = get_object_or_404(Post, pk=pk) return render(request, 'blog/posts/detail.html', { 'patronage':Patronage.list, 'menu':Menu.options(), 'post': post })
def main(request): error = None success = None contact_email = "" contact_text = "" if request.POST: contact_text = request.POST.get("contact-text") contact_email = request.POST.get("contact-email") g_rc_response = request.POST.get("g-recaptcha-response") url = "https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s" % (settings.RECAPTCHA_SECRET_KEY, g_rc_response) resp = urllib.request.urlopen(url) js = json.loads(resp.read().decode("utf-8")) if js['success']: if check_address(contact_email): try: send_email(contact_text, contact_email) contact_text = "" contact_email = "" success = "Twoja wiadomość została wysłana" except Exception: error = "Błąd wysyłania wiadomości, spróbuj później" else: error = "Niepoprawny adres email" else: error = "Udowodnij, że jesteś człowiekiem" return render(request, 'blog/contact/main.html', { 'success': success, 'error': error, 'contact_text': contact_text, 'contact_email': contact_email, 'context_instance': RequestContext(request), 'menu': Menu.options() })
def list(request): posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date') return render(request, 'blog/posts/list.html', { 'patronage':Patronage.list, 'menu':Menu.options(), 'posts':posts })
def list(request): return render(request, 'blog/files/list.html', { 'context_instance': RequestContext(request), 'menu': Menu.options(), 'patronage': Patronage.list, 'links': Links.all() })
def manageAlbum_list(site,request): viewmap={} albummenu=Menu.objects.filter(site=site.get('id')).filter(type='album')[:1] if len(albummenu)==0: albummenu=Menu() albummenu.name='相册' albummenu.index=0 albummenu.type='album' albummenu.site=WebSiteInfo.objects.get(pk=site.get('id')) albummenu.save() else: albummenu=albummenu[0] viewmap['album']=albummenu titlequery=Title.objects.filter(menu=albummenu) albumlist=[] for album in titlequery: firstImageList=PaperImage.objects.filter(title=album).order_by('index')[:1] if 0==len(firstImageList): album.firstImage=None else: album.firstImage=firstImageList[0] album.firstImage.imgsmal=album.firstImage.getImgUrlsmall(site.get('id')) albumlist.append(album) viewmap['albumlist']=albumlist #################### #### 设置左侧数据 left(site,viewmap) #### 设置 menu 数据 menu(site,viewmap) return viewmap
def albumlist(site,request,albumid=None): viewmap={} albummenu=None if albumid: albumid=int(albumid) albummenu=Menu.objects.get(pk=albumid) if not albummenu: albummenu=Menu.objects.filter(site=site.get('id')).filter(type='album')[:1] if len(albummenu)==0: albummenu=Menu() albummenu.name='相册' albummenu.index=0 albummenu.type='album' albummenu.site=WebSiteInfo.objects.get(pk=site.get('id')) albummenu.save() else: albummenu=albummenu[0] viewmap['album']=albummenu titlequery=Title.objects.filter(menu=albummenu) offset=request.GET.get('offset','0') offset=int(offset) offsetN=offset+ALBUM_LIST_LIMIT offsetP=(offset>=ALBUM_LIST_LIMIT and [offset-ALBUM_LIST_LIMIT] or [0])[0] totalpaper=titlequery.count() if totalpaper<offsetN: offsetN-=ALBUM_LIST_LIMIT viewmap['albumlist']=titlequery[offset:offset+ALBUM_LIST_LIMIT] viewmap['offset']=offset viewmap['offsetN']=offsetN viewmap['offsetP']=offsetP pagelist=[] pp=offset-(ALBUM_LIST_LIMIT*4) nn=offset+(ALBUM_LIST_LIMIT*4) for p in range(0,completePage(totalpaper,ALBUM_LIST_LIMIT)): if p*ALBUM_LIST_LIMIT> pp and p*ALBUM_LIST_LIMIT<nn: pagelist.append({'page':p+1,'offset':p*ALBUM_LIST_LIMIT}) viewmap['lastpage']=p*ALBUM_LIST_LIMIT albumlist=[] for album in viewmap['albumlist']: firstImageList=PaperImage.objects.filter(title=album).order_by('index')[:1] if 0==len(firstImageList): album.firstImage=None else: album.firstImage=firstImageList[0] album.firstImage.imgsmal=album.firstImage.getImgUrlsmall(site.get('id')) albumlist.append(album) viewmap['albumlist']=albumlist #################### #### 设置左侧数据 left(site,viewmap) #### 设置 menu 数据 menu(site,viewmap) return viewmap
def deploy(deploy_type): from flask.ext.migrate import upgrade from blog.models import BlogInfo, User, ArticleTypeSetting, Source, \ ArticleType, Plugin, BlogView, Comment # upgrade database to the latest version upgrade() if deploy_type == 'product': # step_1:insert basic blog info BlogInfo.insert_blog_info() # step_2:insert admin account User.insert_admin(email='*****@*****.**', username='******', password='******') # step_3:insert system default setting ArticleTypeSetting.insert_system_setting() # step_4:insert default article sources Source.insert_sources() # step_5:insert default articleType ArticleType.insert_system_articleType() # step_6:insert system plugin Plugin.insert_system_plugin() # step_7:insert blog view BlogView.insert_view() # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)` if deploy_type == 'test_data': # step_1:insert navs Menu.insert_menus() # step_2:insert articleTypes ArticleType.insert_articleTypes() # step_3:generate random articles Article.generate_fake(100) # step_4:generate random comments Comment.generate_fake(300) # step_5:generate random replies Comment.generate_fake_replies(100) # step_4:generate random comments Comment.generate_fake(300)
def manageMenu_save(site,request): if 'POST'!=request.method.upper(): return HttpResponseRedirect('/blog/Admin/manageMenu') msg=u'操作成功' viewmap={} id=request.POST.get('id','') indexnum=request.POST.get('index',0) if id: menuitem=Menu.objects.get(pk=id) else: menuitem=Menu() menuitem.site=WebSiteInfo.objects.get(pk=site.get('id')) lastmenuquery=Menu.objects.filter(site=site.get('id')).filter(type='paper').filter(link=None).order_by('-index')[:1] if 0==len(lastmenuquery): menuitem.index=1 else: menuitem.index=lastmenuquery[0].index+1 if not menuitem: msg=u'操作错误' else: try: indexnum=int(indexnum) except : msg=u'顺序,必须为数字' else: menuitem.name=request.POST.get('name').strip() if id: menuitem.index=indexnum menuitem.save() cache.delete(MENU_ALL_LIST+str(site.get('id'))) viewmap['msg']=msg # viewmap['menulist']=Menu.objects.filter(site=site.get('id')).filter(link=None).order_by('index') #### 设置左侧数据 left(site,viewmap) #### 设置 menu 数据 menu(site,viewmap) return viewmap
def manageAlbum_save(site,request): viewmap={} albummenu=Menu.objects.filter(site=site.get('id')).filter(type='album')[:1] if len(albummenu)==0: albummenu=Menu() albummenu.name='相册' albummenu.index=0 albummenu.type='album' albummenu.site=WebSiteInfo.objects.get(pk=site.get('id')) albummenu.save() else: albummenu=albummenu[0] viewmap['albummenu']=albummenu if 'POST'==request.method.upper(): albumname=request.POST.get('albumName',u'未命名') albumid=request.POST.get('albumId',None) if albumid: album=Title.objects.get(pk=albumid) else: album=Title() album.title=albumname album.menu=albummenu album.type='album' album.author=request.user album.site=WebSiteInfo.objects.get(pk=site.get('id')) album.isPub=True album.save() viewmap['album']=album msg=u'保存成功' viewmap['msg']=msg else: albumid=request.GET.get('albumId',None) if albumid: album=Title.objects.get(pk=albumid) viewmap['album']=album #################### #### 设置左侧数据 left(site,viewmap) #### 设置 menu 数据 menu(site,viewmap) return viewmap
def list(request): return render(request, 'blog/bio/list.html', { 'menu':Menu.options(), 'bio': Bio.objects.all(), 'patronage':Patronage.list })
def detail(request, pk): bio = get_object_or_404(Bio, pk=pk) return render(request, 'blog/bio/detail.html', { 'bio': bio, 'menu':Menu.options() })