コード例 #1
0
ファイル: user.py プロジェクト: jness/dmirr
    def delete(self, user_name=None, *a, **kw):
        u = db.query(model.User).filter_by(user_name=user_name).first()
        admins = db.query(model.Group).filter_by(group_name='dmirr_admin')\
                 .all()

        _display_name = u.display_name
        if not u:
            raise HTTPNotFound
        
        _h.protect_user_obj(u)
        
        came_from = url('/user/%s/edit' % u.user_name)
        
        if u.user_name in admins and len(admins) == 1:
            flash(_("Can not delete the only site administrator."), 'warning')
            redirect(came_from)
            
        confirmed = kw.get('confirmed', None)        
        if not confirmed:
            display_name = u.display_name
            action = url('/user/%s/delete' % u.user_name)
            return dict(errors={}, display_name=display_name, action=action, 
                        came_from=came_from)
        else:
            db.delete(u)
            transaction.commit()
            flash(_("%s and all associated data have been deleted." % \
                    _display_name), 'info')
            redirect(url('/logout_handler'))
コード例 #2
0
ファイル: host.py プロジェクト: jness/dmirr
    def put(self, host_id=None, *a, **kw):
        h = DBSession.query(Host).filter_by(id=host_id).first()
        if not h:
            raise HTTPNotFound
            
        errors  = _h.get_validation_errors()
        h.user  = request.identity['user']
        h.group = _h.get_group_by_name(kw.get('group_name', None))
        h.address = unicode(kw['address'].strip())
        h.online_status = DBSession.query(Status)\
                          .filter_by(label='Offline').first()
                          
        res = self._get_geoip_data(h.address)
        if not res:
            errors['host_address'] = "The host '%s' could not be " + \
                                     "identified via GeoIP.  Please " + \
                                     "ensure the hostname resolves" % h.address
        if errors:
            transaction.doom()
            return dict(errors=errors, host=h)

        h.city = unicode(res.get('city', None))
        h.region_name   = unicode(res.get('region_name', None))
        h.longitude     = res.get('longitude', None)
        h.latitude      = res.get('latitude', None)
        h.country_name  = unicode(res.get('country_name', None))
        h.country_code  = unicode(res.get('country_code', None))
        h.country_code3 = unicode(res.get('country_code3', None))
        h.postal_code   = res.get('postal_code', None)
        flash(_("%s updated successfully!" % kw['address']), 'info')
        redirect(url('/dashboard'))
コード例 #3
0
ファイル: project.py プロジェクト: jness/dmirr
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     group = _h.get_group_by_name(kw.get('group_name', None))
     protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
     all_protocols = DBSession.query(SyncProtocol).all()
     
     if not group:
         errors['group'] = 'Group does not exist!'
     if not protocol:
         errors['sync_protocol'] = 'Sync Protocol does not exist!'
         
     p = Project()
     p.label = unicode(re.sub(' ', '_', kw['label']).lower())
     _label = p.label
     p.display_name = unicode(kw.get('display_name', None))
     p.desc = kw.get('desc', None)
     p.url = unicode(kw.get('url', None))
     p.user = request.identity['user']
     p.sync_base_path = unicode(kw.get('sync_base_path', None))
     p.sync_flags = unicode(kw.get('sync_flags', None))
     p.group = group
     p.sync_protocol = protocol
     
     if len(errors) > 0:
         transaction.doom()
         return dict(page="project", errors=errors, project=p,
                     all_protocols=all_protocols)
     DBSession.add(p)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/project/%s/edit' % _label))
コード例 #4
0
ファイル: product.py プロジェクト: jness/dmirr
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     project = _h.get_project_by_name(kw.get('project_label', None))
     if not project:
         errors['project'] = "Project does not exist"
     
     _h.protect_obj_modify(project)
         
     _existing_p = _h.get_product_by_name(kw.get('label', None))
     if _existing_p:
         errors['label'] = "%s already exists!" % kw.get('label', None)
         
     p = Product()
     p.label = unicode(re.sub(' ', '_', kw['label']).lower())
     p.display_name = unicode(kw.get('display_name', None))
     p.desc = kw.get('desc', None)
     
     if len(errors) > 0:
         return dict(errors=errors, project=project, product=p)
         
     p.project = project
     
     DBSession.add(p)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/product/new?project=%s' % kw['project_label']))
コード例 #5
0
ファイル: site.py プロジェクト: jness/dmirr
 def put(self, site_label=None, *a, **kw):
     errors = _h.get_validation_errors()
     s = DBSession.query(Site).filter_by(label=site_label).first()
     group = _h.get_group_by_name(kw.get('group_name', None))
     all_p = DBSession.query(Project).all()
     _h.protect_obj(s)
     
     if not s:
         raise HTTPNotFound         
     if not group:
         errors['group'] = 'Group does not exist!'
         
     s.label = unicode(re.sub(' ', '_', kw['label']).lower())
     s.display_name = unicode(kw.get('display_name', None))
     s.desc = kw.get('desc', None)
     s.url = unicode(kw.get('url', None))
     s.contact_name = unicode(kw.get('contact_name', None))
     s.contact_email = unicode(kw.get('contact_email', None))
     s.sync_base_path = unicode(kw.get('sync_base_path', None))
     s.user = request.identity['user']
     s.group = group
 
     if len(errors) > 0:
         all_projects = [x for x in all_p if x not in s.projects]
         all_hosts = [x for x in request.identity['user'].hosts \
                         if x not in s.hosts]
         transaction.doom()
         return dict(page='site', errors=errors, site=s,
                     all_projects=all_projects, all_hosts=all_hosts)
         
     transaction.commit()
     flash(_("%s updated successfully!" % kw['display_name']), 'info')
     redirect(url('/site/%s/edit' % kw['label']))
コード例 #6
0
ファイル: site.py プロジェクト: jness/dmirr
    def assign_project(self, site_id, *a, **kw):
        errors = _h.get_validation_errors()
        s = DBSession.query(Site).filter_by(id=site_id).first()
        p = DBSession.query(Project).filter_by(id=kw.get('project_id', None))\
            .first()
        all_p = DBSession.query(Project).all()
        
        _h.protect_obj(s)
        _h.protect_obj(p)

        if not s:
            raise HTTPNotFound
        if not p:
            raise HTTPNotFound    
        
        all_projects = [x for x in all_p if x not in s.projects]
        
        if errors:
            transaction.doom()
            return dict(errors=errors, site=s, all_projects=all_projects)

        _s_label = s.label
        s.projects.append(p)

        if kw.get('sync_path', None):
            self._add_site_sync_path(s.id, p.id, kw['sync_path'])
        else:
            transaction.doom()
            flash(_('Site sync path required for each project.'), 'warning')
            redirect(url("/site/%s/edit#mirrored_projects" % _s_label))

        transaction.commit()    
        redirect(url("/site/%s/edit#projects" % _s_label))
コード例 #7
0
ファイル: project.py プロジェクト: jness/dmirr
    def put(self, project_id=None, *a, **kw):
        errors = _h.get_validation_errors()
        p = DBSession.query(Project).filter_by(id=project_id).first()
        if not p:
            raise HTTPNotFound
        if kw['label'] != p.label:
            other_p = DBSession.query(Project).filter_by(label=kw['label'])\
                      .first()
            if other_p:
                errors['label'] = "%s already exists, use another label." % \
                    other_p.label
        group = _h.get_group_by_name(kw.get('group_name', None))
        protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
        all_protocols = DBSession.query(SyncProtocol).all()

        _h.protect_obj_modify(p)
        
        p.display_name = unicode(kw['display_name'])
        p.desc = kw['desc']
        p.url = unicode(kw['url'])
        p.sync_base_path = unicode(kw.get('sync_base_path', None))
        p.sync_flags = unicode(kw.get('sync_flags', None))
        p.sync_protocol = protocol
        p.group = group
        
        if len(errors) > 0:
            transaction.doom()
            return dict(errors=errors, project=p, all_protocols=all_protocols)

        p.label = unicode(re.sub(' ', '_', kw['label']).lower())
        _label = p.label
        transaction.commit()
        flash(_("%s updated successfully!" % kw['display_name']), 'info')
        redirect(url('/project/%s/edit' % _label))
コード例 #8
0
ファイル: project.py プロジェクト: jness/dmirr
    def edit(self, project_label=None, *a, **kw):
        p = DBSession.query(Project).filter_by(label=project_label).first()
        
        all_protocols = DBSession.query(SyncProtocol).all()
        _h.protect_obj_modify(p)
        
        # only groups that both the logged in user, and the owner of the
        # project share.
        all_groups = []
        for group in request.identity['user'].groups:
            if p.user in group.users:
                all_groups.append(group)
        for group in p.user.groups:
            if request.identity['user'] in group.users:
                all_groups.append(group)
                
        all_hosts = []
        for host in request.identity['user'].hosts:
            if host.group in all_groups and not host in all_hosts:
                all_hosts.append(host)
            elif host.user == p.user:
                all_hosts.append(host)
        for group in all_groups:
            for host in group.hosts:
                if not host in all_hosts:
                    all_hosts.append(host)

        all_h = [x for x in all_hosts if x not in p.hosts]            
        return dict(page='project', errors={}, project=p, 
                    all_protocols=all_protocols, all_hosts=all_h)
コード例 #9
0
ファイル: project.py プロジェクト: jness/dmirr
 def get_all(self, *a, **kw):
     view = kw.get('view', None)
     if view and view == 'user':
         ps = DBSession.query(Project)\
              .filter_by(user_id=request.identity['user'].user_id).all()
     else:         
         ps = DBSession.query(Project).all()
     return dict(page="project", errors={}, page_title="dMirr Projects",
                 projects=ps)
コード例 #10
0
ファイル: user.py プロジェクト: jness/dmirr
    def change_email(self, **kw):
        u = db.query(model.User).filter_by(user_name=kw['u'])\
            .filter_by(verify_code=kw['vc']).first()

        if not u:
            flash(_('Email verification failed.  %s was not found or invalid code!' % kw['u']), 'warning')
            redirect(url('/dashboard'))

        u.email_address = kw['e']
        db.flush()
        flash(_('%s successfully changed email address to %s!' % (u.display_name, u.email_address)),
'info')
        transaction.commit()

        redirect(url('/dashboard'))
コード例 #11
0
ファイル: user.py プロジェクト: jness/dmirr
 def get_all(self, *a, **kw):
     protected_users = []
     users = db.query(model.User).all()
     for u in users:
         protected_users.append(self._strip_private(u))
     return dict(errors={}, page='user', page_title="dMirr Users",
                 users=protected_users)
コード例 #12
0
ファイル: helpers.py プロジェクト: jness/dmirr
def get_group_by_name(group_name=None):
    if not group_name:
        group_name = 'dmirr_no_group'
    group = db.query(model.Group)\
            .filter_by(group_name=group_name)\
            .first()
    return group
コード例 #13
0
ファイル: validators.py プロジェクト: jness/dmirr
def validate_unique_group_name(value_dict, state, validator):
    # first for edit forms
    if value_dict.has_key('group_id'):
        g1 = db.query(model.Group).filter_by(group_id=value_dict['group_id'])\
             .first()
        if g1 and g1.group_name != value_dict['group_name']:
            g2 = db.query(model.Group)\
                 .filter_by(group_name=value_dict['gropu_name']).first()
            if g2:
                return {'group_name':'The group name already exists.'}
    # or new form                
    else:
        g1 = db.query(model.Group)\
             .filter_by(group_name=value_dict['group_name']).first()
        if g1:
            return {'group_name':'The group name already exists.'}
コード例 #14
0
ファイル: site.py プロジェクト: jness/dmirr
    def edit(self, site_label=None, *a, **kw):
        s = _h.get_site_by_name(site_label)
        all_projects = DBSession.query(Project).all()

        # only groups that both the logged in user, and the owner of the
        # site share.
        all_groups = []
        for group in request.identity['user'].groups:
            if s.user in group.users:
                all_groups.append(group)
        for group in s.user.groups:
            if request.identity['user'] in group.users:
                all_groups.append(group)
                
        all_hosts = []
        for host in request.identity['user'].hosts:
            if host.group in all_groups and not host in all_hosts:
                all_hosts.append(host)
            elif host.user == s.user:
                all_hosts.append(host)
        for group in all_groups:
            for host in group.hosts:
                if not host in all_hosts:
                    all_hosts.append(host)
                    
        
        if not s:
            raise HTTPNotFound
            
        _h.protect_obj_modify(s)
        
        # I love python...
        all_p = [x for x in all_projects if x not in s.projects]
        all_h = [x for x in all_hosts if x not in s.hosts]
        return dict(errors={}, site=s, all_projects=all_p, all_hosts=all_h)
コード例 #15
0
ファイル: product.py プロジェクト: jness/dmirr
    def put(self, product_label=None, *a, **kw):
        p = DBSession.query(Product).filter_by(label=product_label).first()
        project = p.project
        _project_label = project.label    
        
        if not p:
            raise HTTPNotFound
        if not project:
            raise HTTPNotFound
        
        _h.protect_obj_modify(project)
        _h.protect_obj_modify(p.project)
        
        errors = _h.get_validation_errors()
        
        if kw.get('label', None) != p.label:
            _existing_p = _h.get_product_by_name(kw.get('label', None))
            if _existing_p:
                errors['label'] = "%s already exists!" % kw.get('label', None)
            
        p.label = unicode(re.sub(' ', '_', kw['label']).lower())
        p.display_name = unicode(kw['display_name'])
        p.desc = kw['desc']
        p.project = project
                    
        if errors:
            transaction.doom()
            return dict(project=p.project, errors=errors, product=p)

        transaction.commit()
        flash(_("%s updated successfully!" % kw['display_name']), 'info')
        redirect(url("/project/%s/edit#products" % _project_label))
コード例 #16
0
ファイル: validators.py プロジェクト: jness/dmirr
def validate_unique_email(value_dict, state, validator):
    # first for edit forms
    if value_dict.has_key('user_id'):
        u1 = db.query(model.User).filter_by(user_id=value_dict['user_id'])\
             .first()
        if u1.email_address != value_dict['email_address']:
            u2 = db.query(model.User)\
                 .filter_by(email_address=value_dict['email_address']).first()
            if u2:
                return {'email_address':'The address already exists.'}
    # or new form                
    else:
        u1 = db.query(model.User)\
             .filter_by(email_address=value_dict['email_address']).first()
        if u1:
            return {'email_address':'The address already exists.'}
コード例 #17
0
ファイル: validators.py プロジェクト: jness/dmirr
def validate_unique_user_name(value_dict, state, validator):
    # first for edit forms
    if value_dict.has_key('user_id'):
        u1 = db.query(model.User).filter_by(user_id=value_dict['user_id'])\
             .first()
        if u1 and u1.user_name != value_dict['user_name']:
            u2 = db.query(model.User)\
                 .filter_by(user_name=value_dict['user_name']).first()
            if u2:
                return {'user_name':'The user name already exists.'}
    # or new form        
    else:
        u1 = db.query(model.User)\
             .filter_by(user_name=value_dict['user_name']).first()
        if u1:
            return {'user_name':'The user name already exists.'}
コード例 #18
0
ファイル: project.py プロジェクト: jness/dmirr
 def get_one(self, label, *a, **kw):
     p = DBSession.query(Project).filter_by(label=label).first()
     site_hosts = []
     for s in p.sites:
         for h in s.hosts:
             h.sync_base_path = s.sync_base_path
             site_hosts.append(h)
     return dict(errors={}, project=p, site_hosts=site_hosts)
コード例 #19
0
ファイル: site.py プロジェクト: jness/dmirr
 def _add_site_sync_path(self, site_id, project_id, sync_path):
     s = DBSession.query(Site).filter_by(id=site_id).first()
     p = DBSession.query(Project).filter_by(id=project_id).first()
     alt = DBSession.query(SiteSyncPath).filter_by(site_id=s.id)\
           .filter_by(project_id=p.id).first()
     if alt:
         alt.sync_path = sync_path
         transaction.commit()
         return alt
 
     alt = SiteSyncPath()
     alt.site = s
     alt.project = p
     alt.sync_path = sync_path
     DBSession.add(alt)
     transaction.commit()
     return alt
コード例 #20
0
ファイル: product.py プロジェクト: jness/dmirr
 def new(self, *a, **kw):
     product = _h.get_product_by_name(kw.get('product', None))
     all_archs = DBSession.query(Arch).all()
     if not product:
         raise HTTPNotFound
         
     _h.protect_obj_modify(product.project)
     
     r = ProductRelease()
     r.label = kw.get('label', '')
     r.display_name = kw.get('display_name', '')
     r.desc = kw.get('desc', '')
     arch = DBSession.query(Arch)\
         .filter_by(label=kw.get('arch_label', 'noarch'))\
         .first()
     r.path = kw.get('path', '')
     return dict(page='product_release', errors={}, project=product.project, product=product, all_archs=all_archs, arch=arch, release=r)
コード例 #21
0
ファイル: site.py プロジェクト: jness/dmirr
    def unassign_host(self, site_id, host_id):
        s = DBSession.query(Site).filter_by(id=int(site_id)).first()
        h = DBSession.query(Host).filter_by(id=int(host_id)).first()
        
        _h.protect_obj(s)
        _h.protect_obj(h)

        if not s:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
                
        _s_label = s.label
        s.hosts.remove(h)
        transaction.commit()
        redirect(url("/site/%s/edit#downstream_mirrors" % _s_label))
        return dict(errors={}, site=s)    
コード例 #22
0
ファイル: project.py プロジェクト: jness/dmirr
    def unassign_host(self, project_id, host_id):
        p = DBSession.query(Project).filter_by(id=int(project_id)).first()
        h = DBSession.query(Host).filter_by(id=int(host_id)).first()
        
        _h.protect_obj(p)
        _h.protect_obj(h)

        if not p:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
                
        _p_label = p.label
        p.hosts.remove(h)
        transaction.commit()
        redirect(url("/project/%s/edit#upstream_mirrors" % _p_label))
        return dict(errors={}, project=p)    
コード例 #23
0
ファイル: product.py プロジェクト: jness/dmirr
 def edit(self, release_label=None, *a, **kw):
     r = _h.get_release_by_name(release_label)
     all_archs = DBSession.query(Arch).all()
     if not r:
         raise HTTPNotFound
     
     _h.protect_obj_modify(r.product.project)            
     return dict(project=r.product.project, errors={}, all_archs=all_archs, 
                 release=r)
コード例 #24
0
ファイル: project.py プロジェクト: jness/dmirr
 def delete(self, project_label=None, *a, **kw):
     _p = DBSession.query(Project).filter_by(label=project_label).first()   
     if not _p:
         raise HTTPNotFound
     _p_label = _p.label
     _h.protect_obj(_p)
         
     confirmed = kw.get('confirmed', None)        
     if not confirmed:
         display_name = _p.display_name
         action = url('/project/%s/delete' % _p.label)
         came_from = url('/project/%s/edit' % _p_label)
         return dict(page="project", errors={}, display_name=display_name, action=action, came_from=came_from)
     else:
         DBSession.delete(_p)
         transaction.commit()
         flash(_("%s and all associated data have been deleted." % _p.display_name), 'info')
         redirect(url('/dashboard'))
コード例 #25
0
ファイル: product.py プロジェクト: jness/dmirr
    def put(self, release_id=None, *a, **kw):
        errors = _h.get_validation_errors()
        r = DBSession.query(ProductRelease)\
            .filter_by(id=release_id)\
            .first()
        product = r.product
        allarchs = DBSession.query(Arch).all()
        _project_label = r.product.project.label
        
        if not r:
            raise HTTPNotFound
        
        _h.protect_obj_modify(r.product.project)
        _h.protect_obj_modify(product.project)
            
        r.label = unicode(re.sub(' ', '_', kw['label']).lower())
        r.display_name = unicode(kw.get('display_name', None))
        r.desc = kw.get('desc', None)
        r.path = unicode(kw.get('path', ''))
        r.product = product
        
        if kw.get('label') != r.label:
            existing_r = _h.get_release_by_name(kw.get('label', None))
            if _existing_r:
                errors['label'] = "%s already exists!" % kw.get('label', None)
    
        if not kw.get('archs'):
            errors['archs'] = "Must select atleast one arch"
        else:
            for a in allarchs:
                if _(a.id) in kw['archs']:
                    r.archs.append(a)
                else:
                    if a in r.archs:
                        r.archs.remove(a)
                
        if len(errors) > 0:
            transaction.doom()
            return dict(errors=errors, project=r.product.project, 
                        all_archs=allarchs, release=r)

        transaction.commit()
        flash(_("%s updated successfully!" % kw['display_name']), 'info')
        redirect(url('/project/%s/edit#products' % _project_label))
コード例 #26
0
ファイル: validators.py プロジェクト: jness/dmirr
def validate_user_exists(value_dict, state, validator):
    # first for edit forms
    if value_dict.has_key('user_name'):
        u = db.query(model.User).filter_by(user_name=value_dict['user_name'])\
             .first()
        if not u:
            return {'user_name':'%s does not exists.' % value_dict['user_name']}
    # or new form        
    else:
        return {'user_name':'User does not exists.'}
コード例 #27
0
ファイル: product.py プロジェクト: jness/dmirr
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     product = _h.get_product_by_name(kw.get('product_label', None))
     allarchs = DBSession.query(Arch).all()
     if not product:
         raise HTTPNotFound
     _product_label = product.label
     
     _h.protect_obj_modify(product.project)
     
     r = ProductRelease()
     
     _existing_r = _h.get_release_by_name(kw.get('label', None))
     if _existing_r:
         errors['label'] = "%s already exists!" % kw.get('label', None)
     
     if len(errors) > 0:
         transaction.doom()
         return dict(errors=errors, project=product.project, 
                     all_archs=allarchs, product=product, release=r)
     
     r.product = product
     r.label = unicode(re.sub(' ', '_', kw['label']).lower())
     r.display_name = unicode(kw.get('display_name', None))
     r.desc = kw.get('desc', None)
     r.path = unicode(kw.get('path', ''))
         
     if not kw.get('archs'):
         errors['archs'] = "Must select atleast one arch"
     else:
         for a in allarchs:
             if _(a.id) in kw['archs']:
                 r.archs.append(a)
             else:
                 if a in r.archs:
                     r.archs.remove(a)
                     
     # FIX ME: Add check to make sure the rsync path is valid
     
     DBSession.add(r)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/product_release/new?product=%s' % _product_label))
コード例 #28
0
ファイル: user.py プロジェクト: jness/dmirr
 def edit(self, user_name=None, **kw):
     user = db.query(model.User).filter_by(user_name=user_name).first()
     if not user:
         raise HTTPNotFound
     
     _h.protect_user_obj(user)
         
     errors = _h.get_validation_errors()
     tmpl_context.form = edit_user_form
     return dict(page='user', page_title='Edit Account Settings', 
                 errors=errors, user=user)
コード例 #29
0
ファイル: host.py プロジェクト: jness/dmirr
 def delete(self, host_address=None, *a, **kw):
     h = DBSession.query(Host).filter_by(address=host_address).first()   
     if not h:
         raise HTTPNotFound
     _host_address = h.address
     _h.protect_obj(h)
         
     confirmed = kw.get('confirmed', None)        
     if not confirmed:
         display_name = h.address
         action = url('/host/%s/delete' % h.address)
         came_from = url('/host/%s/edit' % h.address)
         return dict(errors={}, display_name=display_name, action=action, 
                     came_from=came_from)
     else:
         DBSession.delete(h)
         transaction.commit()
         flash(_("%s and all associated data have been deleted." % \
             _host_address), 'info')
         redirect(url('/dashboard'))
コード例 #30
0
ファイル: site.py プロジェクト: jness/dmirr
    def assign_host(self, site_id, *a, **kw):
        errors = _h.get_validation_errors()
        s = DBSession.query(Site).filter_by(id=site_id).first()
        h = DBSession.query(Host).filter_by(id=kw.get('host_id', None)).first()
        
        _h.protect_obj(s)
        _h.protect_obj(h)

        if not s:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
        
        if errors:
            return dict(errors=errors, site=s)
            
        _s_label = s.label
        s.hosts.append(h)
        transaction.commit()
        redirect(url("/site/%s/edit#downstream_mirrors" % _s_label))