repair_team_members.py (AEN 4.2.0)
==================================

.. raw:: html

    <div class="highlight-bash"><div class="highlight"><pre><span></span>from wk_server.base import init as wk_server_init
    from wk_server.tasks import add_team_member
    import wk_server.database as db

    wk_server_init<span class="o">()</span>

    <span class="nv">users</span> <span class="o">=</span> db.get_users<span class="o">()</span>
    <span class="k">for</span> user in users:
        <span class="nv">projects</span> <span class="o">=</span> db.get_projects<span class="o">(</span>user, user<span class="o">)</span>
        <span class="k">for</span> p in projects:
            <span class="k">if</span> not p.get<span class="o">(</span><span class="s1">&#39;team&#39;</span><span class="o">)</span>:
                <span class="k">continue</span>
            print user<span class="o">[</span><span class="s1">&#39;username&#39;</span><span class="o">]</span>, p<span class="o">[</span><span class="s1">&#39;name&#39;</span><span class="o">]</span>, p<span class="o">[</span><span class="s1">&#39;team&#39;</span><span class="o">]</span>
            <span class="k">for</span> team in p<span class="o">[</span><span class="s1">&#39;team&#39;</span><span class="o">]</span>:
                <span class="nv">team_member</span> <span class="o">=</span> db.get_user<span class="o">(</span><span class="nv">_id</span><span class="o">=</span>team<span class="o">)</span>
                print <span class="s1">&#39;adding&#39;</span>, user<span class="o">[</span><span class="s1">&#39;username&#39;</span><span class="o">]</span>, p<span class="o">[</span><span class="s1">&#39;name&#39;</span><span class="o">]</span>, p<span class="o">[</span><span class="s1">&#39;team&#39;</span><span class="o">]</span>, team_member<span class="o">[</span><span class="s1">&#39;username&#39;</span><span class="o">]</span>
                add_team_member<span class="o">(</span>user<span class="o">[</span><span class="s1">&#39;_id&#39;</span><span class="o">]</span>, user<span class="o">[</span><span class="s1">&#39;_id&#39;</span><span class="o">]</span>, p<span class="o">[</span><span class="s1">&#39;name&#39;</span><span class="o">]</span>, team_member<span class="o">[</span><span class="s1">&#39;_id&#39;</span><span class="o">])</span>
    </pre></div>
    </div>
