Esempio n. 1
0
    def render_doc(self, push, current_user, pending_requests):
        doc = common.Document(title='pushmaster: push: %s %s' % (util.format_datetime(push.ptime), push.name))
        doc.funcbar(T.span('|', class_='sep'), common.push_email(push, 'Send Mail to Requesters'))

        requests = query.push_requests(push)
        push_div = self.render_push_div(current_user, push, requests, pending_requests)
        doc.body(push_div)

        doc.scripts(common.script('/js/push.js'))
        push_json = ScriptCData('this.push = %s;' % json.dumps(dict(key=str(push.key()), state=push.state)))
        doc.head(T.script(type='text/javascript')(push_json))

        return doc
Esempio n. 2
0
    def render_push_div(self, current_user, push, requests, pending_requests):
        push_div = T.div(class_='push')

        if current_user == push.owner:
            push_div(push_actions_form(push, requests)(class_='small push-action'))
        elif push.state != 'live':
            push_div(common.take_ownership_form(push)(class_='small push-action'))
            
        header = T.h1(common.display_datetime(push.ptime), T.span(class_='name')(push.name or ''), common.user_home_link(push.owner))

        if any(request.push_plans for request in requests):
            header(common.push_plans_badge())

        if any(request.js_serials for request in requests):
            header(common.js_serials_badge())

        if any(request.img_serials for request in requests):
            header(common.img_serials_badge())

        push_div(header)
        push_div(T.div(common.push_email(push, 'Mail Requesters')))
        requests_div = T.div(class_='requests')
        push_div(requests_div)

        def requests_with_state(state):
            return filter(lambda r: r.state == state, requests)

        if push.state == 'live':
            requests_div(accepted_list(requests_with_state('live')))
        else:
            def onstage_request_item(request):
                li = common.request_item(request)
                if current_user == push.owner or current_user == request.owner:
                    li(T.div(class_='actions')(mark_tested_form(request), T.span('or', class_='sep'), withdraw_form(request)))
                return li

            def withdrawable_request_item(request):
                li = common.request_item(request)
                if current_user == push.owner:
                    li(T.div(class_='actions')(withdraw_form(request)))
                return li

            def accepted_request_item(request):
                li = common.request_item(request)
                if current_user == push.owner:
                    li(T.div(class_='actions')(
                            mark_checked_in_form(request), 
                            T.span('or', class_='sep'),  
                            withdraw_form(request),
                            T.span('or', class_='sep'),
                            reject_request_link(request),
                            ))
                return li

            request_states = [
                ('Tested on Stage', requests_with_state('tested'), withdrawable_request_item),
                ('On Stage', requests_with_state('onstage'), onstage_request_item),
                ('Checked In', requests_with_state('checkedin'), withdrawable_request_item),
                ('Accepted', requests_with_state('accepted'), accepted_request_item),
                ]
            for label, subrequests, request_item in request_states:
                if subrequests:
                    if len(subrequests) > 5:
                        label = '%(label)s (%(count)d)' % {'label': label, 'count': len(subrequests)}
                    requests_div(T.h3(label), accepted_list(subrequests, request_item=request_item))

        if current_user == push.owner:
            accepted_requests = requests_with_state('accepted')
            if accepted_requests:
                requests_div(T.div('rebase-pull-branches %s' % (' '.join(['"%s"' % request.branch for request in accepted_requests if request.branch]),), class_='code'))
                    
        if push.state in ('accepting', 'onstage'):
            if pending_requests:
                pending_requests_title = ('Pending Requests (%d)' % len(pending_requests)) if len(pending_requests) > 5 else 'Pending Requests'
                push_div(T.h2(class_='pending')(pending_requests_title), push_pending_list(push, pending_requests))

        return push_div