Ejemplo n.º 1
0
def show_project(post_id):
    reload_init()
    if data.lookup_project(post_id)[0] == 0:            #kex err code
        logger('###Project ' + str(post_id) + ' visited')       #sends log message with post id if it exists
        return render_template('project_id.html', project = data.lookup_project(post_id)[1])        #renders the requested page
    else:
        logger('###Nonexistent project visited')            #sends err message to the log if nonexistent project
        return render_template('project_id.html', error = "Project not found")      #err msg to user
Ejemplo n.º 2
0
def index(id=None):
    data.init()

    #default template
    template = kid.Template(name=os.path.basename(__file__)[:-3],
                            title=get_text('sitename') + '-' +
                            get_text(os.path.basename(__file__)[:-3]),
                            projects=[],
                            headline=get_text(os.path.basename(__file__)[:-3]),
                            project_not_found=u'Databasen är inte tillgänglig',
                            **common_language[DEFAULT_LANGUAGE])

    if id == None:
        projects = data.retrieve_projects(sort_order='desc')

        if projects[0] == 0:
            template = kid.Template(name=os.path.basename(__file__)[:-3],
                                    title=get_text('sitename') + '-' +
                                    get_text(os.path.basename(__file__)[:-3]),
                                    projects=projects[1],
                                    headline=get_text(
                                        os.path.basename(__file__)[:-3]),
                                    project_not_found='',
                                    **common_language[DEFAULT_LANGUAGE])

    # Find project by id
    else:
        project = data.lookup_project(id)
        # Project not found
        if project[0] == 2:
            projects = data.retrieve_projects(sort_order='desc')

            if projects[0] == 0:
                template = kid.Template(
                    name=os.path.basename(__file__)[:-3],
                    title=get_text('sitename') + '-' +
                    get_text('project_not_found'),
                    projects=projects[1],
                    headline=get_text(os.path.basename(__file__)[:-3]),
                    project_not_found=get_text('project_not_found'),
                    **common_language[DEFAULT_LANGUAGE])
        # Show project by id
        else:
            project = data.retrieve_projects(search=id,
                                             search_fields=['project_no'])
            project[1][0]['techniques_used'] = ", ".join(
                project[1][0]['techniques_used'])
            template = kid.Template(
                name='projectsbyid',
                title=get_text('sitename') + '-' + get_text('projects') +
                ": " + project[1][0]['project_name'],
                headline=project[1][0]['project_name'],
                **dict(project[1][0], **common_language[DEFAULT_LANGUAGE]))

    template.cache = False

    return template.serialize(output='xhtml-strict')
Ejemplo n.º 3
0
def page_project(id):
    data.init()
    _project = data.lookup_project(id)[1]

    if _project == None:
        _project = ""
    
    data_error = data._error_meaning[data._error_code]
    return render_template("project.html", _db_data=_project, data_error=data_error)
Ejemplo n.º 4
0
def index(id=None):
    data.init()

    #default template
    template = kid.Template(name=os.path.basename(__file__)[:-3], 
                                title=get_text('sitename') + '-' + get_text(os.path.basename(__file__)[:-3]), 
                                projects=[],
                                headline=get_text(os.path.basename(__file__)[:-3]),
                                project_not_found=u'Databasen är inte tillgänglig',
                                **common_language[DEFAULT_LANGUAGE])

    if id == None:
        projects = data.retrieve_projects(sort_order='desc');
    
        if projects[0] == 0:
            template = kid.Template(name=os.path.basename(__file__)[:-3], 
                                title=get_text('sitename') + '-' + get_text(os.path.basename(__file__)[:-3]), 
                                projects=projects[1],
                                headline=get_text(os.path.basename(__file__)[:-3]),
                                project_not_found='',
                                **common_language[DEFAULT_LANGUAGE])

    # Find project by id
    else:
        project = data.lookup_project(id)
        # Project not found
        if project[0] == 2:
            projects = data.retrieve_projects(sort_order='desc');
            
            if projects[0] == 0:
                template = kid.Template(name=os.path.basename(__file__)[:-3],
                                        title=get_text('sitename') + '-' + get_text('project_not_found'),
                                        projects=projects[1],
                                        headline=get_text(os.path.basename(__file__)[:-3]),
                                        project_not_found=get_text('project_not_found'),
                                        **common_language[DEFAULT_LANGUAGE])
        # Show project by id
        else:
            project = data.retrieve_projects(search=id,search_fields=['project_no']);
            project[1][0]['techniques_used'] = ", ".join(project[1][0]['techniques_used'])
            template = kid.Template(name='projectsbyid', 
                                    title=get_text('sitename') + 
                                    '-' + 
                                    get_text('projects') + 
                                    ": " +
                                    project[1][0]['project_name'],
                                    headline=project[1][0]['project_name'],
                                    **dict(project[1][0],**common_language[DEFAULT_LANGUAGE]))
    
    template.cache = False

    return template.serialize(output='xhtml-strict')
Ejemplo n.º 5
0
def index(id):
    try:
        id = int(id)
    except ValueError:
        pass        
    project = data.lookup_project(id)[1]
    if project is not None:
        template = kid.Template(file=os.path.dirname(__file__) + os.sep + 'templates' + os.sep + 'project',project_id=project)

    else:
        template = kid.Template(file=os.path.dirname(__file__) + os.sep + 'templates' + os.sep + 'error',project_id=project)
    template.cache = False
    site.cache = False
    return template.serialize(output='xhtml-strict')
Ejemplo n.º 6
0
	
if os.path.exists(data_temp_name):
  os.rename(data_temp_name, "data.csv")

errcode, result = data.project_count()
assert errcode != 0

data.init()

os.rename("data.csv", data_temp_name)

errcode, result = data.project_count()
WORKED(errcode)
assert result == 4

errcode, result = data.lookup_project(1)
WORKED(errcode)
assert result[u'course_id'] == u'TDP003'
assert result[u'course_name'] == u'OKÄNT'
assert result[u'techniques_used'] == [u'python']

errcode, result = data.lookup_project(4)
WORKED(errcode)
assert result[u'course_id'] == u' "'
assert result[u'techniques_used'] == []
assert result[u'lulz_had'] == u'over 9000'

errcode, result = data.lookup_project(2)
WORKED(errcode)
assert result[u'project_name'] == u'2007'