Beispiel #1
0
def post_save(sender, instance, created, data, old_data):
    """
    用来处理教程某个章节被评论时发送消息通知的处理
    """
    from uliweb import request
    from uliweb.utils.textconvert import text2html

    authors = instance.chapter.tutorial.authors.ids()
    if request.user.id in authors:
        authors.remove(request.user.id)

    message = u"""<p>%s 评论了教程 《<a href="/tutorial/view_chapter/%d">%s</a>》</p>
%s
""" % (
        unicode(instance.modified_user),
        instance._chapter_,
        unicode(instance.chapter),
        text2html(instance.content),
    )
    functions.send_message(request.user, authors, message, type="2")

    users = [x.id for x in functions.parse_user(instance.content)]
    diff = set(users) - set(authors)
    message = u"""<p>%s 评论教程 《<a href="/tutorial/view_chapter/%d">%s</a>》时提到了你</p>
%s
""" % (
        unicode(instance.modified_user),
        instance._chapter_,
        unicode(instance.chapter),
        text2html(instance.content),
    )
    functions.send_message(request.user, list(diff), message, type="2")
Beispiel #2
0
    def __call__(self, environ, start_response):
        profname = "%s.prof" % (environ['PATH_INFO'].strip("/").replace('/', '.'))
        profname = os.path.join(self.path, profname)
        prof = hotshot.Profile(profname)
#        prof.start()
        ret = prof.runcall(self.app, environ, start_response)
        prof.close()
        
        out = StringIO()
        old_stdout = sys.stdout
        sys.stdout = out
        
        stats = hotshot.stats.load(profname)
        #stats.strip_dirs()
        stats.sort_stats('time', 'calls')
        stats.print_stats()
        
        sys.stdout = old_stdout
        stats_str = out.getvalue()
        
        from uliweb.utils.textconvert import text2html
        text = text2html(stats_str)
        outputfile = profname + '.html'
        file(outputfile, 'wb').write(text)
        
        return ret
Beispiel #3
0
    def __call__(self, environ, start_response):
        profname = "%s.prof" % (environ['PATH_INFO'].strip("/").replace(
            '/', '.'))
        profname = os.path.join(self.path, profname)
        prof = hotshot.Profile(profname)
        #        prof.start()
        ret = prof.runcall(self.app, environ, start_response)
        prof.close()

        out = StringIO()
        old_stdout = sys.stdout
        sys.stdout = out

        stats = hotshot.stats.load(profname)
        #stats.strip_dirs()
        stats.sort_stats('time', 'calls')
        stats.print_stats()

        sys.stdout = old_stdout
        stats_str = out.getvalue()

        from uliweb.utils.textconvert import text2html
        text = text2html(stats_str)
        outputfile = profname + '.html'
        file(outputfile, 'wb').write(text)

        return ret
Beispiel #4
0
    def old_value(value, obj):
        if value:
            import pickle

            return text2html(json_dumps(pickle.loads(value)))
        else:
            return ""
Beispiel #5
0
    def reply(self):
        """
        """
        from uliweb.utils.textconvert import text2html

        user = request.POST.get('user')
        if not user:
            error('没有指定用户,无法回复')
            
        message = request.POST.get('message')
        
        functions.send_message(request.user, int(user), text2html(message))
        return json({'success':True})
Beispiel #6
0
    def reply(self):
        """
        """
        from uliweb.utils.textconvert import text2html

        user = request.POST.get('user')
        if not user:
            error('没有指定用户,无法回复')

        message = request.POST.get('message')

        functions.send_message(request.user, int(user), text2html(message))
        return json({'success': True})
Beispiel #7
0
def builds_view():
    #'by_branch','by_btype'
    vtype = request.GET.get('vtype','by_time')
    current_menu = "builds_view_%s"%(vtype)
    view_data,unknown_files = get_view_data(vtype)
    return {
        "current_menu":current_menu,
        "view_data":view_data,
        "unknown_files":unknown_files,
        "vtype":vtype,
        "header_diminish":vtype=='by_time',
        "df":text2html(cmdout("df -h"))
        }
Beispiel #8
0
    def reply(self):
        """
        """
        from uliweb.utils.textconvert import text2html

        user = request.POST.get("user")
        if not user:
            error("没有指定用户,无法回复")

        message = request.POST.get("message")

        functions.send_message(request.user, int(user), text2html(message))
        return json({"success": True})
Beispiel #9
0
 def _get_comment_data(self, obj, data=None):
     from uliweb.utils.textconvert import text2html
     from uliweb.orm import NotFound
     d = {}
     try:
         obj.modified_user
     except NotFound:
         obj.modified_user = None
         obj.save()
         
     d['username'] = unicode(obj.modified_user)
     d['image_url'] = functions.get_user_image(obj.modified_user, size=20)
     d['date'] = self._get_date(obj.modified_date)
     d['content'] = text2html(obj.content)
     return d
Beispiel #10
0
    def _get_comment_data(self, obj, data=None):
        from uliweb.utils.textconvert import text2html
        from uliweb.orm import NotFound
        d = {}
        try:
            obj.modified_user
        except NotFound:
            obj.modified_user = None
            obj.save()

        d['username'] = unicode(obj.modified_user)
        d['image_url'] = functions.get_user_image(obj.modified_user, size=20)
        d['date'] = self._get_date(obj.modified_date)
        d['content'] = text2html(obj.content)
        return d
Beispiel #11
0
def post_save(sender, instance, created, data, old_data):
    """
    用来处理教程某个章节被评论时发送消息通知的处理
    """
    from uliweb import request
    from uliweb.utils.textconvert import text2html
    
    authors = instance.chapter.tutorial.authors.ids()
    if request.user.id in authors:
        authors.remove(request.user.id)
    
    message = u"""<p>%s 评论了教程 《<a href="/tutorial/view_chapter/%d">%s</a>》</p>
%s
""" % (unicode(instance.modified_user), instance._chapter_, unicode(instance.chapter),
    text2html(instance.content))
    functions.send_message(request.user, authors, message, type='2')
    
    users = [x.id for x in functions.parse_user(instance.content)]
    diff = set(users) - set(authors)
    message = u"""<p>%s 评论教程 《<a href="/tutorial/view_chapter/%d">%s</a>》时提到了你</p>
%s
""" % (unicode(instance.modified_user), instance._chapter_, unicode(instance.chapter),
    text2html(instance.content))
    functions.send_message(request.user, list(diff), message, type='2')
Beispiel #12
0
    def send(self):
        from forms import SendMessageForm
        from uliweb.core.html import Tag
        from sqlalchemy.sql import select, func
        from uliweb.utils.textconvert import text2html

        User = get_model('user')
        form = SendMessageForm()
        if request.method == 'GET':
            SendMessageForm.users.choices = []
            return {'form': form.build, 'ok': False}
        if request.method == 'POST':
            flag = form.validate(request.POST)
            if flag:
                u = get_model('user')
                for u in form.users.data:
                    _id = int(u)
                    user = User.get(_id)

                    functions.send_message(request.user, user,
                                           text2html(form.message.data))
                flash(_('Send message successful!'))
                return redirect(url_for(MessageView.sended_list))
            else:
                #process select values
                choices = []
                for u in form.users.data:
                    _id = int(u)
                    user = User.get(_id)
                    if user:
                        choices.append((str(user.id), unicode(user)))
                SendMessageForm.users.choices = choices
                if '_' in form.errors:
                    message = form.errors['_']
                else:
                    message = _('There are something wrong, please fix them')
                flash(message, 'error')
                return {'form': form.build, 'ok': False}
Beispiel #13
0
 def send(self):
     from forms import SendMessageForm
     from uliweb.core.html import Tag
     from sqlalchemy.sql import select,func
     from uliweb.utils.textconvert import text2html
     
     User = get_model('user')
     form = SendMessageForm()
     if request.method == 'GET':
         SendMessageForm.users.choices = []
         return {'form':form.build, 'ok':False}
     if request.method == 'POST':
         flag = form.validate(request.POST)
         if flag:
             u = get_model('user')
             for u in form.users.data:
                 _id = int(u)
                 user = User.get(_id)
                 
                 functions.send_message(request.user, user, text2html(form.message.data))
             flash(_('Send message successful!'))
             return redirect(url_for(MessageView.sended_list))
         else:
             #process select values
             choices = []
             for u in form.users.data:
                 _id = int(u)
                 user = User.get(_id)
                 if user:
                     choices.append((str(user.id), unicode(user)))
             SendMessageForm.users.choices = choices
             if '_' in form.errors:
                 message = form.errors['_']
             else:
                 message = _('There are something wrong, please fix them')
             flash(message, 'error')
             return {'form':form.build, 'ok':False}
Beispiel #14
0
def generate_html(tables, apps, **kwargs):
    from uliweb import orm
    from os.path import dirname, join
    from uliweb.core.template import template_file
    from uliweb.orm import ReferenceProperty
    from uliweb.utils.textconvert import text2html
    from sqlalchemy.schema import CreateIndex

    menus = []
    for app in apps:
        section = {'name': '%s' % app, 'items': []}

        t = get_model_tables(tables, app)
        if not t: continue
        for tablename in t:
            item = {
                'app_name': app.replace('.', '_'),
                'name': tablename,
                'caption': tablename,
            }
            try:
                M = orm.get_model(tablename)
            except:
                continue

            item['label'] = getattr(M, '__verbose_name__', tablename)
            if tablename != M.tablename:
                item['caption'] += ' - ' + M.tablename

            section['items'].append(item)
        menus.append(section)

    all_tables = []
    for name, t in sorted(tables.iteritems()):
        model = {
            'name': name,
            'fields': [],
            'relations': [],
            'choices': [],
            'indexes': [],
        }
        if hasattr(t, '__appname__'):
            model['appname'] = text2html(t.__appname__)
        else:
            model['appname'] = None

        M = None
        try:
            M = orm.get_model(name)
        except:
            pass

        if getattr(M, '__verbose_name__', None):
            model['label'] = "%s(%s)" % (name,
                                         getattr(M, '__verbose_name__', None))
        else:
            model['label'] = name
        if name != getattr(M, 'tablename', name):
            model['label'] += ' - ' + M.tablename

        #Add docstring for Model
        if M.__doc__:
            model['desc'] = M.__doc__
        else:
            model['desc'] = ''

        #process indexes
        for x in t.indexes:
            model['indexes'].append(CreateIndex(x))

        star_index = 0
        for tablefield in sorted(t.c, key=lambda x: (x.name)):
            field = {
                'name': tablefield.name,
                'type': tablefield.type,
                'nullable': tablefield.nullable,
                'primary_key': tablefield.primary_key
            }
            field['reftable'] = None
            field['star'] = False
            field['label'] = "%s" % tablefield.name

            if M:
                ppp = M.properties[tablefield.name]
                if getattr(ppp, 'verbose_name', None):
                    field['label'] = "%s" % (getattr(ppp, 'verbose_name',
                                                     None))

                if getattr(ppp, 'choices', None):
                    choices_list = getattr(ppp, 'choices', None)
                    if callable(choices_list):
                        choices_list = choices_list()
                    if choices_list:
                        star_index = star_index + 1
                        model['choices'].append({
                            'index': star_index,
                            'fieldlabel': field['label'],
                            'fieldname': field['name'],
                            'list': choices_list
                        })
                        field['star'] = star_index

                if ppp and ppp.__class__ is ReferenceProperty:
                    field['reftable'] = "%s" % ppp.reference_class.tablename

            model['fields'].append(field)
        all_tables.append(model)
    database = {}
    database["menus"] = menus
    database["tables"] = all_tables
    return template_file(join(dirname(__file__), "templates/docindex.html"),
                         database)
Beispiel #15
0
 def old_value(value, obj):
     if value:
         import pickle
         return text2html(json_dumps(pickle.loads(value)))
     else:
         return ''
Beispiel #16
0
def generate_html(tables, apps, **kwargs):
    from uliweb import orm
    from os.path import dirname, join    
    from uliweb.core.template import template_file
    from uliweb.orm import ReferenceProperty
    from uliweb.utils.textconvert import text2html
    from sqlalchemy.schema import CreateIndex
    
    menus = []
    for app in apps:
        section = {
            'name': '%s' % app,
            'items': []
        }

        t = get_model_tables(tables, app)
        if not t: continue
        for tablename in t:       
            item = {
                'app_name': app.replace('.', '_'),
                'name': tablename,
                'caption': tablename,
            }
            try:
                M = orm.get_model(tablename)
            except:
                continue     
            
            item['label'] = getattr(M, '__verbose_name__', tablename)
            if tablename != M.tablename:
                item['caption'] += ' - ' + M.tablename
            
            section['items'].append(item)
        menus.append(section)
    
    
    all_tables = []
    for name, t in sorted(tables.iteritems()):
        model = {
            'name': name,
            'fields': [],
            'relations': [],
            'choices': [],
            'indexes': [],
        }
        if hasattr(t, '__appname__') :
            model['appname'] = text2html(t.__appname__)
        else :
            model['appname'] = None
        
        M = None
        try:
            M = orm.get_model(name)
        except:
            pass
    
        if getattr(M, '__verbose_name__', None):
            model['label'] = "%s(%s)" % (name, getattr(M, '__verbose_name__', None))
        else:
            model['label'] = name
        if name != getattr(M, 'tablename', name):
            model['label'] += ' - ' + M.tablename
            
        #Add docstring for Model
        if M.__doc__:
            model['desc'] = M.__doc__
        else:
            model['desc'] = ''
        
        #process indexes
        for x in t.indexes:
            model['indexes'].append(CreateIndex(x))
        
        star_index = 0
        for tablefield in sorted(t.c, key=lambda x:(x.name)):
            field = {
                'name': tablefield.name,
                'type': tablefield.type,
                'nullable': tablefield.nullable,
                'primary_key': tablefield.primary_key
            }
            field['reftable'] = None
            field['star'] = False
            field['label'] = "%s" % tablefield.name
            
            if M:
                ppp =  M.properties[tablefield.name]
                if getattr(ppp, 'verbose_name', None):
                    field['label'] = "%s" % (getattr(ppp, 'verbose_name', None))
                
                if getattr(ppp, 'choices', None):
                    choices_list = getattr(ppp, 'choices', None)
                    if callable(choices_list) :
                        choices_list = choices_list()
                    if choices_list :
                        star_index = star_index + 1
                        model['choices'].append({
                            'index': star_index , 
                            'fieldlabel':field['label'], 
                            'fieldname':field['name'], 
                            'list':choices_list})
                        field['star'] = star_index
    
                if ppp and ppp.__class__ is ReferenceProperty:
                    field['reftable'] = "%s" % ppp.reference_class.tablename


            model['fields'].append(field)
        all_tables.append(model)
    database = {}
    database["menus"] = menus;
    database["tables"] = all_tables;
    return template_file(join(dirname(__file__), "templates/docindex.html"), database)