aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--mediagoblin/media_types/blog/__init__.py0
-rw-r--r--mediagoblin/media_types/blog/forms.py42
-rw-r--r--mediagoblin/media_types/blog/models.py0
-rw-r--r--mediagoblin/media_types/blog/routing.py52
-rw-r--r--mediagoblin/media_types/blog/views.py130
-rw-r--r--mediagoblin/plugins/blog/LICENCE0
-rw-r--r--mediagoblin/plugins/blog/README.srt0
-rw-r--r--mediagoblin/plugins/blog/__init__.py0
-rw-r--r--mediagoblin/plugins/blog/forms.py17
-rw-r--r--mediagoblin/plugins/blog/setup.py10
-rw-r--r--mediagoblin/plugins/blog/templates/blogpost_edit.html19
-rw-r--r--mediagoblin/plugins/blog/views.py16
-rw-r--r--mediagoblin/routing.py1
-rw-r--r--mediagoblin/templates/mediagoblin/blog/blog_edit_create.html34
15 files changed, 323 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..d6b023a9
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+mediagoblin_blog
+================
diff --git a/mediagoblin/media_types/blog/__init__.py b/mediagoblin/media_types/blog/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/mediagoblin/media_types/blog/__init__.py
diff --git a/mediagoblin/media_types/blog/forms.py b/mediagoblin/media_types/blog/forms.py
new file mode 100644
index 00000000..fa409519
--- /dev/null
+++ b/mediagoblin/media_types/blog/forms.py
@@ -0,0 +1,42 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import wtforms
+
+from mediagoblin.tools.text import tag_length_validator, TOO_LONG_TAG_WARNING
+from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
+from mediagoblin.tools.licenses import licenses_as_choices
+
+class BlogPostEditForm(wtforms.Form):
+ title = wtforms.TextField(_('Title'),
+ [wtforms.validators.Length(min=0, max=500)])
+ description = wtforms.TextAreaField(_('Content'))
+ tags = wtforms.TextField(_('Tags'), [tag_length_validator],
+ description="Seperate tags by commas.")
+ license = wtforms.SelectField(_('License'),
+ [wtforms.validators.Optional(),], choices=licenses_as_choices())
+
+class BlogEditForm(wtforms.Form):
+ title = wtforms.TextField(_('Title'),
+ [wtforms.validators.Length(min=0, max=500)])
+ description = wtforms.TextAreaField(_('Content'))
+
+
+
+
+
+
+
diff --git a/mediagoblin/media_types/blog/models.py b/mediagoblin/media_types/blog/models.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/mediagoblin/media_types/blog/models.py
diff --git a/mediagoblin/media_types/blog/routing.py b/mediagoblin/media_types/blog/routing.py
new file mode 100644
index 00000000..6d2aaa1f
--- /dev/null
+++ b/mediagoblin/media_types/blog/routing.py
@@ -0,0 +1,52 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from mediagoblin.tools.routing import add_route
+
+#URL mapping for blog-admin, where all the blog posts of a particular blog
+#are listed. providing the facility of edit, delete and view a particular blog post."
+add_route('mediagoblin.media_types.blog.blog-admin', \
+ '/u/<string:user>/b/<string:blog_name>/blog-admin', 'mediagoblin.media_types.blog.views:blog-admin')
+
+#URL mapping for creating a new blog post.
+add_route('mediagoblin.media_types.blog.blogpost.create', '/u/<string:user>/b/<string:blog_name>/create',
+ 'mediagoblin.media_types.blog.views:blog_post_edit')
+
+#URL mapping for editing an existing blog post.
+add_route('mediagoblin.media_types.blog.blogpost.edit', '/u/<string:user>/b/<string:blog_name>/p/blog_post_slug/edit',
+ 'mediagoblin.media_types.blog.views:blog_post_edit')
+
+#URL mapping for blog-collection-admin, where all the blogs of the user
+#are listed. providing the facility of edit, delete and view a blog.
+#view facility redirects to blog-admin page of that particular blog.
+add_route('mediagoblin.media_types.blog.blog-collection-admin', \
+ '/u/<string:user>/blog-collection-admin', 'mediagoblin.media_types.blog.views:blog-collection-admin')
+
+#URL mapping for creating a new blog.
+add_route('mediagoblin.media_types.blog.create', '/u/<string:user>/b/create',
+ 'mediagoblin.media_types.blog.views:blog_create')
+
+#URL mapping for editing an existing blog.
+add_route('mediagoblin.media_types.blog.create', '/u/<string:user>/b/<string:blog_name>/edit',
+ 'mediagoblin.media_types.blog.views:blog_edit')
+
+#route for gallery view of blog posts and blogs.
+
+
+
+
+
+
diff --git a/mediagoblin/media_types/blog/views.py b/mediagoblin/media_types/blog/views.py
new file mode 100644
index 00000000..5a9498cd
--- /dev/null
+++ b/mediagoblin/media_types/blog/views.py
@@ -0,0 +1,130 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from datetime import datetime
+
+from werkzeug.exceptions import Forbidden
+
+from mediagoblin import messages
+from mediagoblin import mg_globals
+
+from mediagoblin.media_types.blog import forms as blog_forms
+from mediagoblin.messages import add_message, SUCCESS
+#from mediagoblin.edit.lib import may_edit_media
+from mediagoblin.decorators import (require_active_login, active_user_from_url,
+ get_media_entry_by_id, user_may_alter_collection,
+ get_user_collection)
+from mediagoblin.tools.response import (render_to_response,
+ redirect, redirect_obj, render_404)
+from mediagoblin.tools.translate import pass_to_ugettext as _
+from mediagoblin.tools.template import render_template
+from mediagoblin.tools.text import (
+ convert_to_tag_list_of_dicts, media_tags_as_string)
+from mediagoblin.tools.url import slugify
+from mediagoblin.db.util import check_media_slug_used, check_collection_slug_used
+from mediagoblin.db.models import User, Collection
+
+@require_active_login
+def blog_create(request, media=None):
+ """
+ View to create and edit a blog
+ """
+
+ blog_form = blog_forms.BlogEditForm(request.form)
+
+ if request.method == 'POST' and blog_form.validate():
+ blog = request.db.Collection()
+
+ blog.title = unicode(blog_form.title.data)
+ blog.description = unicode(blog_form.description.data)
+ blog.creator = request.user.id
+ blog.generate_slug()
+
+ # Make sure this user isn't duplicating an existing collection
+ existing_blog_name = request.db.Collection.find_one({
+ 'creator': request.user.id,
+ 'title':blog.title})
+
+ if existing_blog_name:
+ add_message(request, messages.ERROR,
+ _('You already have a blog called "%s"!') \
+ % blog.title)
+ else:
+ blog.save()
+
+ add_message(request, SUCCESS,
+ _('Blog "%s" added!') % blog.title)
+
+ return redirect(request, "mediagoblin.user_pages.user_home",
+ user=request.user.username)
+
+ return render_to_response(
+ request,
+ 'mediagoblin/blog/blog_edit_create.html',
+ {'blog_form': blog_form,
+ 'user' : request.user,
+ 'app_config': mg_globals.app_config})
+
+
+@require_active_login
+@user_may_alter_collection
+@get_user_collection
+def blog_edit(request, collection):
+ """
+ View for editing an existing blog which is a collection of MediaEntries.
+ """
+ blog = collection
+ defaults = dict(
+ title = blog.title,
+ description = blog.description)
+ existing_blog = request.db.Collection.find_one({
+ 'creator': request.user.id,
+ 'title':blog_form.title.data})
+ if existing_blog and existing_blog.id != blog.id:
+ messages.add_message(
+ request, messages.ERROR,
+ _('You already have a blog called "%s"!') % \
+ blog_form.title.data)
+ else:
+ blog.title = unicode(blog_form.title.data)
+ blog.description = unicode(blog_form.description.data)
+
+ blog.save()
+
+ return redirect_obj(request, blog)
+
+ if request.user.is_admin \
+ and blog.creator != request.user.id \
+ and request.method != 'POST':
+ messages.add_message(
+ request, messages.WARNING,
+ _("You are editing another user's blog. Proceed with caution."))
+
+ return render_to_response(
+ request,
+ 'mediagoblin/blog/blog_edit_create.html',
+ {'blog': blog,
+ 'form': blog_form})
+
+
+
+
+
+
+
+
+
+
diff --git a/mediagoblin/plugins/blog/LICENCE b/mediagoblin/plugins/blog/LICENCE
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/mediagoblin/plugins/blog/LICENCE
diff --git a/mediagoblin/plugins/blog/README.srt b/mediagoblin/plugins/blog/README.srt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/mediagoblin/plugins/blog/README.srt
diff --git a/mediagoblin/plugins/blog/__init__.py b/mediagoblin/plugins/blog/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/mediagoblin/plugins/blog/__init__.py
diff --git a/mediagoblin/plugins/blog/forms.py b/mediagoblin/plugins/blog/forms.py
new file mode 100644
index 00000000..52af1cf1
--- /dev/null
+++ b/mediagoblin/plugins/blog/forms.py
@@ -0,0 +1,17 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import wtforms
diff --git a/mediagoblin/plugins/blog/setup.py b/mediagoblin/plugins/blog/setup.py
new file mode 100644
index 00000000..c4e0ee97
--- /dev/null
+++ b/mediagoblin/plugins/blog/setup.py
@@ -0,0 +1,10 @@
+from setuptools import setup, find_packages
+
+setup(
+ name = 'blog',
+ version = '1.0',
+ packages = find_packages();
+ include_package_data = True,
+ install_requires = [],
+ license = 'AGPLv3',
+ )
diff --git a/mediagoblin/plugins/blog/templates/blogpost_edit.html b/mediagoblin/plugins/blog/templates/blogpost_edit.html
new file mode 100644
index 00000000..fec7a9c2
--- /dev/null
+++ b/mediagoblin/plugins/blog/templates/blogpost_edit.html
@@ -0,0 +1,19 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+-#}
+{% extends "mediagoblin/base.html" %}
+
diff --git a/mediagoblin/plugins/blog/views.py b/mediagoblin/plugins/blog/views.py
new file mode 100644
index 00000000..c4e8601d
--- /dev/null
+++ b/mediagoblin/plugins/blog/views.py
@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/mediagoblin/routing.py b/mediagoblin/routing.py
index 986eb2ed..4228d29b 100644
--- a/mediagoblin/routing.py
+++ b/mediagoblin/routing.py
@@ -36,6 +36,7 @@ def get_url_map():
import mediagoblin.webfinger.routing
import mediagoblin.listings.routing
import mediagoblin.notifications.routing
+ import mediagoblin.media_types.blog.routing
for route in PluginManager().get_routes():
add_route(*route)
diff --git a/mediagoblin/templates/mediagoblin/blog/blog_edit_create.html b/mediagoblin/templates/mediagoblin/blog/blog_edit_create.html
new file mode 100644
index 00000000..385e1417
--- /dev/null
+++ b/mediagoblin/templates/mediagoblin/blog/blog_edit_create.html
@@ -0,0 +1,34 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#}
+{% extends "mediagoblin/base.html" %}
+
+{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
+
+{% block mediagoblin_content %}
+ <form action="{{ request.urlgen('mediagoblin.media_types.blog.create', user=user.username) }}"
+ method="POST" enctype="multipart/form-data">
+ <div class="form_box_xl">
+ <h1>{% trans %}Create/Edit a Blog{% endtrans %}</h1>
+ {{ wtforms_util.render_divs(blog_form) }}
+ <div class="form_submit_buttons">
+ {{ csrf_token }}
+ <input type="submit" value="{% trans %}Add{% endtrans %}" class="button_form" />
+ </div>
+ </div>
+ </form>
+{% endblock %}