Skip to content

Commit

Permalink
add publish page
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Feb 28, 2018
1 parent b808729 commit aad1686
Show file tree
Hide file tree
Showing 72 changed files with 15,354 additions and 84 deletions.
Binary file modified article/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified article/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file modified article/__pycache__/views.cpython-36.pyc
Binary file not shown.
14 changes: 10 additions & 4 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db import models
from tinymce.models import HTMLField,TinyMCE
from django.contrib.auth.models import User
from django.forms import ModelForm,Textarea
from django.forms import *
from userpage.models import *
#from django.conf import settings
#from tagging.fields import TagField
Expand Down Expand Up @@ -50,9 +50,15 @@ class Meta:
class ArticleForm(ModelForm):
class Meta:
model = Article
fields = ['title','author','section','tag','cover','detail']
fields = ['title','author','author_id','section','tag','cover','detail']
widgets = {
'detail':TinyMCE(attrs={'cols':'100%','rows':50}),
'detail':TinyMCE(attrs={'cols':'100%','rows':30}),
'cover':ClearableFileInput(attrs={'style':'width:50%','class':'form-control','placeholder':"封面"}),
'tag':TextInput(attrs={'class':'form-control','placeholder':"添加标签,回车确认",'data-role':'tagsinput'}),
'author':TextInput(attrs={'class':'form-control','placeholder':"署名"}),
'title':TextInput(attrs={'style':'width:50%','class':'form-control','placeholder':"标题"}),
'section':widgets.Select(choices=Section.objects.values_list('id','name'),attrs={'class':'form-control','placeholder':"标题"}),

}


Expand All @@ -62,7 +68,7 @@ class Comment(models.Model):
user = models.ForeignKey(Profile,on_delete=models.CASCADE,default=0)
comment_time = models.DateTimeField(auto_now_add=True,editable=False)
comment = HTMLField()
ip = models.GenericIPAddressField()
ip = models.GenericIPAddressField(blank=True,null=True,default='0.0.0.0')
clickcount = models.IntegerField(default=0)
refer = models.CharField(max_length=5096,default='none')
agent = models.CharField(max_length=5096,default='none')
Expand Down
26 changes: 18 additions & 8 deletions article/templates/article/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,37 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>

{% block content %}
<div class="card margintop article-content">
<span class="fad">作者:<a href="#"><img src="/static/{{art.author_id.avatar}}" class="avatar-img">&nbsp;{{art.author}}</a> </span>
<span class="fad">作者:<a href="#"><img src="/{{art.author_id.avatar}}" class="avatar-img">&nbsp;{{art.author}}</a> </span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fad">阅读数:{{art.readtime}}</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fad">评论数:{{comments|length}}</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fad">发表于:{{art.publish_time}}</span>
<span class="sep margintop"></span>
{% ifequal request.user.id art.author_id.id %}
<span class="fad pull-right" ><button class="btn btn-primary" onclick="window.location.href='/article/update/{{art.id}}/'">编辑</button></span>
{% else %}
{{request.user.id}},{{art.author_id.id}}
{% endifequal %}
<p></p>
<span class="fad">标签:{{art.tag}}</span>
<span class="sep margintop" ></span>
<div class="ad1"> <h3>广告位</h3> </div>
{{art.detail|safe|escape }}
</div>

<div class="card">
<p>评论</p>
<p>评论</p>
<span class="sep"></span>
{% for i in comments %}
<div class="comment row">
<div class="comment-avatar" style="background:url(/static/{{i.user.avatar}}) no-repeat;background-position:10px 20px;background-size:60px 60px;">
<div class="comment-avatar" style="background:url(/{{i.user.avatar}}) no-repeat;background-position:10px 20px;background-size:60px 60px;">
{{i.user}}
</div>
<div class="comment-info">
<span class="glyphicon glyphicon-time fad"> </span>&nbsp;<span class="fad">{{i.comment_time}}</span>
<span class="pull-right fad floor" id="floor_{{forloop.counter}}"># {{forloop.counter}}</span>
<span class="pull-right">
<span class="pull-right ico fad floor" id="floor_{{forloop.counter}}"># {{forloop.counter}}</span>
<span class="pull-right ico ">
<a href="#"><img style="inline-block" src="/static/image/reply.png" align="absmiddle" border="0" alt="Reply"></a>
</span>
<p></p>
Expand All @@ -69,19 +76,22 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
</div>

<div class="card">
<p>发布评论</p>

{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
<form method="post" novalidate>
<form class="textarea" method="post" novalidate>
{% csrf_token %}
<input type='hidden' name="article" value="{{art.id}}" />
<input type='hidden' name="user" value="{{request.user.id}}" />
{{comment_form.comment}}
<button class="btn btn-default pull-right" type="submit">发表</button>
<p></p>
<button class="btn btn-default pull-right" type="submit">发布</button>
</form>

</div>
Expand Down
71 changes: 24 additions & 47 deletions article/templates/article/publish.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "base.html" %}

{% block header %}
<title>{{art.title}} - 物志</title>
<title>发布文章 - 物志</title>
<script type="text/javascript" src="/static/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinyMCE.init(
Expand All @@ -19,68 +19,45 @@

);
</script>

<script type="text/javascript" src="/static/bootstrap/js/bootstrap-tagsinput.js"></script>
<link href="/static/bootstrap/css/bootstrap-tagsinput.css" rel="stylesheet">
{% endblock %}


{% block banner %}
<div class="banner" style="background:url(/{{art.cover}}) no-repeat;background-position:center;background-size:cover;">
<div class="container">
<h1>{% if art %}{{art.title}}{% endif %} </h1>
<div style="height:30px">
<p></p>
</div>
</div>
{% endblock %}


{% block content %}
<div class="card margintop article-content">
<span class="fad">作者:<a href="#"><img src="/static/{{art.author_id.avatar}}" class="avatar-img">&nbsp;{{art.author}}</a> </span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fad">发表于:{{art.publish_time}}</span>
<span class="sep margintop"></span>
<div class="ad1"> <h3>广告位</h3> </div>
{{art.detail|safe|escape }}
</div>

<div class="card">
<p>评论</p>
<span class="sep"></span>
{% for i in comments %}
<div class="comment row">
<div class="comment-avatar" style="background:url(/static/{{i.user.avatar}}) no-repeat;background-position:10px 20px;background-size:60px 60px;">
{{i.user}}
</div>
<div class="comment-info">
<span class="glyphicon glyphicon-time fad"> </span>&nbsp;<span class="fad">{{i.comment_time}}</span>
<span class="pull-right fad floor"> # {{forloop.counter}}</span>
<span class="pull-right">
<a href="#"><img style="inline-block" src="/static/image/reply.png" align="absmiddle" border="0" alt="Reply"></a>
</span>
<p></p>
{{i.comment|safe|escape}}
</div>
</div>
<span class="sep"></span>
{% endfor %}
</div>

<div class="card">
<h4>{{operation}}文章</h4>
<span class="sep margintop"></span>
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
<form method="post">
{% csrf_token %}
<input type='hidden' name="article" value="{{art.id}}" />
<input type='hidden' name="user" value="{{request.user.id}}" />
<input type='hidden' name="ip" value="1.1.1.1" />

{{comment_form.comment}}
<button class="btn btn-default pull-right" type="submit">发表</button>
<form method="post" class="form-inline textarea" novalidate>
{% csrf_token %}
<input type="hidden" name="author_id" value="{{request.user.id}}">
<p>{{article_form.section}} - {{article_form.title}} - {{article_form.author}}</p>
<p>上传封面图片 : {{article_form.cover}}</p>
<span class="sep margintop"></span>
<p>正文</p>
{{article_form.detail}}
<p></p>
{{article_form.tag}}
<p></p>
<button class="btn btn-default pull-right" type="submit">发布</button>
</form>
</div>

<div class="card margintop article-content">
<div class="ad1"> <h3>广告位</h3> </div>
{{art.detail|safe|escape }}
</div>

{% endblock %}
2 changes: 2 additions & 0 deletions article/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
urlpatterns = [
#path('', views.homepage),
path('<int:article_id>/', views.detail, name='detail'),
path('publish/', views.publish, name='publish'),
path('update/<int:article_id>/', views.update, name='update'),
]
58 changes: 47 additions & 11 deletions article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.template import RequestContext,Template,Context,loader,defaultfilters
from django.contrib import messages
from .models import *
from edconline import globalarg


# Create your views here.

Expand All @@ -19,21 +19,23 @@ def detail(request, article_id):

if request.method == 'POST':
comment_form = CommentForm(request.POST,instance=None)
print(comment_form)

if comment_form.is_valid():
instance = comment_form.save(commit=False)
instance.ip = request.META['REMOTE_ADDR']
instance.save()
return redirect('.')
else:
messages.error(request, 'Please correct the error below.')

instance = comment_form.save(commit=False)
instance.ip = request.META['REMOTE_ADDR']

instance.save()
return redirect('.')
#else:
# messages.error(request, 'Please correct the error below.')
else:
art.readtime = art.readtime + 1
art.save(update_fields=['readtime'])
comment_form = CommentForm(instance=None)


return render(request,'article/detail.html',{'art':art,'comments':comments,'comment_form':comment_form},[globalarg.settings])
return render(request,'article/detail.html',{'art':art,'comments':comments,'comment_form':comment_form})
#return HttpResponse("You're looking at article %s." % article_id)


Expand All @@ -45,10 +47,44 @@ def publish(request):
instance = article_form.save(commit=False)
instance.ip = request.META['REMOTE_ADDR']
art = instance.save()
return redirect('/article/%d/' % (art.pk,))


return redirect('/article/%d/' % (instance.pk,))
else:
messages.error(request, 'Please correct the error below.')
else:
article_form = ArticleForm(instance=None)

return render(request,'article/publish.html',{'article_form':article_form},[globalarg.settings])
return render(request,'article/publish.html',{'article_form':article_form,'operation':'发布'})


def update(request, article_id):
art = Article.objects.get(pk=article_id)
if request.method == 'POST':
article_form = ArticleForm(request.POST,instance=art)

if article_form.is_valid():
instance = article_form.save(commit=False)
instance.ip = request.META['REMOTE_ADDR']
art = instance.save()

return redirect('/article/%d/' % (article_id,))
else:
messages.error(request, 'Please correct the error below.')
else:
article_form = ArticleForm(instance=art)

return render(request,'article/publish.html',{'article_form':article_form,'operation':'编辑'})













Binary file modified db.sqlite3
Binary file not shown.
Binary file modified edconline/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file modified edconline/__pycache__/views.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion edconline/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
#'edconline.edconline.global.settings',
'edconline.globalarg.settings',
],
},
},
Expand Down
4 changes: 2 additions & 2 deletions edconline/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.shortcuts import render
from django.http import HttpResponse,HttpResponseRedirect
from django.db.models import Q
from django.template import Template,Context,loader,defaultfilters
from django.template import Template,defaultfilters,RequestContext
from django.shortcuts import render_to_response
from article.models import *
import os,random
Expand Down Expand Up @@ -30,6 +30,6 @@ def homepage(request):
else:
arts = Article.objects.all().order_by('-publish_time')

return render(request,'index.html',{'cover':cover,'username':username,'arts':arts},[globalarg.settings])
return render(request,'index.html',{'cover':cover,'arts':arts})


Binary file added static/avatar/raven.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/avatar/raven_kYfHOfu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/avatar/wolf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions static/bootstrap/css/bootstrap-tagsinput-typeahead.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.twitter-typeahead .tt-query,
.twitter-typeahead .tt-hint {
margin-bottom: 0;
}

.twitter-typeahead .tt-hint
{
display: none;
}

.tt-menu {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
list-style: none;
font-size: 14px;
background-color: #ffffff;
border: 1px solid #cccccc;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
background-clip: padding-box;
cursor: pointer;
}

.tt-suggestion {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #333333;
white-space: nowrap;
}

.tt-suggestion:hover,
.tt-suggestion:focus {
color: #ffffff;
text-decoration: none;
outline: 0;
background-color: #428bca;
}
Loading

0 comments on commit aad1686

Please sign in to comment.