예제 #1
0
파일: test_app.py 프로젝트: zofuthan/july
class TestJulyApp(object):
    def setUp(self):
        self.app = JulyApp('test', __name__)

    def test_first_register(self):
        assert self.app.first_register() == True
        assert self.app.first_register() == False

    def test_add_handler(self):
        self.app.add_handler(('/', 'TestJulyApp'))
        assert self.app.handlers == [('/', 'TestJulyApp')]
예제 #2
0
파일: service.py 프로젝트: jun0205/june
    @asynchronous
    def post(self):
        content = self.get_argument('content', None)
        user_id = self.get_argument('user', None)
        if not (content and user_id):
            self.finish('deny')
            return
        network = Social.query.get_first(service='twitter', user_id=user_id)
        if not network:
            self.finish('deny')
            return
        token = escape.json_decode(network.token)
        status = escape.utf8(content)
        self.twitter_request('/statuses/update',
                             post_args={'status': status},
                             access_token=token,
                             callback=self._on_post)

    def _on_post(self, entry):
        if not entry:
            self.finish('fail')
            return
        self.finish('ok')


handlers = [
    ('/twitter', TwitterHandler),
]

app = JulyApp('social', __name__, handlers=handlers)
예제 #3
0

class PostHandler(JulyHandler):
    def get(self, id):
        post = Post.query.filter_by(id=id).first()
        if not post:
            self.send_error(404)
            return
        self.render('post.html', post=post)


handlers = [
    ('/create', CreateHandler),
    url('/(\d+)', PostHandler, name='post'),
]

post_app = JulyApp('post',
                   __name__,
                   handlers=handlers,
                   template_folder="templates")

if __name__ == '__main__':
    from tornado.options import options
    options.sqlalchemy_master = 'sqlite:////tmp/demo.sqlite'

    from july import run_server, JulyApplication
    run_server(
        JulyApplication(handlers=handlers,
                        debug=True,
                        template_path="templates"))
예제 #4
0
파일: handlers.py 프로젝트: zofuthan/july
class MailHandler(JulyHandler):
    def check_xsrf_cookie(self):
        #: disable xsrf cookie check
        return

    def post(self):
        #: provide as a service
        #: only the server has access to this service
        if self.request.remote_ip != '127.0.0.1':
            self.send_error(403)
            return
        user = self.get_argument('user', None)
        subject = self.get_argument('subject', None)
        body = self.get_argument('body', '')
        subtype = self.get_argument('subtype', 'plain')
        if not (user and subject):
            self.send_error(403)
            logging.warn('Send mail without user or subject')
            return
        try:
            send_mail(user, subject, body, subtype=subtype)
        except Exception as e:
            logging.error(e)

        self.write('')


app = JulyApp('mail',
              __name__,
              handlers=[url('/outbox', MailHandler, name='mail-outbox')])
예제 #5
0
파일: test_app.py 프로젝트: zofuthan/july
 def setUp(self):
     self.app = JulyApp('test', __name__)
예제 #6
0
파일: test_app.py 프로젝트: zofuthan/july
 def test_register_app2(self):
     #: app without handlers
     app = JulyApp('app2', 'app2')
     assert '__july_apps__' not in self.application.settings
     self.application.register_app(app, '/app')
예제 #7
0
파일: handlers.py 프로젝트: jun0205/june
    @require_user
    def post(self):
        title = self.get_argument('title', None)
        content = self.get_argument('content', None)
        if not (title and content):
            self.flash_message('Please fill in required fields', 'error')
            self.render("create_feedback.html")
            return

        key = hashlib.md5(utf8(content)).hexdigest()
        url = cache.get(key)
        if url:
            self.redirect(url)
            return

        feedback = Feedback(title=title, content=content)
        feedback.sender = self.current_user.id

        db.session.add(feedback)
        db.session.commit()

        self.flash_message('Thank you for your feedback', 'info')
        self.redirect('/')


handlers = [
    ('/create', CreateFeedbackHandler),
]

app = JulyApp('feedback', __name__, handlers=handlers)
예제 #8
0
파일: test_app.py 프로젝트: zofuthan/july
 def test_register_app1(self):
     app = JulyApp('app1', __name__)
     app.add_handler(('', 'joking'))
     self.application.register_app(app, '/app')
예제 #9
0
파일: handlers.py 프로젝트: jun0205/june
        sidebar = Storage.get('sidebar')
        return sidebar or ''


class SiteInfoModule(UIModule):
    def render(self):
        _ = self.handler.locale.translate
        member = Member.query.count()
        topic = Topic.query.count()
        node = Node.query.count()
        reply = Reply.query.count()
        html = '<ul>'
        html += '<li>%s: %s</li>' % (_('Member'), member)
        html += '<li>%s: %s</li>' % (_('Node'), node)
        html += '<li>%s: %s</li>' % (_('Topic'), topic)
        html += '<li>%s: %s</li>' % (_('Reply'), reply)
        html += '</ul>'
        return html


modules = {
    'Sidebar': SidebarMoudle,
    'SiteInfo': SiteInfoModule,
}

app = JulyApp('dashboard',
              __name__,
              handlers=handlers,
              ui_modules=modules,
              template_folder='templates')
예제 #10
0
            following = True
        else:
            following = False

        return self.render_string('module/node.html',
                                  node=node,
                                  following=following)


class FollowingNodesModule(UIModule):
    def render(self, user_id):
        fs = FollowNode.query.filter_by(user_id=user_id).values('node_id')
        node_ids = (f[0] for f in fs)
        nodes = Node.query.filter_by(id__in=node_ids).all()
        return self.render_string('module/node_list.html', nodes=nodes)


class RecentAddNodesModule(UIModule):
    def render(self):
        nodes = Node.query.order_by('-id')[:20]
        return self.render_string('module/node_list.html', nodes=nodes)


app_modules = {
    'Node': NodeModule,
    'FollowingNodes': FollowingNodesModule,
    'RecentAddNodes': RecentAddNodesModule,
}

app = JulyApp('node', __name__, handlers=app_handlers, ui_modules=app_modules)
예제 #11
0
파일: handlers.py 프로젝트: jun0205/june
    ('/password', PasswordHandler),
    ('/message', MessageHandler),
]


class RecentMembersModule(UIModule):
    def render(self):
        users = Member.query.order_by('-id').limit(12)
        return self.render_string('module/member_cell.html', users=users)


modules = {
    'RecentMembers': RecentMembersModule,
}

app = JulyApp('account', __name__, handlers=handlers, ui_modules=modules)


class MembersHandler(UserHandler):
    def head(self):
        pass

    def get(self):
        p = self.get_argument('p', 1)
        pagination = Member.query.order_by('-reputation').paginate(p, 80)
        self.render('member_list.html', pagination=pagination)


class CityMembersHandler(UserHandler):
    def head(self):
        pass
예제 #12
0
파일: handlers.py 프로젝트: jun0205/june
        backend = import_object(options.image_backend)
        backend.save(body, filename, self._on_post)

    def _on_post(self, result):
        if result:
            self.write('{"stat":"ok", "url":"%s"}' % result)
        else:
            self.write('{"stat":"fail", "msg": "server error"}')
        self.finish()


handlers = [
    ('/', LatestHandler),
    ('/following', FollowingHandler),
    ('/popular', PopularHandler),
    ('/preview', PreviewHandler),
    ('/feed', SiteFeedHandler),
    ('/search', SearchHandler),
    ('/upload', UploadHandler),
    ('/node/(\w+)', NodeHandler),
    ('/node/(\w+)/feed', NodeFeedHandler),
    ('/member/(\w+)', MemberHandler),
    ('/~(\w+)', RedirectMemberHandler),
    ('/doc/(\w+)', DocHandler),
]

app = JulyApp('front',
              __name__,
              handlers=handlers,
              template_folder='_templates')
예제 #13
0
파일: handlers.py 프로젝트: jun0205/june
    ('/(\d+)/reply', CreateReplyHandler),
    ('/(\d+)/vote', VoteTopicHandler),
]


class UserModule(UIModule):
    """UserModule

    This module contains topic and reply count,
    in this case, it is located in topic app
    """
    def render(self, user_id):
        user = Member.query.get_first(id=user_id)
        if not user:
            return ''
        topic_count = Topic.query.filter_by(user_id=user_id).count()
        reply_count = Reply.query.filter_by(user_id=user_id).count()
        user.topic_count = topic_count
        user.reply_count = reply_count
        return self.render_string('module/user.html', user=user)


app_modules = {
    'User': UserModule,
}

app = JulyApp(
    'topic', __name__, handlers=app_handlers,
    ui_modules=app_modules
)