Commit 98e11391eb7ce7da77996ef0438bc01464e1a51f
1 parent
b47acb09
Exists in
master
and in
3 other branches
Adding group delete
Showing
9 changed files
with
87 additions
and
9 deletions
Show diff stats
amadeus/static/css/themes/green.css
... | ... | @@ -67,6 +67,11 @@ a, a:focus, a:hover { |
67 | 67 | color: #000000 !important; |
68 | 68 | } |
69 | 69 | |
70 | +.group-panel-body { | |
71 | + background: #FFFFFF !important; | |
72 | + border-top: 1px solid #CCCCCC; | |
73 | +} | |
74 | + | |
70 | 75 | .topic-panel > .panel-heading { |
71 | 76 | background-color: #7BA5B9 !important; |
72 | 77 | } | ... | ... |
amadeus/static/js/course.js
... | ... | @@ -193,4 +193,14 @@ $('.collapse').on('hide.bs.collapse', function (e) { |
193 | 193 | }); |
194 | 194 | } |
195 | 195 | } |
196 | -}); | |
197 | 196 | \ No newline at end of file |
197 | +}); | |
198 | + | |
199 | +function delete_group(url) { | |
200 | + $('.modal').remove(); | |
201 | + | |
202 | + $.get(url, function (modal) { | |
203 | + $("#group-accordion").after(modal); | |
204 | + | |
205 | + $('.modal').modal('show'); | |
206 | + }); | |
207 | +} | |
198 | 208 | \ No newline at end of file | ... | ... |
students_group/models.py
... | ... | @@ -0,0 +1,23 @@ |
1 | +{% load i18n %} | |
2 | + | |
3 | +<div class="modal fade" id="topic" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
4 | + <div class="modal-dialog" role="document"> | |
5 | + <div class="modal-content"> | |
6 | + <div class="modal-body"> | |
7 | + <form id="delete_form" action="{% url 'groups:delete' group.slug %}" method="post"> | |
8 | + {% csrf_token %} | |
9 | + <h3>{% trans 'Are you sure you want delete the group' %}: {{ group }}?</h3> | |
10 | + <p>{% trans 'With this action the group will no longer exist but your participants will still be attached to the subject.' %}</p> | |
11 | + </form> | |
12 | + </div> | |
13 | + <div class="modal-footer"> | |
14 | + <div class="pull-right"> | |
15 | + <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | |
16 | + </div> | |
17 | + <div class="pull-left"> | |
18 | + <button type="submit" form="delete_form" class="btn btn-success btn-raised">{% trans "Delete" %}</button> | |
19 | + </div> | |
20 | + </div> | |
21 | + </div> | |
22 | + </div> | |
23 | +</div> | |
0 | 24 | \ No newline at end of file | ... | ... |
students_group/templates/groups/index.html
... | ... | @@ -33,15 +33,15 @@ |
33 | 33 | </div> |
34 | 34 | |
35 | 35 | <div class="col-md-12 cards-content"> |
36 | - <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | |
36 | + <div class="panel-group" id="group-accordion" role="tablist" aria-multiselectable="true"> | |
37 | 37 | {% for group in groups %} |
38 | 38 | <div class="panel panel-info group-panel"> |
39 | 39 | <div class="panel-heading"> |
40 | 40 | <div class="row"> |
41 | 41 | <div class="col-md-12 category-header"> |
42 | 42 | <h4 class="panel-title"> |
43 | - <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{group.slug}}"> | |
44 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{ group }} | |
43 | + <a class="category-course-link pull-left" data-parent="#group-accordion" data-toggle="collapse" href="#{{group.slug}}"> | |
44 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{ group }} ({{ group.participants.count }}) | |
45 | 45 | </a> |
46 | 46 | </h4> |
47 | 47 | |
... | ... | @@ -56,18 +56,34 @@ |
56 | 56 | </a> |
57 | 57 | </li> |
58 | 58 | <li><a href="{% url 'groups:update' subject.slug group.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> {% trans 'Edit' %}</a></li> |
59 | - <li><a href=""><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
59 | + <li><a href="javascript:delete_group('{% url 'groups:delete' group.slug %}')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
60 | 60 | </ul> |
61 | 61 | </div> |
62 | 62 | </div> |
63 | 63 | </div> |
64 | 64 | </div> |
65 | - </div> | |
65 | + <div id="{{ group.slug }}" class="panel-collapse panel-body collapse category-panel-content group-panel-body"> | |
66 | + {% autoescape off %} | |
67 | + {{ group.description }} | |
68 | + {% endautoescape %} | |
66 | 69 | |
70 | + <h3>{% trans 'Participant(s)' %}: </h3> | |
71 | + | |
72 | + <ul class="list-inline"> | |
73 | + {% for user in group.participants.all %} | |
74 | + <li class="list-inline-item text-center col-lg-2 col-md-2 col-sm-2 col-xs-3"> | |
75 | + <img src="{{ user.image_url }}" class="img-responsive" /> | |
76 | + <p><small>{{ user }}</small></p> | |
77 | + </li> | |
78 | + {% endfor %} | |
79 | + </ul> | |
80 | + </div> | |
81 | + </div> | |
67 | 82 | {% endfor %} |
68 | 83 | |
69 | 84 | {% pagination request paginator page_obj %} |
70 | 85 | </div> |
71 | 86 | </div> |
72 | 87 | |
88 | + <script type="text/javascript" src="{% static 'js/course.js' %}"></script> | |
73 | 89 | {% endblock %} |
74 | 90 | \ No newline at end of file | ... | ... |
students_group/urls.py
... | ... | @@ -6,4 +6,5 @@ urlpatterns = [ |
6 | 6 | url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateView.as_view(), name='create'), |
7 | 7 | url(r'^update/(?P<sub_slug>[\w_-]+)/(?P<slug>[\w_-]+)/$', views.UpdateView.as_view(), name='update'), |
8 | 8 | url(r'^replicate/(?P<slug>[\w_-]+)/(?P<group_slug>[\w_-]+)/$', views.CreateView.as_view(), name='replicate'), |
9 | + url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteView.as_view(), name = 'delete'), | |
9 | 10 | ] |
10 | 11 | \ No newline at end of file | ... | ... |
students_group/views.py
... | ... | @@ -149,4 +149,26 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
149 | 149 | def get_success_url(self): |
150 | 150 | messages.success(self.request, _('The group "%s" was updated successfully!')%(self.object.name)) |
151 | 151 | |
152 | + return reverse_lazy('groups:index', kwargs = {'slug': self.object.subject.slug}) | |
153 | + | |
154 | +class DeleteView(LoginRequiredMixin, generic.DeleteView): | |
155 | + login_url = reverse_lazy("users:login") | |
156 | + redirect_field_name = 'next' | |
157 | + | |
158 | + template_name = 'groups/delete.html' | |
159 | + model = StudentsGroup | |
160 | + context_object_name = 'group' | |
161 | + | |
162 | + def dispatch(self, request, *args, **kwargs): | |
163 | + slug = self.kwargs.get('slug', '') | |
164 | + group = get_object_or_404(StudentsGroup, slug = slug) | |
165 | + | |
166 | + if not has_subject_permissions(request.user, group.subject): | |
167 | + return redirect(reverse_lazy('subjects:home')) | |
168 | + | |
169 | + return super(DeleteView, self).dispatch(request, *args, **kwargs) | |
170 | + | |
171 | + def get_success_url(self): | |
172 | + messages.success(self.request, _('The group "%s" was removed successfully!')%(self.object.name)) | |
173 | + | |
152 | 174 | return reverse_lazy('groups:index', kwargs = {'slug': self.object.subject.slug}) |
153 | 175 | \ No newline at end of file | ... | ... |
users/templates/users/search.html
... | ... | @@ -29,7 +29,7 @@ |
29 | 29 | </form> |
30 | 30 | </div> |
31 | 31 | <div class="col-md-3"> |
32 | - <a href="{% url 'users:create' %}" class="pull-right btn btn-primary btn-raised btn-md"><i class="fa fa-plus"></i> {% trans 'Create User' %}</a> | |
32 | + <a href="{% url 'users:create' %}" class="pull-right btn btn-success btn-raised btn-md"><i class="fa fa-plus"></i> {% trans 'Create User' %}</a> | |
33 | 33 | </div> |
34 | 34 | </div> |
35 | 35 | |
... | ... | @@ -53,7 +53,7 @@ |
53 | 53 | </div> |
54 | 54 | <div class="col-md-3"> |
55 | 55 | <div align="right"> |
56 | - <a href="{% url 'users:update' acc.email %}" class="btn btn-primary btn-raised btn-sm"><i class="fa fa-edit"></i> {% trans 'Edit' %}</a> | |
56 | + <a href="{% url 'users:update' acc.email %}" class="btn btn-success btn-raised btn-sm"><i class="fa fa-edit"></i> {% trans 'Edit' %}</a> | |
57 | 57 | <a href="{% url 'users:delete' acc.email %}" class="btn btn-default btn-raised btn-sm"><i class="fa fa-trash"></i> {% trans 'Delete' %}</a> |
58 | 58 | </div> |
59 | 59 | </div> | ... | ... |
users/views.py
... | ... | @@ -72,7 +72,7 @@ class SearchView(braces_mixins.LoginRequiredMixin, braces_mixins.StaffuserRequir |
72 | 72 | def get_queryset(self): |
73 | 73 | search = self.request.GET.get('search', '') |
74 | 74 | |
75 | - users = User.objects.filter(Q(username__icontains = search) | Q(last_name__icontains = search) | Q(social_name__icontains = search) | Q(email__icontains = search)).order_by('social_name','username').exclude(email = self.request.user.email) | |
75 | + users = User.objects.filter(Q(username__icontains = search) | Q(last_name__icontains = search) | Q(social_name__icontains = search) | Q(email__icontains = search)).distinct().order_by('social_name','username').exclude(email = self.request.user.email) | |
76 | 76 | |
77 | 77 | return users |
78 | 78 | ... | ... |