diff --git a/accounts/urls.py b/accounts/urls.py index e972a46..d753d24 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -22,4 +22,5 @@ from .forms import LoginForm urlpatterns = [ url(r'^login/$', views.LoginView.as_view(success_url='/'), name='login', kwargs={'authentication_form': LoginForm}), url(r'^register/$', views.RegisterView.as_view(success_url="/"), name='register'), + url(r'^logout/$', views.logout, name='logout') ] diff --git a/accounts/views.py b/accounts/views.py index f29e8cb..39ffb44 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render -from django.contrib.auth.views import login +from django.contrib.auth.views import login, logout from .forms import RegisterForm, LoginForm from django.contrib.auth import authenticate from django.views.generic.edit import FormView @@ -25,6 +25,10 @@ class RegisterView(FormView): return HttpResponseRedirect('/') +def LogOut(requests): + logout(request=requests) + return HttpResponseRedirect("/") + class LoginView(FormView): form_class = LoginForm diff --git a/blog/models.py b/blog/models.py index 2319f3e..17b408f 100644 --- a/blog/models.py +++ b/blog/models.py @@ -83,6 +83,10 @@ class Article(models.Model): comments = self.comment_set.all() parent_comments = comments.filter(parent_comment=None) + def get_admin_url(self): + info = (self._meta.app_label, self._meta.model_name) + return reverse('admin:%s_%s_change' % info, args=(self.pk,)) + ''' class BlogPage(models.Model): diff --git a/blog/templatetags/blog_tags.py b/blog/templatetags/blog_tags.py index fc92e54..6d99fed 100644 --- a/blog/templatetags/blog_tags.py +++ b/blog/templatetags/blog_tags.py @@ -138,14 +138,15 @@ def load_sidebar(user): @register.inclusion_tag('blog/tags/article_meta_info.html') -def load_article_metas(article): +def load_article_metas(article, user): """ 获得文章meta信息 :param article: :return: """ return { - 'article': article + 'article': article, + 'user': user } @@ -160,7 +161,7 @@ def load_nav_info(): @register.inclusion_tag('blog/tags/article_info.html') -def load_article_detail(article, isindex): +def load_article_detail(article, isindex, user): """ 加载文章详情 :param article: @@ -169,7 +170,8 @@ def load_article_detail(article, isindex): """ return { 'article': article, - 'isindex': isindex + 'isindex': isindex, + 'user': user } diff --git a/blog/views.py b/blog/views.py index 192025a..8814989 100644 --- a/blog/views.py +++ b/blog/views.py @@ -17,7 +17,7 @@ from django import http from django.http import HttpResponse from abc import ABCMeta, abstractmethod - +""" class SeoProcessor(): __metaclass__ = ABCMeta @@ -32,6 +32,7 @@ class SeoProcessor(): @abstractmethod def get_description(self): pass +""" class ArticleListView(ListView): @@ -47,11 +48,7 @@ class ArticleListView(ListView): page_kwarg = 'page' -class IndexView(ArticleListView, SeoProcessor): - def get_title(self): - return '逝去日子的博客' - def get_keywords(self): - pass +class IndexView(ArticleListView): def get_queryset(self): article_list = Article.objects.filter(status='p') diff --git a/comments/forms.py b/comments/forms.py index 93bfcfb..1790954 100644 --- a/comments/forms.py +++ b/comments/forms.py @@ -44,7 +44,10 @@ class LoginCommentForm(ModelForm): class CommentForm(ModelForm): url = forms.URLField(label='网址', required=False) email = forms.EmailField(label='电子邮箱', required=False) - name = forms.CharField(label='姓名') + name = forms.CharField(label='姓名', widget=forms.TextInput(attrs= + {'value': "", 'size': "30", 'maxlength': "245", + 'aria-required': 'true'} + )) parent_comment_id = forms.IntegerField(widget=forms.HiddenInput, required=False) """ if get_user_model().is_authenticated: @@ -61,6 +64,7 @@ class CommentForm(ModelForm): 'name': forms.CharField(widget=forms.HiddenInput()), }) """ + class Meta: model = Comment fields = ['body'] diff --git a/comments/views.py b/comments/views.py index 96d2965..1b624aa 100644 --- a/comments/views.py +++ b/comments/views.py @@ -52,4 +52,5 @@ class CommentPostView(FormView): comment.save(True) - return HttpResponseRedirect(article.get_absolute_url()) + # return HttpResponseRedirect(article.get_absolute_url() + "#div-comment-" + comment.pk) + return HttpResponseRedirect("%s#div-comment-%d" % (article.get_absolute_url(), comment.pk)) diff --git a/templates/account/login.html b/templates/account/login.html index a3e04a3..91335f6 100644 --- a/templates/account/login.html +++ b/templates/account/login.html @@ -15,7 +15,7 @@ {% endcomment %} {{ form.non_field_errors }} {% for field in form %} - {{ field }} + {{ field }} {{ field.errors }} {% endfor %} @@ -33,7 +33,7 @@
- Create an account + Create an account
diff --git a/templates/account/registration_form.html b/templates/account/registration_form.html index b02901a..f6f126a 100644 --- a/templates/account/registration_form.html +++ b/templates/account/registration_form.html @@ -34,7 +34,7 @@ diff --git a/templates/accountbase.html b/templates/accountbase.html index ba209fe..e1df7d6 100644 --- a/templates/accountbase.html +++ b/templates/accountbase.html @@ -10,7 +10,7 @@ -{{ comment_item.body }}
diff --git a/templates/comments/tags/post_comment.html b/templates/comments/tags/post_comment.html index 3a599cf..f7434e9 100644 --- a/templates/comments/tags/post_comment.html +++ b/templates/comments/tags/post_comment.html @@ -11,6 +11,7 @@ {% endcomment %}{{ form.body.label_tag }} + {{ form.body }} {{ form.body.errors }} {% comment %}