Revision 9eafaa32

b/snf-astakos-app/astakos/im/forms.py
647 647
                                         ('date_joined', 'Status')
648 648
                                         ),
649 649
                                required=False)
650

  
651
class PickResourceForm(forms.Form):
652
    resource = forms.ModelChoiceField(
653
        queryset=Resource.objects.select_related().all()
654
    )
655
    resource.widget.attrs["onchange"]="this.form.submit()"
b/snf-astakos-app/astakos/im/management/commands/user-update.py
38 38
from django.core.exceptions import ValidationError
39 39
from django.db.utils import IntegrityError
40 40

  
41
from astakos.im.models import AstakosUser, AstakosGroup, Membership
41
from astakos.im.models import (AstakosUser, AstakosGroup, Membership, Resource,
42
                               AstakosUserQuota)
42 43
from astakos.im.endpoints.aquarium.producer import report_user_credits_event
43 44
from ._common import remove_user_permission, add_user_permission
44 45

  
......
47 48
    args = "<user ID>"
48 49
    help = "Modify a user's attributes"
49 50

  
50
    option_list = BaseCommand.option_list + (
51
    option_list = list(BaseCommand.option_list) + [
51 52
        make_option('--invitations',
52 53
                    dest='invitations',
53 54
                    metavar='NUM',
......
111 112
                    dest='refill',
112 113
                    default=False,
113 114
                    help="Refill user credits"),
114
    )
115

  
115
    ]
116
    resources = Resource.objects.select_related().all()
117
    append = option_list.append
118
    for r in resources:
119
        append(make_option('--%s-set-quota' % r,
120
                    dest='%s-set-quota' % r,
121
                    metavar='QUANTITY',
122
                    help="Set resource quota"))
123
    
116 124
    def handle(self, *args, **options):
117 125
        if len(args) != 1:
118 126
            raise CommandError("Please provide a user ID")
......
225 233

  
226 234
        if password:
227 235
            self.stdout.write('User\'s new password: %s\n' % password)
236
        
237
        for r in self.resources:
238
            limit = options.get('%s-set-quota' % r)
239
            if not limit:
240
                continue
241
            if not limit.isdigit():
242
                raise CommandError('Invalid limit')
243
            
244
            q = AstakosUserQuota.objects
245
            q, created = q.get_or_create(resource=r, user=user,
246
                                         defaults={'uplimit': limit})
247
            verb = 'set' if created else 'updated'
248
            self.stdout.write('User\'s quota %s successfully\n' % verb)
b/snf-astakos-app/astakos/im/models.py
297 297
    def quota(self):
298 298
        d = defaultdict(int)
299 299
        for q in self.astakosuserquota_set.select_related().all():
300
            d[q.resource.name] += q.uplimit
300
            d[q.resource] += q.uplimit
301 301
        for m in self.membership_set.select_related().all():
302 302
            if not m.is_approved:
303 303
                continue
......
306 306
                continue
307 307
            for r, uplimit in g.quota.iteritems():
308 308
                d[r] += uplimit
309
        
309 310
        # TODO set default for remaining
310 311
        return d
311 312

  
b/snf-astakos-app/astakos/im/templates/im/astakosuserquota_list.html
5 5
{% block page.body %}
6 6
<div class="maincol {% block innerpage.class %}{% endblock %}">
7 7
    <div class="section">
8
            {% for k, v in user.quota|items %}
9
                <strong>{{k}}</strong>
10
                <table class="zebra-striped id-sorted">
11
<!-- 
12
                    <thead>
13
                      <tr>
14
                        <th>Limit (Group)</th>
15
                      </tr>
16
                    </thead>
17
 -->
18
                    <tbody>
19
                    {% for m in user.membership_set.select_related.all %}
20
                        {% if m.group.is_enabled %}
21
                            {% with m.group.quota as quota %}
22
                            {% if  quota %}
23
                                {% for kk, vv in quota|items %}
24
                                    {% if k == kk %}
25
                                    <tr>
26
                                        <td>{{ vv }} ({{m.group.name}})</td>
27
                                    </tr>
28
                                    {% endif %}
29
                                {% endfor %}
30
                            {% endif %}
31
                            {% endwith %}
8
        <form action="" method="post"
9
	            class="withlabels">{% csrf_token %}
10
	            {% include "im/form_render.html" %}
11
	    </form>
12
	    <table>
13
	    {% for q in object_list %}
14
	        {% if q.group.is_enabled %}
15
	            <tr>
16
	                <td>{{ q.uplimit }}</td><td>({{ q.group }})</td>
17
	            </tr>
18
	        {% endif %}
19
	    {% endfor %}
20
	    {% if form.cleaned_data %}
21
            {% with form.cleaned_data|lookup:'resource' as resource %}
22
                {% if resource %}
23
                    {% for q in user.astakosuserquota_set.all %}
24
                        {% if q.resource == resource %}
25
                        <tr>
26
                            <td>{{ q.uplimit }}</td><td>(assigned to me)</td>
27
                        </tr>
32 28
                        {% endif %}
33 29
                    {% endfor %}
34
                                    <tr>
35
                                        <td><strong>{{ v }}</strong></td>
36
                                    </tr>
37
                                    <tr/>
38
                    </tbody>
39
                </table>
40
            {% endfor %}
30
                        <tr>
31
                            <td>{{ user.quota|lookup:resource }}</td><td>(total)</td>
32
                        </tr>
33
                {% endif %}
34
            {% endwith %}
35
        {% endif %}
36
	    </table>
41 37
    </div>
42 38
</div>
43 39
{% endblock %}
b/snf-astakos-app/astakos/im/views.py
61 61

  
62 62
from astakos.im.models import (
63 63
    AstakosUser, ApprovalTerms, AstakosGroup, Resource,
64
    EmailChange, GroupKind, Membership)
64
    EmailChange, GroupKind, Membership, AstakosGroupQuota)
65 65
from astakos.im.activation_backends import get_backend, SimpleBackend
66 66
from astakos.im.util import get_context, prepare_response, set_cookie, get_query
67 67
from astakos.im.forms import (LoginForm, InvitationForm, ProfileForm,
......
70 70
                              AstakosGroupCreationForm, AstakosGroupSearchForm,
71 71
                              AstakosGroupUpdateForm, AddGroupMembersForm,
72 72
                              AstakosGroupSortForm, MembersSortForm,
73
                              TimelineForm)
73
                              TimelineForm, PickResourceForm)
74 74
from astakos.im.functions import (send_feedback, SendMailError,
75 75
                                  invite as invite_func, logout as auth_logout,
76 76
                                  activate as activate_func,
......
1031 1031
@signed_terms_required
1032 1032
@login_required
1033 1033
def resource_list(request):
1034
    return render_response(
1035
        template='im/astakosuserquota_list.html',
1036
        context_instance=get_context(request))
1034
    if request.method == 'POST':
1035
        form = PickResourceForm(request.POST)
1036
        if form.is_valid():
1037
            r = form.cleaned_data.get('resource')
1038
            if r:
1039
                groups = request.user.membership_set.only('group').filter(
1040
                    date_joined__isnull=False)
1041
                groups = [g.group_id for g in groups]
1042
                q = AstakosGroupQuota.objects.select_related().filter(
1043
                    resource=r, group__in=groups)
1044
    else:
1045
        form = PickResourceForm()
1046
        q = AstakosGroupQuota.objects.none()
1047
    return object_list(request, q,
1048
                       template_name='im/astakosuserquota_list.html',
1049
                       extra_context={'form': form})
1037 1050

  
1038 1051

  
1039 1052
def group_create_list(request):
1053
    form = PickResourceForm()
1040 1054
    return render_response(
1041 1055
        template='im/astakosgroup_create_list.html',
1042 1056
        context_instance=get_context(request),)

Also available in: Unified diff