Skip to content

Commit

Permalink
update user page
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Feb 28, 2018
1 parent d152069 commit 2d446a1
Show file tree
Hide file tree
Showing 33 changed files with 757 additions and 222 deletions.
Binary file modified article/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified article/__pycache__/views.cpython-36.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions article/migrations/0014_auto_20180228_1552.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.2 on 2018-02-28 07:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('article', '0013_auto_20180226_1938'),
]

operations = [
migrations.AlterField(
model_name='comment',
name='ip',
field=models.GenericIPAddressField(blank=True, default='0.0.0.0', null=True),
),
]
Binary file not shown.
23 changes: 15 additions & 8 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,22 @@ class ArticleForm(ModelForm):
class Meta:
model = Article
fields = ['title','author','author_id','section','tag','cover','detail']
error_messages = {
'section':{'required': '请选择主题分区'},
'author':{'required': '请输入作者名称'},
'cover':{'required': '请上传封面图'},
'detail':{'required': '请输入正文内容'},
'title':{'required': '请输入文章标题'},

}
widgets = {
'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':"标题"}),

}
'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':"标题"}),
}


class Comment(models.Model):
Expand Down
79 changes: 49 additions & 30 deletions article/templates/article/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{% block header %}
<title>{{art.title}} - 物志</title>

<script type="text/javascript" src="/static/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinyMCE.init(
Expand Down Expand Up @@ -34,7 +35,7 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>

{% block content %}
<div class="card margintop article-content">
<span class="fad">作者:<a href="#"><img src="/{{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;
Expand All @@ -43,55 +44,73 @@ <h1>{% if art %}{{art.title}}{% endif %} </h1>
<span class="fad">发表于:{{art.publish_time}}</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 }}
<span class="sep margintop" ></span>
<div class="ad1"> <h3>广告位</h3> </div>
{{art.detail|safe }}
</div>

<div class="card">
<p>评论</p>
<span class="sep"></span>
{% for i in comments %}
<p>评论</p>
<span class="sep"></span>
{% for i in comments %}
<div class="comment row">
<div class="comment-avatar" style="background:url(/{{i.user.avatar}}) no-repeat;background-position:10px 20px;background-size:60px 60px;">
{{i.user}}
{{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 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>
{{i.comment|safe|escape}}

<span class="glyphicon glyphicon-time fad"> </span>&nbsp;<span class="fad">{{i.comment_time}}</span> &nbsp;&nbsp;
{% ifequal request.user.id art.author_id.id %}
<span class="ico fad" style="padding:2px;border:1px solid gray">作者</span>
{% endifequal %}
<span class="pull-right ico fad floor" id="comment_{{i.id}}"># {{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>
{{i.comment|safe|escape}}
</div>
</div>
<span class="sep"></span>
{% endfor %}
<span class="sep"></span>
{% endfor %}
</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>
{% if comment_form.errors %}
{% for field in comment_form %}
{% for error in field.errors %}
<script type="text/javascript">
$.notify({
// options
message: '{{ error|escape }}',
},{
// settings
type: 'warning',
delay: 5000,
timer: 1000,
animate: {
enter: 'animated flipInY',
exit: 'animated flipOutX'
},
},);
</script>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
{% endif %}

<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}}
{% csrf_token %}
<input type='hidden' name="article" value="{{art.id}}" />
<input type='hidden' name="user" value="{{request.user.id}}" />
{{comment_form.comment}}
<p></p>
<button class="btn btn-default pull-right" type="submit">发布</button>
<button class="btn btn-default pull-right" type="submit">发布</button>
</form>

</div>
Expand Down
31 changes: 24 additions & 7 deletions article/templates/article/publish.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
</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 %}
Expand All @@ -33,14 +35,29 @@
<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>
{% if article_form.errors %}
{% for field in article_form %}
{% for error in field.errors %}
<script type="text/javascript">
$.notify({
// options
message: '{{ error|escape }}',
},{
// settings
type: 'warning',
delay: 5000,
timer: 1000,
animate: {
enter: 'animated flipInY',
exit: 'animated flipOutX'
},
},);
</script>
{% endfor %}
</ul>
{% endif %}
<form method="post" class="form-inline textarea" novalidate>
{% endfor %}
{% endif %}

<form method="post" class="form-inline textarea" data-ajax="false" enctype="multipart/form-data" novalidate>
{% csrf_token %}
<input type="hidden" name="author_id" value="{{request.user.id}}">
<p>{{article_form.section}} - {{article_form.title}} - {{article_form.author}}</p>
Expand Down
11 changes: 4 additions & 7 deletions article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def detail(request, article_id):

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


instance = comment_form.save(commit=False)
instance.ip = request.META['REMOTE_ADDR']
Expand All @@ -41,17 +39,16 @@ def detail(request, article_id):

def publish(request):
if request.method == 'POST':
article_form = ArticleForm(request.POST,instance=None)
article_form = ArticleForm(request.POST,request.FILES,instance=None)

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


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

Expand All @@ -61,7 +58,7 @@ def publish(request):
def update(request, article_id):
art = Article.objects.get(pk=article_id)
if request.method == 'POST':
article_form = ArticleForm(request.POST,instance=art)
article_form = ArticleForm(request.POST,request.FILES,instance=art)

if article_form.is_valid():
instance = article_form.save(commit=False)
Expand All @@ -70,7 +67,7 @@ def update(request, article_id):

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

Expand Down
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified edconline/__pycache__/globalarg.cpython-36.pyc
Binary file not shown.
Binary file modified edconline/__pycache__/settings.cpython-36.pyc
Binary file not shown.
7 changes: 5 additions & 2 deletions edconline/globalarg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@


def settings(request):
secs = Section.objects.all()
return {'secs':secs}
if request.user.is_authenticated :
userid = request.user.id
user =Profile.objects.get(user=userid)
secs = Section.objects.all()
return {'secs':secs,'user':user}
11 changes: 11 additions & 0 deletions edconline/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import os
from django.contrib.messages import constants as messages

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -139,6 +140,16 @@
)



MESSAGE_TAGS = {
messages.DEBUG: 'alert-info',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}


TINYMCE_DEFAULT_CONFIG = {
'height': 360,
'width': 1120,
Expand Down
Empty file added notification/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions notification/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import *


class MsgAdmin(admin.ModelAdmin):
list_display=('id','user','mention_user','msg_time')
admin.site.register(Msg,MsgAdmin)
5 changes: 5 additions & 0 deletions notification/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class NotificationConfig(AppConfig):
name = 'notification'
Empty file.
19 changes: 19 additions & 0 deletions notification/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm,Textarea
from userpage.models import *
from article.models import *

# Create your models here.

class Msg(models.Model):
id=models.AutoField(primary_key=True)
user = models.ForeignKey(Profile, on_delete=models.CASCADE)
mention_user = models.ManyToManyField(Profile, on_delete=models.CASCADE)
comment = models.ForeignKey(Comment, on_delete=models.CASCADE)
msg_time = models.DateTimeField(auto_now_add=True,editable=False)

def __str__(self):
return self.comments


3 changes: 3 additions & 0 deletions notification/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions notification/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
23 changes: 20 additions & 3 deletions static/bootstrap/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ div.container-fluid {
padding-bottom:30px;
}

.card .comment {
}

.card .comment div {
display: inline-block;
margin:10px;
Expand Down Expand Up @@ -171,6 +168,26 @@ span.floor {
padding-bottom: 40px;
}

.card .usercard div {
display: inline-block;
margin:10px;
float:left;
}

.card .usercard .usercard-avatar {
margin:10px 0 0 20px;
width:80px;
height:80px;
}

.card .usercard .usercard-info {
float:left;
padding-right:20px;
}







Expand Down
Loading

0 comments on commit 2d446a1

Please sign in to comment.