Commit af36afe4 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Progress II

parent afe72ca0
......@@ -491,8 +491,9 @@ class ExtendedPasswordChangeForm(PasswordChangeForm):
def get_astakos_group_creation_form(request):
class AstakosGroupCreationForm(forms.ModelForm):
issue_date = forms.DateField(widget=SelectDateWidget())
expiration_date = forms.DateField(widget=SelectDateWidget())
issue_date = forms.DateField(widget=SelectDateWidget(), initial=datetime.now())
# TODO set initial in exact one month
expiration_date = forms.DateField(widget=SelectDateWidget(), initial = datetime.now() + timedelta(days=30))
kind = forms.ModelChoiceField(queryset=GroupKind.objects.all(), empty_label=None)
name = forms.URLField()
......@@ -510,23 +511,19 @@ def get_astakos_group_creation_form(request):
if commit:
g.save()
g.owner = [request.user]
# g.approve_member(request.user)
g.approve_member(request.user)
return g
return AstakosGroupCreationForm
def get_astakos_group_policy_creation_form(group):
def get_astakos_group_policy_creation_form(astakosgroup):
class AstakosGroupPolicyCreationForm(forms.ModelForm):
choices = Resource.objects.filter(~Q(astakosgroup=group))
choices = Resource.objects.filter(~Q(astakosgroup=astakosgroup))
resource = forms.ModelChoiceField(queryset=choices, empty_label=None)
# TODO check that it does not hit the db
group = forms.ModelChoiceField(queryset=AstakosGroup.objects.all(), initial=astakosgroup, widget=forms.HiddenInput())
class Meta:
model = AstakosGroupQuota
def __init__(self, *args, **kwargs):
if not args:
args = ({'group':group},)
super(AstakosGroupPolicyCreationForm, self).__init__(*args, **kwargs)
self.fields['group'].widget.attrs['disabled'] = True
return AstakosGroupPolicyCreationForm
......@@ -113,7 +113,7 @@ class AstakosGroup(Group):
creation_date = models.DateTimeField('Creation date', default=datetime.now())
issue_date = models.DateTimeField('Issue date', null=True)
expiration_date = models.DateTimeField('Expiration date', null=True)
moderatation_enabled = models.BooleanField('Moderated membership?', default=False)
moderatation_enabled = models.BooleanField('Moderated membership?', default=True)
approval_date = models.DateTimeField('Activation date', null=True, blank=True)
estimated_participants = models.PositiveIntegerField('Estimated #participants', null=True)
......@@ -153,10 +153,10 @@ class AstakosGroup(Group):
self.save()
def approve_member(self, member):
m = self.membership_set.get(person=member)
m, created = self.membership_set.get_or_create(person=member, group=self)
m.date_joined = datetime.now()
m.save()
def disapprove_member(self, member):
m = self.membership_set.remove(member)
......
......@@ -7,12 +7,32 @@
<table class="zebra-striped id-sorted">
<tr>
<th>Name: {{object.name}}</th>
</tr>
</tr>
</table>
<div class="section">
<h2>Members:</h2>
{% if members %}
<table class="zebra-striped id-sorted">
<thead>
<tr>
<th>Realname</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{% for name, approved in members %}
<tr>
<th>Members: {{object.membership.all}}</th>
<td>{{name}}</td>
<td>{{approved}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="section">
{% else %}
<p>No members yet!</p>
{% endif %}
</div>
<div class="section">
<h2>Policies:</h2>
{% if quota %}
<table class="zebra-striped id-sorted">
......@@ -35,5 +55,14 @@
<p>No policies</p>
{% endif %}
</div>
<div class="rightcol">
<form action="{% url group_policies_add object.id %}" method="post" class="innerlabels signup">{% csrf_token %}
<h2><span>NEW POLICY</span></h2>
{% include "im/form_render.html" %}
<div class="form-row submit">
<input type="submit" class="submit altcol" value="+" />
</div>
</form>
</div>
</div>
{% endblock %}
......@@ -35,7 +35,7 @@
{% include "im/form_render.html" %}
<div class="form-row submit">
<input type="submit" class="submit altcol" value="+" />
<a class="extra-link" href="{% url group_approval_request group.id %}">Request approval</a>
<a href="{% url group_approval_request group.id %}">Request approval</a>
</div>
</form>
</div>
......
......@@ -428,11 +428,7 @@ def logout(request, template='registration/logged_out.html', extra_context={}):
response['Location'] = LOGOUT_NEXT
response.status_code = 301
return response
<<<<<<< HEAD
messages.success(request, _('You have successfully logged out.'))
=======
messages.add_message(request, messages.SUCCESS, _('<p>You have successfully logged out.</p>'))
>>>>>>> origin/newstyles
context = get_context(request, extra_context)
response.write(render_to_string(template, context_instance=context))
return response
......@@ -590,14 +586,13 @@ def change_email(request, activation_key=None,
form = form,
context_instance = get_context(request,
extra_context))
<<<<<<< HEAD
@signed_terms_required
def group_add(request):
return create_object(request,
form_class=get_astakos_group_creation_form(request),
login_required = True,
post_save_redirect = '/im/group/%(id)s/policies/add')
post_save_redirect = '/im/group/%(id)s/')
@signed_terms_required
@login_required
......@@ -617,13 +612,17 @@ def group_detail(request, group_id):
except AstakosGroup.DoesNotExist:
return HttpResponseBadRequest(_('Invalid group.'))
d = {}
for resource in group.policy.all():
d[resource.name] = group.policy.through.objects.get(resource__id=resource.id,
group__id=group_id).limit
related_resources = group.policy.through.objects
for r in group.policy.all():
d[r.name] = related_resources.get(resource__id=r.id,
group__id=group_id).limit
members = map(lambda m:{m.person.realname:m.is_approved}, group.membership_set.all())
return object_detail(request,
AstakosGroup.objects.all(),
object_id=group_id,
extra_context = {'quota':d})
extra_context = {'quota':d,
'members':members,
'form':get_astakos_group_policy_creation_form(group)})
@signed_terms_required
@login_required
......@@ -636,7 +635,7 @@ def group_policies_add(request, group_id):
try:
group = AstakosGroup.objects.select_related().get(id=group_id)
except AstakosGroup.DoesNotExist:
raise HttpResponseBadRequest(_('Invalid group.'))
return HttpResponseBadRequest(_('Invalid group.'))
d = {}
for resource in group.policy.all():
d[resource.name] = group.policy.through.objects.get(resource__id=resource.id,
......@@ -644,7 +643,8 @@ def group_policies_add(request, group_id):
return create_object(request,
form_class=get_astakos_group_policy_creation_form(group),
login_required=True,
post_save_redirect = reverse('group_policies_add', kwargs=dict(group_id=group_id)),
template_name = 'im/astakosgroup_detail.html',
post_save_redirect = reverse('group_detail', kwargs=dict(group_id=group_id)),
extra_context = {'group':group,
'quota':d})
@signed_terms_required
......@@ -652,5 +652,3 @@ def group_policies_add(request, group_id):
def group_approval_request(request, group_id):
return HttpResponse()
=======
>>>>>>> origin/newstyles
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment