コード例 #1
0
def import_pages(content):
    # Index page content to be references from metdata
    page_content = {item['pk']: item for item in dp.get_content(content,'pages.richtextpage')}
    # Iterate through page metadata to normalize with page content
    for item in dp.get_content(content, 'pages.page'):
        DJANGO_PAGE_LIST[item['pk']] = item
        if item['pk'] in page_content:
            DJANGO_PAGE_LIST[item['pk']]['fields']['content'] = page_content[item['pk']]['fields']['content']
        else:
            DJANGO_PAGE_LIST[item['pk']]['fields']['content'] = None
    for page in DJANGO_PAGE_LIST.values():
        _add_page(page)
コード例 #2
0
def import_applications(content):
    app_urls = {}
    for url in dp.get_content(content, 'apps.applicationurl'):
        app_urls[url['fields']['application']] = url

    for item in content:
        if item['model'] == 'apps.application':
            _add_application(item)
コード例 #3
0
def _format_app_content(app_data):
    '''
    Concatinates several previous fields into a single post body

    :param app_data: Python dict of application structure. See modelsamples/application_sample.txt
    :return:
    '''
    content = _content_start(app_data)

    content += _wrap_tag(app_data['fields']['summary'])
    content += _wrap_tag(app_data['fields']['impact_statement'])

    # If an acknowlegement exists, add that.
    if app_data['fields']['acknowledgments']:
        ackknowlegement_text = _wrap_tag('Acknowledgments:', 'strong')
        ackknowlegement_text += " %s" % app_data['fields']['acknowledgments']
        content += _wrap_tag(ackknowlegement_text)

    # If team information is there, add that.
    if app_data['fields']['team_name'] or app_data['fields']['team_description']:
        team_text = _wrap_tag("Team Information:", 'strong')
        if app_data['fields']['team_name'] :
            team_text += " " + app_data['fields']['team_name'] + ","
        if app_data['fields']['team_description']:
            team_text += " " + app_data['fields']['team_description']
        content += team_text

    # Merging links from apps.application.fields.website and apps.applicationurl
    links = []
    if app_data['fields']['website']:
        links.append(
            _wrap_tag('<a href="%s" target="blank">Project Homepage</a>' % (app_data['fields']['website']), 'li')
        )

    for item in dp.get_content(DJANGO_DATA, 'apps.applicationurl'):
        if item['fields']['application'] == app_data['pk']:
            links.append(
                _wrap_tag('<a href="%s" target="blank">%s</a>' % (
                    item['fields']['url'],
                    item['fields']['name']
                ),
                          'li')
            )

    if links:
        content += _wrap_tag('Project Links', 'h3')
        content += _wrap_tag(''.join(links), 'ul')
    return _clean_text(content)
コード例 #4
0
def _add_blogpost(post_data):
    '''
    Adds a blog post parsed from blog.blogpost

    Model published status codes are as follows:  PUBLISHED = 1, DRAFT = 2, DELETED = 3

    :param post_data: Python dict of post structure.  See modelsamples/blogpost_sample.txt for structure.
    :return:
    '''
    post = WordPressPost()
    post.title = post_data['fields']['title']
    post.content = post_data['fields']['content']
    post.date = _return_datetime(post_data['fields']['publish_date'])
    post.date_modified = _return_datetime(post_data['fields']['updated'])
    post.slug = post_data['fields']['slug']
    if post_data['fields']['status'] == 2:
        post.post_status = 'publish'
    # Assign Author
    if post_data['fields']['user']:
        wp_userid = _get_wordpress_user_id_by_email(_get_django_user_email_by_id(post_data['fields']['user']))
        if wp_userid:
            post.user = wp_userid
    # TODO set catagories and tags to proper taxonomy
    post.terms_names = {
        'category': ['Blogpost']
    }
    if post_data['fields']['categories']:
        categories = []
        for category in dp.get_content(DJANGO_DATA, 'blog.blogcategory'):
            if category['pk'] in post_data['fields']['categories']:
                categories.append(category['fields']['title'])
        post.terms_names['post_tag'] = categories
    try:
        if post_data['fields']['status'] != 3:
            post.id = API.call(NewPost(post))
            print("created post", post.id, post.title)
    except Fault as err:
        pprint(post)
        print(err.faultCode, err.faultString)
コード例 #5
0
def _content_start(app_data):
    '''
    This parses the application media associated with the application and determines if there is a embedded video
    that can start the content, otherwise returns a blank string.

    :param app_data:
    :return: Media embed string or blank string
    '''
    def _get_pk(elm):  # sorting function for list sort below.
        return elm['pk']

    media_list = []
    for item in dp.get_content(DJANGO_DATA, 'apps.applicationmedia'):
        if item['fields']['application'] == app_data['pk']:
            media_list.append(item)
    media_list.sort(key=_get_pk)

    content = []
    for item in media_list:
        if item['fields']['url']:
            content.append('[embed]%s[/embed]' % item['fields']['url'])

    return '\n'.join(content) or ''
コード例 #6
0
def import_blogposts(content):
    for post in dp.get_content(content, 'blog.blogpost'):
        _add_blogpost(post)
コード例 #7
0
def _get_django_user_email_by_id(id):
    email = None
    for user in dp.get_content(DJANGO_DATA, 'profiles.user'):
        if user['pk'] == id:
            email = user['fields']['email']
    return email
コード例 #8
0
def _get_hub_byid(hub_id):
    for hub in dp.get_content(DJANGO_DATA, 'hubs.hub'):
        if hub['pk'] == hub_id:
            return hub['fields']['name']
    return None