Git recent commits template tag

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    from git import *
    
    from django.conf import settings
    from django.template import Library, Node
    register = Library()
    
    class LatestCommitsNode(Node):
        def __init__(self, num, varname):
            self.num, self.varname = num, varname
    
        def render(self, context):
            repo = Repo(settings.REPO)
            context[self.varname] = repo.commits()[-self.num:]
            return ''
    
    @register.tag        
    def get_recent_commits(parser, token):
        bits = token.contents.split()
        if len(bits) != 4:
            raise TemplateSyntaxError, "get_recent_commits tag takes exactly three arguments"
        if bits[2] != 'as':
            raise TemplateSyntaxError, "second argument to get_recent_commits tag must be 'as'"
        return LatestCommitsNode(int(bits[1]), bits[3])

More like this

  1. Template filter that divides a list into exact columns by davmuz 1 year, 4 months ago
  2. Paginator TemplateTag by trbs 5 years, 1 month ago
  3. Recurse template tag for Django by Zarin 5 years, 3 months ago
  4. BetterForm with fieldsets and row_attrs by carljm 4 years, 3 months ago
  5. Notifications Middleware for Session-Backed Messages by tclineks 4 years, 9 months ago

Comments

(Forgotten your password?)