Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Advanced options for kotti_blog #5

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

nightmarebadger
Copy link

A while ago I tried playing around with kotti_blog a bit and figured out it just isn't (for the lack of a better word) advanced enough to be of any real use as a blogging platform.

Now that I actually have some minor experience with creating / writing a blog, I've decided to work on this a bit :).

I'll put a list of what I would like to see and what I've already implemented here below, but be sure to drop any ideas you have here.

Sidebar

Create a sidebar that will automatically show your tags/archives etc. (on which you can actually filter).

We get the needed data directly from the Blog object methods. If we manage to cache them correctly, this should be fast (look at the problems section).

  • Create a simple sidebar using kotti.views.slots
  • Make sure sidebar only appears on blogs
  • Make sure sidebar works well even with multiple blogs
  • Automatically create a list of tags out of your posts
  • Link tags to their filters
  • Automatically create an archives list (year and month) out of your posts
  • Link archives to their filters
  • Make sure sidebar only shows the tags/dates of posts you can actually see
  • Show number of posts for a filter/archive
  • Optimise the way I'm getting the tags/archives data

Filtering

Create options for filtering on tags/archives etc.

Everything that has to do with getting the tags/archives is inside Blog object methods. I've tried to cache those calls server-side so they'd only be calculated once before changing, but I couldn't get it to work. I tried using Kotti's request_cache like in https://github.com/Kotti/Kotti/blob/master/kotti/security.py and while it worked for multiple calls inside the same view, the cache was reset each time I refreshed ... Anyway, if anyone can tell me how to use it correctly it'd be great :)

I've also created a way to filter via URL's like

/blog/categories/tag (shows only posts that have a tag named "tag")
/blog/archives/2013_12 (show only posts from December 2013)

etc., with pagination now working via URL's like

/blog/categories/tag/2 (second page with categories filters)
/blog/archives/2013_12/2 (second page with archives filters)

or simply

/blog/view/2 (second page without filters)

This is done in a kind of hackish way - I've created a "super" view that parses the URL and calls the view needed (e.g. categories list or main view with proper parameters passed in.

  • Create a tags-based filter
  • Create a date-based filter
  • Make sure the GET requests don't clash with paging ones
  • Create a "Tags" or "Categories" view (shows all tags)
  • Create an "Archives" view (shows all archives)

Misc

  • Update the look of the blog a bit and make sure we use the metadata we have (show tags on blog posts etc.) [some changes done already]
  • Add basic sharing buttons (facebook, twitter, google+) to posts
  • Add a RSS feed

Comments

  • Add comments (I guess this could be done using Disqus, but if comments are implemented into Kotti I'd rather use that)

Settings

I want to extend the settings view to also include:

  • Enable/disable sidebar (I guess this will need a server restart since it's a view pushed into the right slot)
  • Enable/disable parts of the sidebar (tags, archives)
  • Limit how many tags you want to show in the sidebar (ordered descending on the number of posts)
  • Limit how many archives you want to show in the sidebar (ordered descending on the date)
  • Enable/disable/choose which sharing buttons you want to have on your posts
  • Enable/disable RSS feed
  • Enable/disable/manage comments

Extras

Definitely not needed but would be fun extra goodies to have

  • Integrate a syntax highlighter

There are probably more things that could be done, but those were the things that sprung to mind the most. Feel free to check out what I've already done or comment on what you'd like to see.

Problems

  1. Caching: As said I've tried to cache the methods that get the data (get all tags/archives/children) but I couldn't get it to work (it worked for multiple calls inside the same view, but it started over on each refresh). For keys, we could use the blog's modification date together with your permissions (as the content could be different if you have view or admin permissions) - we would then hook into BlogEntry on_create, on_delete and on_edit (or whatever their equivalents are here) events and modify the blogs modification_date accordingly. If you have any better ideas speak up, this is the best one we could come up with currently (if you need to parse all children to get the key it's kinda pointless :P). Anyway, I'd need some help from someone more experienced on caching :).
  2. "Super" views: As mentioned above, I use some "super" views so I can use nice URL's for filtering and pagination. I don't think there is anything wrong with this method speed-wise, but it seems kinda hackish/ugly. If you have a better idea that would have the same effect I'm all ears.

month and year, ordered descending. No filtering yet
some styling changes (I think it looks much nicer/cleaner this
way, we can of course revert back to how it was)
blog posts filtered by the provided tag (kinda hacky)
blog/categories/tag1/{page-number} or
blog/view/{page-number}

It's a bit hacky and I couldn't make it work with
blog/{page-number} though ...
(note: ''.split('/') is not an empty list ... :P)
(enable/disable and nr. of categories/archives in sidebar),
categories are now sorted on post numbers. Some minor
cleaning and making sure we use "categories" everywhere
instead of "tags"
@j23d
Copy link
Member

j23d commented Dec 23, 2013

Thanks for the contribution, looks promising. The product was created while developing a costumer site, so it only fit the needs for the site. But would be great to have a full functioning blog system for Kotti. I will have a closer look to the code after the holidays, but feel free to add more commits backed with some tests. For now: Merry Christmas :)

@nightmarebadger
Copy link
Author

Cool, it'd be nice to have a second opinion on some of the stuff I did - there are some parts where I have the feeling there should be a better way (the hackish "super" views for instance) and I could really use some help in parts like caching (which I couldn't get to work any way I tried :P)

Anyway, we'll continue this when you go through the code, if I'll work on it more I'll be sure to commit/push and possibly update the PR. Merry Christmas to you too!

on the speed (in my case it was very marginally faster this
way - around 0.1s with 3000 entries when running in
development mode while using sqlite) - when we succesfully
use caching, this should be faster.
shown" option, it shows all (updated the description of
settings too)
@@ -33,6 +34,38 @@ class Blog(Document):
addable_to=[u'Document'],
)

def get_children_with_permission(self, request):
return self.children_with_permission(request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why children_with_permission is reimplemented? Should be used directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I'd need to use some extras here but it turned out I didn't - will fix this :)

<tal:block tal:repeat="tag item.tags">
<a href="${api.url(context)}categories/${tag}">${tag}</a><tal:block tal:condition="not: repeat.tag.end">,</tal:block>
</tal:block></span>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The categories should only be shown if there are tags for the blog entry.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, will add a check here

@j23d
Copy link
Member

j23d commented Jan 7, 2014

Thanks for this PR, great stuff. Some things that come up to my mind:

  • It should be possible to choose the slot where the sidebar is shown. This can be done with the default
    schema SlotSchemaNode. See https://github.com/j23d/kotti_settings#default-schemas for more info.
  • The sidebar should only be shown if there is an output.
  • The URLs in the filtering section looks good and the super methods to determine a more specific behavior seem
    fine to me. I don't think that it should be suffixed with super as this are the views that then call more specific ones.
  • For the problem with the caching I can't help right know, I also have to play with this stuff or better we ask
    @dnouri for some illumination.
  • In another project I added basic sharing buttons for the blog and the posts, so I think I can adopt it easily.
  • For the RSS feed we can use https://github.com/teixas/kotti_feed hopefully.
  • I'm not aware of a working comment addon for Kotti, but I also prefer an own addon for this.
  • Enable/disable the sidebar in the setting is possible without a server restart, see https://github.com/j23d/kotti_tagcloud/blob/master/kotti_tagcloud/widget.py for an example.
  • Tests are missing. It's necessary to have some tests for all the new features before merging it. Unit test are preferred over browser tests here.
  • Please add some lines to the changelog.

The only thing I'm really missing are the tests. Caching would be great, but can also be added later and also the misc features.

@dnouri
Copy link

dnouri commented Jan 8, 2014

On 01/07/2014 11:24 PM, Marco Scheidhuber wrote:

  • For the problem with the caching I can't help right know, I also
    have to play with this stuff or better we ask @dnouri
    https://github.com/dnouri for some illumination.

@nightmarebadger Try using "lru_cache" instead of "request_cache". It
will keep cached values inside Python process.

@nightmarebadger
Copy link
Author

Thanks for the comments, I'll probably be able to play with it a bit till the end of the week and I'll try to get it ready (tests, changelog info etc.) so it could be merged and ready for other people to tinker around with it too. Will look at the "lru_cache" to see if I manage to get it to work, if I still can't I'll just get it ready for a merge and let @dnouri handle this part, since it isn't that important until someone actually has 100+ posts at least :P

  • I'll leave sharing buttons to you @j23d since you said you already implemented something similar
  • I prefixed the views with super in an attempt to make it really transparent that they don't do anything except choose and call the appropriate view
  • I also found https://github.com/teixas/kotti_feed when looking at the RSS feed options, but didn't really get into it yet. If possible it would be good to add a feed for the whole blog and separate feeds for each category, but this can also be added at a later date (most good RSS readers allow you to filter on categories anyway)
  • As far as I know a comment system for Kotti is not made yet (we talked about it with @dnouri at the latest sprint) - but yeah, it should definitely be made as a separate addon if we're going to work on it (is there any real interest in that?). The easier way to go would be to have an option to easily set up Disqus or something similar.

I probably forgot some stuff so I'll probably write something more when I manage to look at this again :)

@dnouri
Copy link

dnouri commented Jan 8, 2014

On 01/08/2014 04:04 PM, Natan Žabkar wrote:

  • As far as I know a comment system for Kotti is not made yet (we
    talked about it with @dnouri https://github.com/dnouri at the
    latest sprint) - but yeah, it should definitely be made as a
    separate addon if we're going to work on it (is there any real
    interest in that?). The easier way to go would be to have an option
    to easily set up Disqus or something similar.

I think even kotti_disqus should be its own add-on.

@j23d
Copy link
Member

j23d commented Feb 14, 2014

@nightmarebadger: I find some time to play. I created a branch with the same name in the kotti_blog repository(https://github.com/Kotti/kotti_blog/tree/advanced-blog), included your commits there and add some small changes and tests. If you want to work on this further, please update your fork and send pull requests to the branch advanced-blog. Sorry for any inconvenience that comes with this. Could you also add your changes into the changelog?

@j23d
Copy link
Member

j23d commented Feb 14, 2014

And I included social media buttons to the blog entry view. I used the fork https://github.com/patrickheck/socialshareprivacy/ of http://www.heise.de/extras/socialshareprivacy/. The basic js and css files are included untouched into the package so it can easily be updated. Would be great to get your opinion on this.

j23d added a commit that referenced this pull request Mar 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants