Example #1
0
def render(template_name, **kwargs):
    global _template_lookup, _media_base_url
    mytemplate = _template_lookup.get_template(template_name)
    
    # Global functions
    kwargs["_"] = _
    kwargs["session"] = controller.session 

    # Check if we need to use a lang prefix
    kwargs["pagename"] = pagename()
    kwargs["base_url"] = controller.base_url()
    kwargs["self_url"] = controller.self_url()
    kwargs["release"] = controller.selected_release
    kwargs["media_base_url"] = _media_base_url
    kwargs["current_release"] = controller.current_release
    kwargs["login_username"] = controller.session('login_username')    
    
    start_t = time.time()
    template_output = mytemplate.render(**kwargs)
    stop_t =  time.time()
    if not template_name.endswith('.mail'):
        template_output += '\n<!-- Template %s rendering took %0.3f ms -->\n' % \
            (template_name, (stop_t-start_t)*1000.0)
    return template_output
Example #2
0
def updates_page(distro, release, **kwargs):
    """ Builds the updates page """

    try:
        page = int(kwargs.get("page", 1))
    except ValueError:
        page = 1
    updates_release = release
    q = kwargs.get("q", None)
    category_name = kwargs.get("category", None)
    format = kwargs.get("format", None)
    category = None
    categories = ApplicationsCategory.query.all()
    if category_name:
        category = ApplicationsCategory.query.filter_by(
            name=category_name).first()
        if not category:
            controller.http_redirect(controller.base_url()+"/updates/Ubuntu/" + \
                controller.current_release)
    codename = distroinfo.get_codename(distro, release)
    if format == "xml":
        items_per_page = 100
    else:
        items_per_page = 5
    (applications_list, package_dict, page_count) = \
        packages.get_applications_list(q = q, category = category, page = page
                                        , release = release , items_per_page = items_per_page
                                        )

    # Determine the "Available for" releases
    available_for = {}
    for app in applications_list:
        package = Package.query.filter_by( id = package_dict[app.id].id)\
             .order_by(desc(Package.last_modified)).first()
        available_for[app.id] = {}
        available_for[app.id] = []
        for packagelist in package.lists:
            if packagelist.version not in available_for[app.id]:
                available_for[app.id].append(packagelist.version)

    # Build the changelogs urls
    changelogs_dict = {}
    for app in applications_list:
        package = Package.query.filter_by( id = package_dict[app.id].id)\
             .order_by(desc(Package.last_modified)).first()
        source_package = package.source or package.package
        if source_package[:3] == 'lib':
            prefix = source_package[:4]
        else:
            prefix = source_package[:1]

        changelogs_dict[app.id] = '%s/%s/%s_%s_source.changelog' % \
            (prefix, source_package, source_package, package.version)

    # get the download stats
    download_stats = packages.get_download_stats()

    search_str = controller.self_url() + "?"
    param_str = ''
    for key, value in kwargs.iteritems():
        if key == "page":
            continue
        param_str += key + '=' + value + '&amp;'
    if param_str:
        search_str = controller.self_url() + '?' + param_str
    if format == "xml":
        return template.render('updates.xml',
                               applications_list=applications_list,
                               package_dict=package_dict,
                               available_for=available_for,
                               updates_release=updates_release,
                               changelogs_dict=changelogs_dict)
    else:
        return template.render('updates.html',
                               categories=categories,
                               applications_list=applications_list,
                               package_dict=package_dict,
                               available_for=available_for,
                               page=page,
                               page_count=page_count,
                               q=q,
                               category=category,
                               search_str=search_str,
                               updates_release=updates_release,
                               codename=codename,
                               changelogs_dict=changelogs_dict,
                               download_stats=download_stats)
Example #3
0
def updates_page(distro, release, **kwargs):
    """ Builds the updates page """
    
    try:
        page = int(kwargs.get("page", 1))
    except ValueError:
        page = 1
    updates_release = release                        
    q = kwargs.get("q", None)    
    category_name = kwargs.get("category", None)
    format = kwargs.get("format", None)
    category = None    
    categories = ApplicationsCategory.query.all() 
    if category_name:
        category = ApplicationsCategory.query.filter_by(name=category_name).first()
        if not category:
            controller.http_redirect(controller.base_url()+"/updates/Ubuntu/" + \
                controller.current_release)
    codename = distroinfo.get_codename(distro, release) 
    if format == "xml":
        items_per_page = 100
    else:
        items_per_page = 5
    (applications_list, package_dict, page_count) = \
        packages.get_applications_list(q = q, category = category, page = page 
                                        , release = release , items_per_page = items_per_page
                                        )
                        
    # Determine the "Available for" releases 
    available_for = {}
    for app in applications_list:        
        package = Package.query.filter_by( id = package_dict[app.id].id)\
             .order_by(desc(Package.last_modified)).first()
        available_for[app.id] = {}
        available_for[app.id] = []
        for packagelist in package.lists:
            if packagelist.version not in available_for[app.id]:
                available_for[app.id].append(packagelist.version)  
    
    # Build the changelogs urls
    changelogs_dict ={}
    for app in applications_list:        
        package = Package.query.filter_by( id = package_dict[app.id].id)\
             .order_by(desc(Package.last_modified)).first()
        source_package = package.source or package.package             
        if source_package[:3] == 'lib':
            prefix = source_package[:4]
        else:
            prefix = source_package[:1]
        
        changelogs_dict[app.id] = '%s/%s/%s_%s_source.changelog' % \
            (prefix, source_package, source_package, package.version)

    # get the download stats
    download_stats = packages.get_download_stats()

    search_str = controller.self_url()+"?"
    param_str = ''
    for key,value in kwargs.iteritems():
        if key == "page": 
            continue        
        param_str += key + '=' + value + '&amp;'
    if param_str:
        search_str = controller.self_url()+ '?' + param_str
    if format == "xml":
        return template.render('updates.xml' 
            , applications_list = applications_list
            , package_dict = package_dict 
            , available_for = available_for    
            , updates_release = updates_release 
            , changelogs_dict = changelogs_dict                    
        )
    else: 
        return template.render('updates.html'
            , categories = categories 
            , applications_list = applications_list 
            , package_dict = package_dict 
            , available_for = available_for 
            , page = page 
            , page_count = page_count 
            , q = q 
            , category = category 
            , search_str = search_str
            , updates_release = updates_release
            , codename = codename
            , changelogs_dict = changelogs_dict
            , download_stats=download_stats
    )