<commit_before># blog/rpc/metaweblog.py
# <NAME>
# 2010 July 16
# http://carsongee.com
#
# Adapted from http://www.allyourpixel.com/post/metaweblog-38-django/
#
# Modifications made:
#    Added proper authentication and authorization.
#    Added newMediaObject implementation
#    Made the getCategories call right. The returned struct was
#    lacking  htmlUrl, and rssUrl
#    Added full Blogger 1.0 API and Moveable Type API
#    Added handling for blog clients like blogtk that don't
#    always keep their different APIs straight.
#
#  General questions, what to do with constructs
#  return blogs for a site, or include authors
#  
#

from django.contrib.sites.models import Site
from blog.models import Tag, Entry, Author, DRAFT, PUBLISHED
import datetime, time

from blog.rpc.xmlrpc import public, list_public_methods
from blog.rpc.decorators import authenticated
from blog.rpc.utils import *

from django.conf import settings
from django.template.defaultfilters import slugify
from django.core.urlresolvers import reverse
import os




# Blogger 1.0 API Methods
#
#
# Complete implementation except for the template methods


@public
@authenticated()
def blogger_getUserInfo(user, appkey):
    """
    Returns a struct with userid (string), firstname, lastname,
    nickname, e-mail, and url.
    """

    return { 'userid': str(user.username), 'firstname': user.first_name,
             'lastname': user.last_name, 'nickname': user.first_name, 
             'email': user.email, 'url': user.get_absolute_url() }


@public
@authenticated()
def blogger_getUsersBlogs(user, appkey):
    """
    an array of <struct>'s containing the ID (blogid), name
    (blogName), and URL (url) of each blog.  Returning one blog
    for each defined author.
    """


    site = Site.objects.get_current()
    blogs = []

    authors = Author.objects.all()
    for author in authors:
        blogs.append( { 
                'blogid': str(author.id),
                'blogName': author.name,
                'url': 'http://%s%s' % (site.domain, 
                                        reverse("author_index", 
                                                kwargs = {'author': author.ident })),
                })
    

    return blogs

@public
@authenticated(pos=2)
def blogger_getPost(user, appkey, postid):

    return blogger_entry_struct(Entry.objects.get(id=postid), user)

@public
@authenticated(pos=2)
def blogger_getRecentPosts(user, appkey, blogid, numberOfPosts):
    entries = Entry.objects.filter(author__id=blogid).order_by('-pub_date')[:numberOfPosts]

    return [blogger_entry_struct(entry, user) for entry in entries]

@public
@authenticated(pos=2, perm="blog.add_entry")
def blogger_newPost(user, appkey, blogid, content, publish):
    """
    Blogger doesn't support titles, so we will use the standard trick of
    searching for a <title></title> tag and using that for a title. Returns
    post id.
    """

    authorid = blogid
    if not authorid:
        authorid = Author.objects.all()[0].id
    title, body = blogger_split_content(content)

    pub_date = datetime.datetime.now()
    
    entry = Entry(headline = title,
                  slug = slugify(title),
                  content = body,
                  author_id = authorid,
                  pub_date = pub_date,
                  status = publish and PUBLISHED or DRAFT,)
    entry.save()
    # No tagging in this API...at least formally
    # setTags(entry, struct)
    entry.sites.add(Site.obects.get_current())

    return entry.id

@public
@authenticated(pos=2, perm="blog.change_entry")
def blogger_editPost(user, appkey, postid, content, publish):
    entry = Entry.objects.get(id=postid)

    headline, body = blogger_split_content(content)
    entry.headline = headline
    entry.content = body
    entry.status = publish and PUBLISHED or DRAFT


    # No tags in blogger API
    # setTags(entry, struct)

    entry.save()

    return True


@public
@authenticated(pos=2, perm="blog.delete_entry")
def blogger_deletePost(user, appkey, postid, publish):
    entry = Entry.objects.get(id=postid)
    entry.delete()
    return True

    


# metaWeblog Methods
#
#
# Complete implementation from http://www.xmlrpc.com/metaWeblogApi
# and including the Movable Type extensions.


@public
@authenticated()
def metaWeblog_getCategories(user, blogid):
    """
       I have added the MovableType extensions, that should only
       come from the struct from the mt.getCategoryList method because
       some clients don't differentiate based on method call.
    """
    tags = Tag.objects.all()

    categories = []
    for tag in tags:
        category = { 'description': tag.tag,
                     'htmlUrl': full_url(
                                   reverse('tag_list', kwargs={'ident': tag.tag }), 
                                   Site.objects.get_current()),
                     'rssUrl': '',
                     'categoryName': tag.tag,
                     'categoryId': str(tag.id)
                     }
        categories.append(category)
    <commit_msg>Adding Reverse feed tag for metaweb.<commit_after># blog/rpc/metaweblog.py
# <NAME>
# 2010 July 16
# http://carsongee.com
#
# Adapted from http://www.allyourpixel.com/post/metaweblog-38-django/
#
# Modifications made:
#    Added proper authentication and authorization.
#    Added newMediaObject implementation
#    Made the getCategories call right. The returned struct was
#    lacking  htmlUrl, and rssUrl
#    Added full Blogger 1.0 API and Moveable Type API
#    Added handling for blog clients like blogtk that don't
#    always keep their different APIs straight.
#
#  General questions, what to do with constructs
#  return blogs for a site, or include authors
#  
#

from django.contrib.sites.models import Site
from blog.models import Tag, Entry, Author, DRAFT, PUBLISHED
import datetime, time

from blog.rpc.xmlrpc import public, list_public_methods
from blog.rpc.decorators import authenticated
from blog.rpc.utils import *

from django.conf import settings
from django.template.defaultfilters import slugify
from django.core.urlresolvers import reverse
import os




# Blogger 1.0 API Methods
#
#
# Complete implementation except for the template methods


@public
@authenticated()
def blogger_getUserInfo(user, appkey):
    """
    Returns a struct with userid (string), firstname, lastname,
    nickname, e-mail, and url.
    """

    return { 'userid': str(user.username), 'firstname': user.first_name,
             'lastname': user.last_name, 'nickname': user.first_name, 
             'email': user.email, 'url': user.get_absolute_url() }


@public
@authenticated()
def blogger_getUsersBlogs(user, appkey):
    """
    an array of <struct>'s containing the ID (blogid), name
    (blogName), and URL (url) of each blog.  Returning one blog
    for each defined author.
    """


    site = Site.objects.get_current()
    blogs = []

    authors = Author.objects.all()
    for author in authors:
        blogs.append( { 
                'blogid': str(author.id),
                'blogName': author.name,
                'url': 'http://%s%s' % (site.domain, 
                                        reverse("author_index", 
                                                kwargs = {'author': author.ident })),
                })
    

    return blogs

@public
@authenticated(pos=2)
def blogger_getPost(user, appkey, postid):

    return blogger_entry_struct(Entry.objects.get(id=postid), user)

@public
@authenticated(pos=2)
def blogger_getRecentPosts(user, appkey, blogid, numberOfPosts):
    entries = Entry.objects.filter(author__id=blogid).order_by('-pub_date')[:numberOfPosts]

    return [blogger_entry_struct(entry, user) for entry in entries]

@public
@authenticated(pos=2, perm="blog.add_entry")
def blogger_newPost(user, appkey, blogid, content, publish):
    """
    Blogger doesn't support titles, so we will use the standard trick of
    searching for a <title></title> tag and using that for a title. Returns
    post id.
    """

    authorid = blogid
    if not authorid:
        authorid = Author.objects.all()[0].id
    title, body = blogger_split_content(content)

    pub_date = datetime.datetime.now()
    
    entry = Entry(headline = title,
                  slug = slugify(title),
                  content = body,
                  author_id = authorid,
                  pub_date = pub_date,
                  status = publish and PUBLISHED or DRAFT,)
    entry.save()
    # No tagging in this API...at least formally
    # setTags(entry, struct)
    entry.sites.add(Site.obects.get_current())

    return entry.id

@public
@authenticated(pos=2, perm="blog.change_entry")
def blogger_editPost(user, appkey, postid, content, publish):
    entry = Entry.objects.get(id=postid)

    headline, body = blogger_split_content(content)
    entry.headline = headline
    entry.content = body
    entry.status = publish and PUBLISHED or DRAFT


    # No tags in blogger API
    # setTags(entry, struct)

    entry.save()

    return True


@public
@authenticated(pos=2, perm="blog.delete_entry")
def blogger_deletePost(user, appkey, postid, publish):
    entry = Entry.objects.get(id=postid)
    entry.delete()
    return True

    


# metaWeblog Methods
#
#
# Complete implementation from http://www.xmlrpc.com/metaWeblogApi
# and including the Movable Type extensions.


@public
@authenticated()
def metaWeblog_getCategories(user, blogid):
    """
       I have added the MovableType extensions, that should only
       come from the struct from the mt.getCategoryList method because
       some clients don't differentiate based on method call.
    """
    tags = Tag.objects.all()

    categories = []
    for tag in tags:
        category = { 'description': tag.tag,
                     'htmlUrl': full_url(
                                   reverse('tag_list', kwargs={'ident': tag.tag }), 
                                   Site.objects.get_current()),
                     'rssUrl': full_url(
                                   reverse('feed_tags', kwargs={'ident': tag.tag }), 
                                   Site.objects.get_current()),
                     'categoryName': tag.tag,
                     'categoryId': str(tag.id)
                     }
        categories.append(category)
{'fraction_non_alphanumeric': 0.10172781984080762, 'fraction_numerical': 0.0034944670937682005, 'mean_word_length': 2.6011883956658512, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '622529', 'n_tokens_mistral': 3111, 'n_tokens_neox': 2896, 'n_words': 848}