NicholasStudt

Changeset 352


Ignore:
Timestamp:
07/18/10 21:05:52 (7 weeks ago)
Author:
nicholas
Message:

RPC Import

Location:
Python/blog/trunk
Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • Python/blog/trunk/AUTHORS

    r348 r352  
    22 
    33        * Nicholas Studt <nicholas@nicholasstudt.com> 
     4 
     5RPC Support 
     6         
     7        * Carson Gee http://carsonegee.com 
  • Python/blog/trunk/Changes

    r350 r352  
    331.3 
    44 - Added {% csrf_token %} to search. 
    5  
     5 - RPC support for Blogger 1.0, MetaWeblog, and MoveableType (Patch 
     6   provided by Carson Gee.) 
     7  
    681.2 (May  3 2010): 
    79 - Added author list page, which shows all authors. 
  • Python/blog/trunk/INSTALL

    r331 r352  
    8484      
    8585     </style> 
     86 
     87* Configure RPC  
     88 
     89  By default, uploads to settings.MEDIA_ROOT/[datestamp]_[orig_name]. 
     90        
     91  If settings.BLOG_RPC_UPLOAD_PATH is set to a tuple, I will run 
     92  strftime against it, and append the passed in filename to the end of 
     93  the time format string. The tuple should be ( file_path, url_path ) 
     94 
     95  If you set settings.BLOG_RPC_UPLOAD_PATH as a python callable, I will 
     96  call it with **kwargs set at {user: django user object, author_id: 
     97  blog author id, name: file name to upload } which must return a tuple 
     98  that is a valid path and URL to that path. 
     99 
     100  Two settings.py examples: 
     101 
     102  1)  
     103    BLOG_RPC_UPLOAD_PATH = ("/home/cgee/tmp/blog/%Y/%m/%d/", "/static_media/%Y/%m/%d/") 
     104 
     105  2) 
     106    import time 
     107        def rpc_path(**kwargs): 
     108                base_path = time.strftime('%d/%m/%Y/', time.localtime()) 
     109                base_path = "%s%s/%s" % (base_path, 
     110                                                                 kwargs['user'].username, 
     111                                                                 kwargs['name']) 
     112                return ("/home/cgee/tmp/blog/%s" % base_path,  
     113                                "/static_media/%s" % base_path) 
     114 
     115        BLOG_RPC_UPLOAD_PATH = rpc_path 
     116 
  • Python/blog/trunk/blog/templatetags/blog.py

    r346 r352  
    4242        return '' 
    4343 
     44class Calendar(template.Node): 
     45    def __init__(self, var_name, kind='month', limit=None, author=None): 
     46        self.var_name = var_name 
     47        self.kind = kind 
     48        self.limit = limit  
     49        self.author = author  
     50 
     51    def render(self, context): 
     52        author = None 
     53 
     54        if self.author: 
     55            try:  
     56                author = Author.objects.get(ident=self.author) 
     57            except ObjectDoesNotExist:  
     58                pass 
     59 
     60        if author: 
     61            list = Entry.objects.published(author=author).dates('pub_date', self.kind, order='DESC') 
     62        else:  
     63            list = Entry.objects.published().dates('pub_date', self.kind,  
     64                                               order='DESC') 
     65 
     66        if self.limit: 
     67            context[self.var_name] = list[:self.limit] 
     68        else: 
     69            context[self.var_name] = list 
     70        return '' 
     71 
    4472class TagList(template.Node): 
    4573    def __init__(self, var_name): 
     
    76104def entry_archive(parser, token): 
    77105    """ 
    78     List all of the tags. 
     106    Listing of of years, months, or days that have entries. 
    79107 
    80108    Example:: 
     
    112140entry_archive = register.tag(entry_archive) 
    113141 
    114 def month_cal(year=datetime.date.today().year, month=datetime.date.today().month):  
     142def month_calendar(parser, token): 
     143    """ 
     144    Create a calendar of a month with the days that have entries linked 
     145    to that day in the archive. 
     146 
     147    Example:: 
     148 
     149        {% month_calendar <year> <month> [author_ident] %} 
     150         
     151        {% load blog %} 
     152 
     153        {% month_calendar 2010 11 author_ident_here %}  
     154 
     155    """ 
     156     
     157    author = None 
     158    year = datetime.date.today().year 
     159    month = datetime.date.today().month 
     160 
     161    bits = token.contents.split() 
     162 
     163    if len(bits) < 2: 
     164        raise TemplateSyntaxError, "'%s' tag requires at least the context name to populate" % bits[0] 
     165     
     166    if len(bits) >= 3: 
     167        (limit, type) = bits[2].split(':')  
     168        try:  
     169            limit = int(limit) 
     170        except ValueError:  
     171            limit = None 
     172 
     173    if len(bits) == 4: 
     174        author = bits[3] 
     175 
     176    return Calendar(bits[1], type, limit, author) 
     177entry_archive = register.tag(entry_archive) 
     178 
     179def month_cal(parser, token): 
     180    year=datetime.date.today().year 
     181    month=datetime.date.today().month 
    115182 
    116183    # Fix this to just use calendar.* for all math. 
     
    121188 
    122189    last_day_of_calendar = datetime.date(year,month,last_day_of_month[1]) + datetime.timedelta(7 - calendar.weekday(year,month,last_day_of_month[1])) 
     190 
     191    return last_day_of_calendar 
    123192 
    124193    event_list = Entry.objects.published(pub_date__gte=first_day_of_calendar, pub_date__lte=last_day_of_calendar) 
  • Python/blog/trunk/blog/urls.py

    r339 r352  
    5353    url(r'^latest/?$', 'blog.views.entry_latest', name="entry_latest"), 
    5454 
     55    # New RPC handling 
     56    url(r'^rpc/?$', 'blog.rpc.xmlrpc.view', {'module': 'blog.rpc.metaweblog' }), 
     57 
    5558    url(r'^(?P<author>[-\w]+)/?$', 'blog.views.entry_list',  
    5659        name="author_index"), 
     
    5861    url(r'^$', 'blog.views.entry_list', name="entry_index"), 
    5962) 
    60  
Note: See TracChangeset for help on using the changeset viewer.