Esempio n. 1
0
    def seturl(self):
        '''URLとURLからフェッチして保存します'''
        user = common.currentuser()
        if not user:
            common.error(self, 404, "User not found.")
            return

        ct = models.CustomTest.all().ancestor(user).get()
        if not ct:
            ct = models.CustomTest(parent=user)

        ct.setbypost(self.request.POST)

        if not ct.rss_link:
            soup = Soup(defines.defaulttesthtml)
        else:
            result = urlfetch.fetch(ct.rss_link)
            if result.status_code != 200:
                common.error(self, 200, "Url Fetch Error")
                return
            soup = Soup(result.content)

        try: 
            ct.data = soup.prettify().decode('UTF-8')
        except ValueError, message:
            common.error(self, 200, message)
            return
Esempio n. 2
0
    def get(self):
        user = common.currentuser()
        if not user:
            common.error(self, 404, 'ユーザが見つかりません')
            return

        myfeeds = models.CustomFeed.all().ancestor(user).fetch(1000)
        template_values = {'username': user.user, 'userid': user.key().id(), 'feeds': myfeeds}
        path = os.path.join(os.path.dirname(__file__), 'templates/mypage.html')

        self.response.out.write(template.render(path, template_values))
Esempio n. 3
0
    def get(self):
        user = common.currentuser()
        if not user:
            common.error(self, 404, "User not found.")
            return

        logs = models.Log.all().order('-time').ancestor(user).fetch(1000)

        template_values = {'logs': logs}
        path = os.path.join(os.path.dirname(__file__), 'templates/log.html')

        self.response.out.write(template.render(path, template_values))
Esempio n. 4
0
    def get(self):
        user = common.currentuser()
        if not user:
            common.error(self, 404, "ユーザを確認出来ませんでした。")
            return

        ct = models.CustomTest.all().ancestor(user).get()
        if not ct:
            ct = models.CustomTest(name='custom', parent=user)
            ct.put()

        template_values = {'ct': ct}
        path = os.path.join(os.path.dirname(__file__), 'templates/customtest.html')
        
        self.response.out.write(template.render(path, template_values))
Esempio n. 5
0
    def get(self, feedname):
        u = common.currentuser()
        if not u:
            common.error(self, 404, 'not accept user')
            return

        cf = models.CustomFeed.get_by_key_name(feedname, parent=u)
        if not cf:
            common.error(self, 404, "フィードが存在しません。");
            return

        template_values = {'feedname': feedname, 'cf': cf}
        path = os.path.join(os.path.dirname(__file__), 'templates/edit.html')

        self.response.out.write(template.render(path, template_values))
Esempio n. 6
0
    def post(self):
        user = common.currentuser()
        if not user:
            common.error(self, 404, 'ユーザが見つかりません')

        newfeedname = self.request.POST['name']
        if models.CustomFeed.get_by_key_name(newfeedname, parent=user):
            common.error(self, 409, "既にページが存在します。")
            return

        cf = models.CustomFeed(parent=user, key_name=newfeedname, name=newfeedname)
        if not cf.put():
            common.error(self, 400, "フィードの作成に失敗しました。")
            return

        self.redirect("/mypage")
Esempio n. 7
0
    def setselectors(self):
        '''POSTデータをカスタムテストエンティティに保存します'''
        user = common.currentuser()
        if not user:
            common.error(self, 404, "User not found")
            return False

        ct = models.CustomTest.all().ancestor(user).get()
        if not ct:
            ct = models.CustomTest(parent=user)

        ct.setbypost(self.request.POST)

        if not ct.put():
            common.error(self, 200, "fail to save.")
            return False

        return True
Esempio n. 8
0
    def post(self):
        user = common.currentuser()
        if not user:
            common.error(self, 404, 'ユーザが見つかりません')
            return

        feedname = self.request.POST['name']
        cf = models.CustomFeed.get_by_key_name(feedname, parent=user)
        if not cf:
            common.error(self, 400, "ページは存在しません。")
            return

        cf.delete()
        if cf.is_saved():
            common.error(self, 400, "削除に失敗しました。")
            return

        self.redirect('/mypage')
Esempio n. 9
0
    def post(self, action=None):
        ''' セレクタの保存と取得を行なっている '''
        if action == 'url':
            self.seturl()
            self.redirect('/customtest')

        else :
            user = common.currentuser()

            self.setselectors()

            texts = self.getselectorstexts()
            if texts == False:
                return

            ct = models.CustomTest.all().ancestor(user).get()

            template_values = {'ct': ct, 'texts': texts}
            path = os.path.join(os.path.dirname(__file__), 'templates/customtest.html')

            self.response.out.write(template.render(path, template_values))
Esempio n. 10
0
    def post(self, feedname):
        u = common.currentuser()
        if not u:
            common.error(self, 404, 'not accept user')
            return

        feed = models.CustomFeed.get_by_key_name(feedname, parent=u)
        if not feed:
            common.error(self, 404, 'Feed not found')
            return

        try:
            feed.setbypost(self.request.POST)
        except ValueError:
            common.error(self, 200, "Invalid input data")
            return

        if not feed.put():
            common.error(self, 200, "fail to save.")
            return

        self.redirect('/edit/' + feedname)
Esempio n. 11
0
    def getselectorstexts(self):
        '''カスタムテストエンティティのセレクタ属性セットから各テキストを取得します'''
        user = common.currentuser()
        if not user:
            common.error(self, 404, "User not found")
            return False

        ct = models.CustomTest.all().ancestor(user).get()
        if not ct:
            return False

        soup = Soup(ct.data)

        texts = {}
        if ct.item_title_enable and ct.item_title_selector:
            texts['titles'] = common.selectortext(soup, ct.item_title_selector, ct.item_title_attr)
        if ct.item_link_enable and ct.item_link_selector:
            texts['links'] = common.selectortext(soup, ct.item_link_selector, ct.item_link_attr)
        if ct.item_description_enable and ct.item_description_selector:
            texts['descriptions'] = common.selectortext(soup, ct.item_description_selector, ct.item_description_attr)
        if ct.item_date_enable and ct.item_date_selector:
            texts['dates'] = common.selectortext(soup, ct.item_date_selector, ct.item_date_attr)

        return texts