Skip to content

Commit

Permalink
add weight feature
Browse files Browse the repository at this point in the history
  • Loading branch information
flyhigher139 committed Apr 24, 2017
1 parent 8a04165 commit 608df90
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 5 deletions.
19 changes: 17 additions & 2 deletions README.md
Expand Up @@ -15,12 +15,19 @@ OctBlog offers every function in MayBlog, and aims to do it better, its features
- admin interface
- change configurations by configuration file or environment variable
- multiple comment plugin
- RESTful API(not yet)
- User defined widgets
- Deploy with docker
- order posts by weight

## Demo

[Gevin's blog](http://gevin-oct-blog.daoapp.io/) is powered by OctBlog
[Gevin's Blog](https://blog.igevin.info/) is powered by OctBlog

## Explanation

The weight is used to order articles, and if you want to hidden an article from the article list, weight is also qualified:

The default weight for each article is 10, if a article's weight is heavier than 10, it will be firstly displayed, and if the weight is negative, the article will be never displayed in the article list

## Dependency

Expand Down Expand Up @@ -165,3 +172,11 @@ You either change settings in `app/OctBlog/config.py` file, or set environment v
## License

OctBlog is under [GPL2](https://github.com/flyhigher139/OctBlog/blob/dev/LICENSE)

## What's more

If you find a bug or want to add a new feature, just issue me.

Want to contribute? Please fork OctBlog and pull request to me.

I'm not good at frontend development, so I used a free bootstrap blog theme. If you can redesign the blog theme and admin interface, I'll appriciate your work very much!
3 changes: 2 additions & 1 deletion app/main/admin_views.py
Expand Up @@ -55,7 +55,7 @@ class PostsList(MethodView):
article_model = models.Post

def get(self, post_type='post'):
posts = self.article_model.objects.filter(post_type=post_type).order_by('-update_time')
posts = self.article_model.objects.filter(post_type=post_type).order_by('-update_time', '-weight')

if not g.identity.can(editor_permission):
posts = posts.filter(author=get_current_user())
Expand Down Expand Up @@ -171,6 +171,7 @@ def post(self, slug=None, post_type='post', is_draft=False):

post.title = form.title.data.strip()
post.slug = form.slug.data.strip()
post.weight = form.weight.data
post.raw = form.raw.data.strip()
abstract = form.abstract.data.strip()
post.abstract = abstract if abstract else post.raw[:140]
Expand Down
1 change: 1 addition & 0 deletions app/main/forms.py
Expand Up @@ -13,6 +13,7 @@
class PostForm(FlaskForm):
title = StringField('Title', validators=[Required()])
slug = StringField('Slug', validators=[Required()])
weight = IntegerField('Weight', default=10)
raw = TextAreaField('Content')
abstract = TextAreaField('Abstract')
category = StringField('Category')
Expand Down
2 changes: 2 additions & 0 deletions app/main/models.py
Expand Up @@ -44,6 +44,7 @@ class Post(db.Document):
tags = db.ListField(db.StringField(max_length=30))
is_draft = db.BooleanField(default=False)
post_type = db.StringField(max_length=64, default='post')
weight = db.IntField(default=1)

def get_absolute_url(self):
# return url_for('main.post_detail', slug=self.slug)
Expand Down Expand Up @@ -118,6 +119,7 @@ class Draft(db.Document):
tags = db.ListField(db.StringField(max_length=30))
is_draft = db.BooleanField(default=True)
post_type = db.StringField(max_length=64, default='post')
weight = db.IntField(default=10)

def save(self, *args, **kwargs):
now = datetime.datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion app/main/views.py
Expand Up @@ -45,7 +45,7 @@ def index():
return 'Hello'

def list_posts():
posts = models.Post.objects.filter(post_type='post', is_draft=False).order_by('-pub_time')
posts = models.Post.objects.filter(post_type='post', is_draft=False, weight__gt=0).order_by('-weight', '-pub_time')

tags = posts.distinct('tags')

Expand Down
2 changes: 1 addition & 1 deletion app/readme.md
Expand Up @@ -67,7 +67,7 @@ export config=prd

## Deploy OctBlog

I recommend you to deploy OctBlog by `Ubuntu + nginx + gunicorn`.
I recommend you to deploy OctBlog with `Ubuntu + nginx + gunicorn`.

[Here](http://flask.pocoo.org/docs/0.10/deploying/wsgi-standalone/) is an instruction, and it is enough.

Expand Down
6 changes: 6 additions & 0 deletions app/templates/blog_admin/post.html
Expand Up @@ -51,6 +51,12 @@
</div>
{% endif %}

<div class="form-group">
{{ form.weight.label }}
{{ form.weight(class_="form-control") }}
<!-- <span class="help-block">{{ url_for('main.post_detail', slug=display_slug) }}</span> -->
</div>

<div class="form-group">
{{ form.raw.label }}

Expand Down
2 changes: 2 additions & 0 deletions app/templates/blog_admin/posts.html
Expand Up @@ -14,6 +14,7 @@
<th>Author</th>
<th style="width: 10%">Publish</th>
<th style="width: 10%">Update</th>
<th style="width: 5%">Weight</th>
<th style="width: 5%">Actions</th>
</tr>
</thead>
Expand All @@ -28,6 +29,7 @@
<td>{{ post.author.username }}</td>
<td>{{ post.pub_time.strftime('%Y-%m-%d %H:%M:%S') }}</td>
<td>{{ post.update_time.strftime('%Y-%m-%d %H:%M:%S') }}</td>
<td>{{ post.weight }}</td>
<td>
<a href="{{ url_for('blog_admin.edit_post', slug=post.slug) }}"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> </a>
&nbsp
Expand Down

0 comments on commit 608df90

Please sign in to comment.