コード例 #1
0
ファイル: views.py プロジェクト: yosukesuzuki/jleagusimulator
def get_article_list(browser_lang,page,article_per_page,tag_name=False):
    if tag_name:
        tag_name_encoded = unicode(tag_name)
    else:
        tag_name_encoded = str(tag_name)
    memcache_key = u'article-'+str(page)+u'-'+str(article_per_page)+u'-'+urllib.quote(tag_name_encoded.encode('utf-8'))+u'-'+browser_lang
    logging.info(memcache_key)
    results_dic = memcache.get(memcache_key)
    #if memcache data exist return
    if results_dic:
        return results_dic
    #else memcach data is none,query from datastore
    now = datetime.datetime.now()
    logging.info(now)
    query = Article.all().filter(u'lang =',DEFAULT_LANG).filter(u'display_page_flg =',True)
    if tag_name:
        query.filter(u'tags =',tag_name)
    query.filter(u'display_time <',now).order('-display_time')
    paginator = Paginator(query,article_per_page)
    try:
        results = paginator.page(page)
    except (EmptyPage,InvalidPage):
        results = paginator.page(paginator.num_pages)
    return_list = []
    for r in results.object_list:
        browser_lang_trans = None
        if browser_lang != DEFAULT_LANG:
            translations = Article.all().ancestor(r.key()).fetch(1000)
            #browser_lang_trans = None
            for trans in translations:
                if trans.lang == browser_lang:
                    browser_lang_trans = trans
                    break
            if browser_lang_trans:
                r.content = browser_lang_trans.content
                r.title = browser_lang_trans.title
        url = r.external_url if r.external_url else url_for('mainapp/show_each_article',key_name=r.key().name())
        if browser_lang_trans and browser_lang != DEFAULT_LANG:
            url += '?hl='+browser_lang
        snippet = html.strip_tags(markdown(r.content)).split('\n')[0]
        try:
            first_image = json.loads(r.images)['images'][0]['image_path']
        except:
            first_image = None
        return_list.append({'key':str(r.key()),
            'id':r.key().name(),
            'title':r.title,
            'snippet':snippet,
            'url':url,
            'first_image':first_image,
            'display_time':str(r.display_time)[:10]})
    results_dic = {'articles':return_list,
    'current_page':results.number,
    'previous_page':results.previous_page_number,
    'next_page':results.next_page_number,
    'has_next':results.has_next,
    'total_pages':results.paginator.num_pages,
    'tag_name':tag_name}
    memcache.set(memcache_key,results_dic)
    return results_dic 
コード例 #2
0
 def test_get_article(self):
     images = {'images': [{'title': '', 'image_path': '//0.0.0.0:8080/_ah/img/WIW0aePJFuNVe9x13v9rIg==', 'id': '668cf791e9e9e7f70669f4931567e3d9'}]}
     tags = ['hoge1','hoge2']
     test_data = {'key_name':'hoge','display_page_flg':True,'display_time':datetime.datetime.now(),
             'title':'hoge_title','url':'hoge_url','content':'hogehohoge\nhogehogeho\nhogehoge',
             'tags_string':','.join(tags),'tags':tags,'images':images,'lang':'en'}
     entity1 = Article(key_name=test_data['key_name'],display_page_flg=test_data['display_page_flg'],display_time=test_data['display_time'],
             title=test_data['title'],url=test_data['url'],content=test_data['content'],
             tags_string=test_data['tags_string'],tags=test_data['tags'],images=json.dumps(test_data['images']),lang=test_data['lang'])
     entity1.put()
     result = get_page_content('en','Article','hoge')
     self.assertEquals(result.title,'hoge_title')
コード例 #3
0
ファイル: index_view.py プロジェクト: rjlowes/codejockey
    def get(self, request, *args, **kwargs):
        # Fetch the latest articles and tag cloud
        recent_articles = Article.objects.order_by('-created').exclude(title='root')[:5]
        raw_tags = Article.objects.values('tags')
        tag_cloud = Article.tag_cloud(raw_tags)

        return TemplateResponse(request, 'mainapp/index/index.html', {'recent_articles': recent_articles, 'tag_cloud': tag_cloud})
コード例 #4
0
ファイル: views.py プロジェクト: yosukesuzuki/jleagusimulator
def index(request):
    key_name = 'jfoottrade2013-2014'
    page = memcache.get(key_name)
    if page is None:
        page = Article.get_by_key_name(key_name)
        if page is None:
            return render_to_response('mainapp/404.html', {})
        markdown_converted_content = markdown(page.content)
        snippet = html.strip_tags(markdown_converted_content).split('\n')[0]
        page.content = markdown_converted_content
        setattr(page,'snippet',snippet)
        try:
            first_image = json.loads(page.images)['images'][0]['image_path']
        except:
            first_image = None
        setattr(page,'first_image',first_image)
        memcache.set(key_name,page)
    return render_to_response('vapp/index.html', {'page': page})
コード例 #5
0
ファイル: fill_db.py プロジェクト: insidefree/my_site
    def handle(self, *args, **options):
        works = [
            {
                'company': 'YIT - Yedioth Information Technology',
                'position': 'Software Developer',
                'duties': 'Big prodject on DJango',
                'date_from': date(1990, 9, 1),
                'date_to': date(1990, 9, 1)
            },
            {
                'company': 'Beame.io',
                'position': 'Front End Software Developer',
                'duties': 'Java script',
                'date_from': date(1990, 9, 1),
                'date_to': date(1990, 9, 1)
            },
            {
                'company': 'Correalata Solutions Ltd.',
                'position': 'Software Developer',
                'duties':
                'Developed chart using VisJS to represent current status of network',
                'date_from': date(1990, 9, 1),
                'date_to': date(1990, 9, 1)
            },
        ]
        companies = [{
            'name':
            'YIT - Yedioth Information Technology',
            'description':
            'Yedioth Information Technologies (YIT) is an independent company, established '
            'for the purpose of serving as the Information Technologies (IT) body of Yedioth Acharonot '
            'group. During our ten years of activity we have led Yedioth Acharonot to the technology '
            'front in the press field, and in other paralleling fields. In a short period of time we '
            'have transformed from a small company providing only support to a company developing '
            'products and selling them in Israel and worldwide.',
            'country':
            'Israel',
            'city':
            'Rishon LeTsiyon',
            'site':
            'http://www.yit.co.il',
            'logo':
            '/static/images/logos/YIT.png'
        }, {
            'name':
            'Beame.io',
            'description':
            'Beame.io is the first cryptographic identity services provider'
            'that doesn\'t hold a single key. We developed a new way to'
            'verify user access privileges using a cryptographic identity '
            'that works seamlessly with mobile and IoT devices.',
            'country':
            'Israel',
            'city':
            'Tel Aviv',
            'site':
            'https://www.beame.io',
            'logo':
            '/static/images/logos/Beameio.png'
        }, {
            'name':
            'Correalata Solutions Ltd.',
            'description':
            'Correlata provides a new business-centric IT management layer that transforms IT '
            'operations and service metrics into business metrics,  helping companies gain the highest'
            'level of visibility and control on ALL their IT Infrastructure environments to senior'
            'management, ensuring companies use their Data Center infrastructure investments'
            'coordinating to their design intentions and business objectives.',
            'country':
            'Israel',
            'city':
            'Yavne',
            'site':
            'http://www.correlata.com',
            'logo':
            '/static/images/logos/Correlata.png'
        }]
        hobbies = [
            {
                'name': 'tourism'
            },
            {
                'name': 'programming'
            },
            {
                'name': 'digging -)'
            },
        ]
        studies = [
            {
                'school_name': 'Tel-Ran',
                'course_name':
                'Master of Computer Applications (MCA) Field Of Study Computer Programming',
                'date_from': date(1990, 9, 1),
                'date_to': date(1998, 6, 1)
            },
            {
                'school_name': 'Technion - Israel Institute of Technology',
                'course_name': 'Network design and security',
                'date_from': date(1998, 9, 1),
                'date_to': date(2001, 6, 1)
            },
            {
                'school_name':
                'Sevastopol National Technical University',
                'course_name':
                'Master\'s degree Field Of Study Automatics and Computer Technology department with a '
                'diploma in Systems',
                'date_from':
                date(2001, 9, 1),
                'date_to':
                date(2006, 8, 1)
            },
        ]
        articles = [{
            'type': 'javascript',
            'content': 'javascript article'
        }, {
            'type': 'python',
            'content': 'python article'
        }]
        skills = [{
            'name': 'python',
            'describe': 'completed big project'
        }, {
            'name': 'javascript',
            'describe': 'completed big project'
        }]
        about = {
            'first_name': 'Denis',
            'last_name': 'Sorokin',
            'email': '*****@*****.**',
            'phone': '+792-555-55-55',
            'story': 'Hi I am developer'
        }

        Company.objects.all().delete()
        for company in companies:
            company = Company(**company)
            company.save()

        Work.objects.all().delete()
        for work in works:
            company_name = work['company']
            company = Company.objects.get(name=company_name)
            work['company'] = company
            work = Work(**work)
            work.save()

        Hobby.objects.all().delete()
        for hobby in hobbies:
            hobby = Hobby(**hobby)
            hobby.save()

        Study.objects.all().delete()
        for study in studies:
            study = Study(**study)
            study.save()

        Skill.objects.all().delete()
        for skill in skills:
            skill = Skill(**skill)
            skill.save()

        Article.objects.all().delete()
        for article in articles:
            article = Article(**article)
            article.save()

        About.objects.all().delete()
        about = About(**about)
        about.save()
コード例 #6
0
ファイル: article_test.py プロジェクト: rjlowes/codejockey
    def test_tag_cloud_good_data(self):
        raw_tags = [{'tags': u'python programming'}, {'tags': u'Spring Java programming'}, {'tags': u'java j2ee'}, {'tags': u'java j2ee'}]

        tag_cloud = Article.tag_cloud(raw_tags)

        self.tag_cloud_asserts(tag_cloud)
コード例 #7
0
ファイル: article_test.py プロジェクト: rjlowes/codejockey
    def test_tag_cloud_bad_data(self):
        raw_tags = [{'tags': u'python, programming.'}, {'tags': u'Spr-ing Java prog**ramming'}, {'tags': u'java,,- j2ee'}, {'tags': u'java     j2ee'}]

        tag_cloud = Article.tag_cloud(raw_tags)
        self.tag_cloud_asserts(tag_cloud)