Planeta

  • Nuno Mariz
    Twitter
    A simple templatetag for adding to the template context a variable with the user timeline from Twitter.
    It uses the CachedContextUpdatingNode snippet for caching from Jacob Kaplan-Moss.
    The reason that is necessary to cache content is because Twitter limits the number of accesses to the API.
    This only works if the cache is enabled on your settings.py.
    class TwitterNode(CachedContextUpdatingNode):
    
        cache_timeout = 1800 # 30 Minutes, maybe you want to change this
        
        def __init__(self, username, varname):
            self.username = username
            self.varname = varname
    
        def make_datetime(self, created_at):
            return datetime.fromtimestamp(mktime(strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y')))
    
        def get_cache_key(self, context):
            return 'twitter_user_timeline_cache'
    
        def get_content(self, context):
            try:
                response = urllib.urlopen('http://twitter.com/statuses/user_timeline/%s.json' % self.username).read()
                json = simplejson.loads(response)
            except:
                return {self.varname : None}
            for i in range(len(json)):
                json[i]['created_at'] = self.make_datetime(json[i]['created_at'])
            return {self.varname : json}
        
    @register.tag
    def twitter_user_timeline(parser, token):
        bits = token.contents.split()
        if len(bits) != 4:
            raise TemplateSyntaxError, "twitter_user_timeline tag takes exactly three arguments"
        if bits[2] != 'as':
            raise TemplateSyntaxError, "second argument to twitter_user_timeline tag must be 'as'"
        return TwitterNode(bits[1], bits[3])
    Usage:
    {% twitter_user_timeline username as twitter_entries %}
    {% if twitter_entries %}
      {% for entry in twitter_entries %}
      {{ entry.created_at|date:"d M Y H:i" }} - {{ entry.text }}
      {% endfor %}
    {% endif %}
    Use the source, Luke.
  • Pedro Lima

    Here is a small extension to the manage command to make deployment of compacted javascript easier (hopefully).

    I think this is better explained with a usage example. I have the templates referring both the standard javascript files for easier debugging and compacted ones for deployment (the debug variable is the standard one and allows the split between development/deployment).

    {% if debug %}
      <script src="{{ MEDIA_URL }}js/jquery-1.2.2b.js"
         type="text/javascript"></script>
      <script src="{{ MEDIA_URL }}js/jquery.cookie.js"
        type="text/javascript"></script>
      <script src="{{ MEDIA_URL }}js/jquery.dimensions.js"
        type="text/javascript"></script> 
      <script src="{{ MEDIA_URL }}js/jquery.hoverIntent.js"
        type="text/javascript"></script>
      <script src="{{ MEDIA_URL }}js/jquery.cluetip.js"
        type="text/javascript"></script>
    {% else %}
      <script src="{{ MEDIA_URL }}js/jqbase-min.js" 
        type="text/javascript"></script>
    {% endif %}
    

    In the settings file I maintain some variables for the JSC command.

    JSC_PATH = '/path_to_media/static/js'
    
    JSC_FILES = (
        ('jqbase-min.js',('jquery-1.2.2b.js', 'jquery.cookie.js',
               'jquery.dimensions.js', 'jquery.hoverIntent.js',
               'jquery.cluetip.js')),
        ('jqui-min.js',('ui.mouse.js','ui.draggable.js',
               'ui.draggable.ext.js', 'ui.droppable.js',
               'ui.droppable.ext.js'))
    )
    
    # either jsmin or jspacker, defaults to jsmin
    JSC_METHOD = 'jsmin'
    

    The first one is the path to the javascript files, the second is a list of compacted filenames and list of files to be included in the compacted one. The third setting is the method to compact the javascript, with options being the jsmin or the jspacker.

    Then in the command line I run

    ./management.py jsc 
    

    to build the compacted files before deployment. Some command line parameters are also available, for example:

    ./management.py jsc -m jspacker -f jqbase-min.js
    

    The jsc command script (jsmin and jspacker included) must be installed according to these instructions.

    I would love to ear about other approaches.

  • Pedro Lima

    Here is a small extension to the manage command to make deployment of compacted javascript easier (hopefully).

    I think this is better explained with a usage example. I have the templates referring both the standard javascript files for easier debugging and compacted ones for deployment (the debug variable is the standard one and allows the split between development/deployment).

    {% if debug %}
      <script src="{{ MEDIA_URL }}js/jquery-1.2.2b.js"
         type="text/javascript"></script>
      <script src="{{ MEDIA_URL }}js/jquery.cookie.js"
        type="text/javascript"></script>
      <script src="{{ MEDIA_URL }}js/jquery.dimensions.js"
        type="text/javascript"></script> 
      <script src="{{ MEDIA_URL }}js/jquery.hoverIntent.js"
        type="text/javascript"></script>
      <script src="{{ MEDIA_URL }}js/jquery.cluetip.js"
        type="text/javascript"></script>
    {% else %}
      <script src="{{ MEDIA_URL }}js/jqbase-min.js" 
        type="text/javascript"></script>
    {% endif %}
    

    In the settings file I maintain some variables for the JSC command.

    JSC_PATH = '/path_to_media/static/js'
    
    JSC_FILES = (
        ('jqbase-min.js',('jquery-1.2.2b.js', 'jquery.cookie.js',
               'jquery.dimensions.js', 'jquery.hoverIntent.js',
               'jquery.cluetip.js')),
        ('jqui-min.js',('ui.mouse.js','ui.draggable.js',
               'ui.draggable.ext.js', 'ui.droppable.js',
               'ui.droppable.ext.js'))
    )
    
    # either jsmin or jspacker, defaults to jsmin
    JSC_METHOD = 'jsmin'
    

    The first one is the path to the javascript files, the second is a list of compacted filenames and list of files to be included in the compacted one. The third setting is the method to compact the javascript, with options being the jsmin or the jspacker.

    Then in the command line I run

    ./management.py jsc 
    

    to build the compacted files before deployment. Some command line parameters are also available, for example:

    ./management.py jsc -m jspacker -f jqbase-min.js
    

    The jsc command script (jsmin and jspacker included) must be installed according to these instructions.

    I would love to ear about other approaches.

  • Nuno Mariz

    Fullread updates

    Por nmariz, em 10 Janeiro 2008 09:34 - Mais entradas deste utilizador
    New features on Fullread:
    • Feeds in the latest and user bookmarks.
      • http://fullread.com/feeds/latest/[rss/atom]/ (By latest - all users)
      • http://fullread.com/feeds/[username]/[rss/atom]/ (By user)
    • List of users that bookmarked the same URL.
    • Multiple bookmarking service support.

    NOTE: If you are using a bookmarking service that is not available, please let me know: http://fullread.com/contacts/?subject=Bookmarking%20service%20support.

  • Nuno Mariz

    Fullread updates

    Por nmariz, em 10 Janeiro 2008 09:34 - Mais entradas deste utilizador
    New features on Fullread:
    • Feeds in the latest and user bookmarks.
      • http://fullread.com/feeds/latest/[rss/atom]/ (By latest - all users)
      • http://fullread.com/feeds/[username]/[rss/atom]/ (By user)
    • List of users that bookmarked the same URL.
    • Multiple bookmarking service support.

    NOTE: If you are using a bookmarking service that is not available, please let me know: http://fullread.com/contacts/?subject=Bookmarking%20service%20support.

  • Nuno Mariz

    Fullread

    Por nmariz, em 3 Janeiro 2008 18:53 - Mais entradas deste utilizador
    fullread.com
    Fullread is online. It's just a simple tool that helps you organize your online readings.
    I use del.icio.us a lot, mainly for bookmarking, but right now my account is a complete mess because I’m constantly adding links that I want to read later and I don't delete them.
    Fullread uses a simple concept: I add an URL to my account to read later, then I decide to archive, delete or add it to my del.icio.us account.
    Feel free to send me any feature request or something else.
    I hope you enjoy it.
  • Nuno Mariz

    Fullread

    Por nmariz, em 3 Janeiro 2008 18:53 - Mais entradas deste utilizador
    fullread.com
    Fullread is online. It's just a simple tool that helps you organize your online readings.
    I use del.icio.us a lot, mainly for bookmarking, but right now my account is a complete mess because I’m constantly adding links that I want to read later and I don't delete them.
    Fullread uses a simple concept: I add an URL to my account to read later, then I decide to archive, delete or add it to my del.icio.us account.
    Feel free to send me any feature request or something else.
    I hope you enjoy it.
  • Nuno Mariz

    Smallr updates

    Por nmariz, em 23 Novembro 2007 16:56 - Mais entradas deste utilizador
    After I've messed up about the domain issue(see this comments), I've just updated smallr with some features. Now provides an API to access the service by REST.
    Right now only supports JSON, XML will be is also available soon.
    A bookmarklet is also available.
  • Nuno Mariz

    Smallr updates

    Por nmariz, em 23 Novembro 2007 16:56 - Mais entradas deste utilizador
    After I've messed up about the domain issue(see this comments), I've just updated smallr with some features. Now provides an API to access the service by REST.
    Right now only supports JSON, XML will be is also available soon.
    A bookmarklet is also available.
  • Nuno Mariz

    Smallr

    Por nmariz, em 22 Novembro 2007 18:51 - Mais entradas deste utilizador
    small.net
    I've just released smallr. It lets you generate small web addresses with a keyword that make it easy to remember, will not break in emails and will never expire.
    Basically is a TinyURL clone, with a keyword addon.
    There will be an API for webservices with JSON and XML, eventually a Firefox extension.
    Test it and send me some feedback.
    I hope you enjoy it.