diff --git a/.gitignore b/.gitignore index 3f6ba2b..5336d2d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ __pycache__/ # vim *.swp +# tags +tags + # C extensions *.so diff --git a/committee/urls.py b/committee/urls.py new file mode 100644 index 0000000..4948132 --- /dev/null +++ b/committee/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ + url(r'^$', views.edit, name='edit'), + url(r'^update/(?P\d+)/$', views.update, name='update'), + url(r'^fincom/$', views.add_to_fincom, name='add_to_fincom'), + url(r'^fincom/delete$', views.remove_fincom, name='remove_fincom'), + url(r'^new$', views.new_committee, name='new_committee'), +] diff --git a/committee/views.py b/committee/views.py index 91ea44a..d02daf4 100644 --- a/committee/views.py +++ b/committee/views.py @@ -1,3 +1,71 @@ -from django.shortcuts import render +from django.shortcuts import HttpResponse, HttpResponseRedirect +from django.template import loader +from django.contrib.auth.decorators import login_required +from django.contrib.auth.models import User, Group +from models import Committee -# Create your views here. +@login_required +def edit(request): + if (not request.user.groups.filter(name='Fincom').exists()): + return HttpResponseRedirect('/items') + + template = loader.get_template('committee/edit.html') + + context = { + 'committees': Committee.objects.order_by('name'), + 'fincom': User.objects.filter(groups__name='Fincom'), + 'users': User.objects.order_by('first_name', 'last_name'), + } + + return HttpResponse(template.render(context, request)) + +@login_required +def update(request, committee): + if (not request.user.groups.filter(name='Fincom').exists()): + return HttpResponseRedirect('/items') + + committee = Committee.objects.get(pk=committee) + + committee.name = request.POST['name'] + committee.chair = User.objects.get(pk=request.POST['chair']) + + committee.save() + + return HttpResponseRedirect('/committees') +@login_required +def new_committee(request): + if (not request.user.groups.filter(name='Fincom').exists()): + return HttpResponseRedirect('/items') + + committee = Committee( + name = request.POST['name'], + chair = User.objects.get(pk=request.POST['chair']), + ) + + committee.save() + + return HttpResponseRedirect('/committees') + +@login_required +def add_to_fincom(request): + if (not request.user.groups.filter(name='Fincom').exists()): + return HttpResponseRedirect('/items') + + user = User.objects.get(pk=request.POST['user']) + user.groups.add(Group.objects.filter(name='Fincom')[0]) + + user.save() + + return HttpResponseRedirect('/committees') + +@login_required +def remove_fincom(request): + if (not request.user.groups.filter(name='Fincom').exists()): + return HttpResponseRedirect('/items') + + for u in request.POST.getlist('user'): + user = User.objects.get(pk=u) + user.groups.remove(Group.objects.filter(name='Fincom')[0]) + user.save() + + return HttpResponseRedirect('/committees') \ No newline at end of file diff --git a/fincom/urls.py b/fincom/urls.py index dca8259..583ca8c 100644 --- a/fincom/urls.py +++ b/fincom/urls.py @@ -21,6 +21,7 @@ urlpatterns = [ url(r'^$', views.index, name='index'), url(r'^logout$', views.user_logout, name='logout'), url(r'^items/', include('items.urls')), + url(r'^committees/', include('committee.urls')), url('', include('social_django.urls', namespace='social')), url(r'^admin/', admin.site.urls), ] diff --git a/items/views.py b/items/views.py index 4cab057..ad34d94 100644 --- a/items/views.py +++ b/items/views.py @@ -53,6 +53,8 @@ def list(request): 'newitems': pageItems(request, items, Item.NEW), 'rejected': pageItems(request, items, Item.REJECTED), 'mine': pageItems(request, mine, 'M'), + 'committees': Committee.objects.order_by('name'), + 'fincom': request.user.groups.filter(name='Fincom').exists(), } return HttpResponse(template.render(context, request)) diff --git a/static/css/site.css b/static/css/site.css index 98e6797..0d849e5 100644 --- a/static/css/site.css +++ b/static/css/site.css @@ -25,7 +25,8 @@ body { float: right; color: #fdd017; text-decoration: none; - font-size: 16px; } + font-size: 16px; + margin-left: 8px; } .pull-right { float: right; @@ -84,6 +85,11 @@ body { .details span { color: #969499; } +form.committee { + border-bottom: 1px solid #969499; + padding: 16px; + margin-bottom: 0; } + section { color: #969499; font-weight: lighter; diff --git a/static/sass/committee.scss b/static/sass/committee.scss new file mode 100644 index 0000000..d7a3049 --- /dev/null +++ b/static/sass/committee.scss @@ -0,0 +1,5 @@ +form.committee { + border-bottom: 1px solid $midgray; + padding: $pad-l; + margin-bottom: 0; +} diff --git a/static/sass/globals.scss b/static/sass/globals.scss index 00c7893..0b78935 100644 --- a/static/sass/globals.scss +++ b/static/sass/globals.scss @@ -44,6 +44,7 @@ body { color: $gold; text-decoration: none; font-size: 16px; + margin-left: $pad-m; } } diff --git a/static/sass/include.scss b/static/sass/include.scss index 6db8a5d..ef9deb1 100644 --- a/static/sass/include.scss +++ b/static/sass/include.scss @@ -1,5 +1,6 @@ @import 'globals'; @import 'details'; +@import 'committee'; @import 'items'; @import 'login'; @import 'new'; diff --git a/templates/boilerplate.html b/templates/boilerplate.html index a300af2..4b05dfc 100644 --- a/templates/boilerplate.html +++ b/templates/boilerplate.html @@ -8,6 +8,9 @@
diff --git a/templates/committee/edit.html b/templates/committee/edit.html new file mode 100644 index 0000000..fcbc670 --- /dev/null +++ b/templates/committee/edit.html @@ -0,0 +1,73 @@ +{% extends "../boilerplate.html" %} + +{% block main %} +
+ {% for C in committees %} +
+ {% csrf_token %} + + + + + + + +
+ {% endfor %} + +
+ {% csrf_token %} + + + + + + + +
+ +
+ {% csrf_token %} + + + + +
+ +
+ {% csrf_token %} +
+ {% for U in fincom %} + + {{ U.first_name }} {{ U.last_name }}
+ {% endfor %} + + +
+ +
+ Back +
+
+ +{% endblock %} \ No newline at end of file