Skip to content

Commit

Permalink
Merge branch 'release/0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
jose ariza committed Sep 6, 2016
2 parents 32e7c51 + e859a38 commit 69ae920
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 14 deletions.
18 changes: 15 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ Django Wordpres API
.. image:: https://coveralls.io/repos/github/swappsco/django-wordpress-api/badge.svg?branch=master
:target: https://coveralls.io/github/swappsco/django-wordpress-api?branch=master

.. image:: https://readthedocs.org/projects/django-wordpress-api/badge/?version=latest
:target: http://django-wordpress-api.readthedocs.io/en/latest/?badge=latest


Easily Install your Wordpress blog in your Django project

This package allows to communicate easily with any wordpress proyect that is using [WP REST API v1](http://wp-api.org/index-deprecated.html). Even though the WP REST API package is already on the 2 version; it is still on beta so it was decided that this package will only support v1 until v2 is out of beta.

Documentation
-------------

Expand All @@ -28,12 +33,18 @@ Install Django Wordpres API::

Then use it in a project::

import wordpress
import wordpress_api

Features
--------

* TODO
* Connect to an external wordpress application
* Retreives all the blog posts ordered by pages
* Filter blog posts using several of the [available filters in WP REST API](http://wp-api.org/index-deprecated.html#posts_retrieve-posts)
* Search blog posts using a keyword
* order the blog posts by several attributes like author, title, type, etc; ascending and descending order (default order is descending date)
* Retreive posts with a different type than "post"
* Four Views to display the blog page, The Post detail, The Posts filtered by category and the Posts filtered by tag; All of this with the search by keyword option

Running Tests
--------------
Expand All @@ -43,8 +54,9 @@ Does the code actually work?
::

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements.txt
(myenv) $ pip install -r requirements_test.txt
(myenv) $ python runtests.py
(myenv) $ python manage.py test

Credits
---------
Expand Down
14 changes: 7 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
parent = os.path.dirname(cwd)
sys.path.append(parent)

import wordpress
import wordpress_api

# -- General configuration -----------------------------------------------------

Expand All @@ -46,17 +46,17 @@
master_doc = 'index'

# General information about the project.
project = u'Django Wordpres API'
project = u'Django Wordpress API'
copyright = u'2016, Swapps'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = wordpress.__version__
version = wordpress_api.__version__
# The full version, including alpha/beta/rc tags.
release = wordpress.__version__
release = wordpress_api.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -192,7 +192,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-wordpress-api.tex', u'Django Wordpres API Documentation',
('index', 'django-wordpress-api.tex', u'Django Wordpress API Documentation',
u'Swapps', 'manual'),
]

Expand Down Expand Up @@ -222,7 +222,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-wordpress-api', u'Django Wordpres API Documentation',
('index', 'django-wordpress-api', u'Django Wordpress API Documentation',
[u'Swapps'], 1)
]

Expand All @@ -236,7 +236,7 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'django-wordpress-api', u'Django Wordpres API Documentation',
('index', 'django-wordpress-api', u'Django Wordpress API Documentation',
u'Swapps', 'django-wordpress-api', 'One line description of project.',
'Miscellaneous'),
]
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Contents:

readme
installation
integration
usage
contributing
authors
Expand Down
29 changes: 29 additions & 0 deletions docs/integration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Integration
===========

This section describes step by step integration of django_wordpress_api with your application.


Configure django-wordpress_api inside your aplication
-----------------------------------------------------

Add this app to your ``INSTALLED_APPS`` in your settings file::

INSTALLED_APPS += ('wordpress_api',)


You need two settings variables to be able to use the package:

::

WP_URL = http://your-wordpress-app.com/
BLOG_POSTS_PER_PAGE = <number-of-blogs-to-display-per-page>

Remmember to add [WP REST API v1](http://wp-api.org/index-deprecated.html) to http://your-wordpress-app.com/ or this package will be useless.


Add django-wordpress-api
------------------------
Add django-plans urls to your URL general configuration::

url(r'^blog/', include('wordpress_api.urls')),
18 changes: 17 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ Usage

To use Django Wordpres API in a project::

import wordpress
import wordpress_api

The django-wordpress-api has two main features:

the WPApiConnector and the Views that uses it.

If you want to use the pre defined views, just add wordpress-api-urls to your project.

The basic django-wordpress-api urls are::

::
http://localhost:8000/blog/; display the blog list
http://localhost:8000/(?P<slug>[-\w]+)/; displays the detail of a blog identified with the given slug
http://localhost:8000/category/(?P<slug>[-\w]+)/; displays the blogs in the category identified with the given slug
http://localhost:8000/tag/(?P<slug>[-\w]+)/; displays the blogs in the tag identified with the given slug

Else, If you want to retreive the blog posts in your custom views, you can use directly the WPApiConnector and its methods. You can check them at wordpress_api/utils.py
2 changes: 1 addition & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sites",
"wordpress",
"wordpress_api",
],
SITE_ID=1,
MIDDLEWARE_CLASSES=(),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
except ImportError:
from distutils.core import setup

version = '0.1.2'
version = '0.1.3'

if sys.argv[-1] == 'publish':
try:
Expand Down
10 changes: 9 additions & 1 deletion wordpress_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class WPApiConnector():

def __init__(self):
self.wp_url = settings.WP_URL
self.blog_per_page = settings.BLOG_POSTS_PER_PAGE

def get_posts(self, wp_filter=None, search=None,
page_number=1, orderby='date', custom_type=None):
Expand All @@ -24,7 +25,7 @@ def get_posts(self, wp_filter=None, search=None,
http://wp-api.org/index-deprecated.html#posts_retrieve-posts
"""
if self.wp_url is '':
if not self.wp_url or not self.blog_per_page:
return {'configuration_error': 'External url is not defined'}
if orderby == 'title':
order = '&filter[order]=ASC'
Expand Down Expand Up @@ -62,6 +63,10 @@ def get_posts(self, wp_filter=None, search=None,
return {'body': response.json(), 'headers': headers, }

def get_tags(self):
"""
Gets all the tags inside the wordpress application
"""

query = self.wp_url + "wp-json/taxonomies/post_tag/terms"
try:
response = requests.get(query)
Expand All @@ -77,6 +82,9 @@ def get_tags(self):
return response.json()

def get_categories(self):
"""
Gets all the categories inside the wordpress application
"""
query = self.wp_url + "wp-json/taxonomies/category/terms"
try:
response = requests.get(query)
Expand Down

0 comments on commit 69ae920

Please sign in to comment.