mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 23:02:19 +00:00
Removed the need for forms to update the Application status.
This commit is contained in:
@@ -15,18 +15,6 @@ APPLICATION_STATUS_CHOICES = (
|
|||||||
(APPLICATION_STATUS_COMPLETED, 'Completed'),
|
(APPLICATION_STATUS_COMPLETED, 'Completed'),
|
||||||
)
|
)
|
||||||
|
|
||||||
APPLICATION_STATUS_CHOICES_ADMIN = (
|
|
||||||
(APPLICATION_STATUS_NOTSUBMITTED, 'Not Submitted'),
|
|
||||||
(APPLICATION_STATUS_AWAITINGREVIEW, 'Submitted'),
|
|
||||||
(APPLICATION_STATUS_QUERY, 'In Query'),
|
|
||||||
(APPLICATION_STATUS_COMPLETED, 'Completed'),
|
|
||||||
)
|
|
||||||
|
|
||||||
APPLICATION_STATUS_CHOICES_USER = (
|
|
||||||
(APPLICATION_STATUS_NOTSUBMITTED, 'Not Submitted'),
|
|
||||||
(APPLICATION_STATUS_AWAITINGREVIEW, 'Submitted'),
|
|
||||||
)
|
|
||||||
|
|
||||||
APPLICATION_STATUS_LOOKUP = {
|
APPLICATION_STATUS_LOOKUP = {
|
||||||
APPLICATION_STATUS_NOTSUBMITTED: 'Not Submitted',
|
APPLICATION_STATUS_NOTSUBMITTED: 'Not Submitted',
|
||||||
APPLICATION_STATUS_AWAITINGREVIEW: 'Submitted',
|
APPLICATION_STATUS_AWAITINGREVIEW: 'Submitted',
|
||||||
|
|||||||
19
hr/forms.py
19
hr/forms.py
@@ -37,25 +37,6 @@ def CreateApplicationForm(user):
|
|||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
return ApplicationForm
|
return ApplicationForm
|
||||||
|
|
||||||
def CreateApplicationStatusForm(admin):
|
|
||||||
|
|
||||||
if admin:
|
|
||||||
form_choices = APPLICATION_STATUS_CHOICES_ADMIN
|
|
||||||
else:
|
|
||||||
form_choices = APPLICATION_STATUS_CHOICES_USER
|
|
||||||
|
|
||||||
class ApplicationStatusForm(forms.Form):
|
|
||||||
""" Application Status Change Form """
|
|
||||||
|
|
||||||
application = forms.IntegerField(required=True, widget=forms.HiddenInput)
|
|
||||||
new_status = forms.ChoiceField(label = u'New Status', choices = form_choices)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
exclude = ('application')
|
|
||||||
|
|
||||||
return ApplicationStatusForm
|
|
||||||
|
|
||||||
|
|
||||||
class NoteForm(forms.ModelForm):
|
class NoteForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ urlpatterns = patterns('',
|
|||||||
(r'^recommendations/(?P<recommendationid>.*)/$', views.view_recommendation),
|
(r'^recommendations/(?P<recommendationid>.*)/$', views.view_recommendation),
|
||||||
(r'^applications/$', views.view_applications),
|
(r'^applications/$', views.view_applications),
|
||||||
(r'^applications/(?P<applicationid>\d+)/$', views.view_application),
|
(r'^applications/(?P<applicationid>\d+)/$', views.view_application),
|
||||||
(r'^applications/(?P<applicationid>\d+)/update/$', views.update_application),
|
(r'^applications/(?P<applicationid>\d+)/update/(?P<status>\d+)/$', views.update_application),
|
||||||
(r'^applications/(?P<applicationid>\d+)/note/$', views.add_note),
|
(r'^applications/(?P<applicationid>\d+)/note/$', views.add_note),
|
||||||
(r'^applications/(?P<applicationid>\d+)/reject/$', views.reject_application),
|
(r'^applications/(?P<applicationid>\d+)/reject/$', views.reject_application),
|
||||||
(r'^applications/(?P<applicationid>\d+)/accept/$', views.accept_application),
|
(r'^applications/(?P<applicationid>\d+)/accept/$', views.accept_application),
|
||||||
|
|||||||
46
hr/views.py
46
hr/views.py
@@ -1,7 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
@@ -13,7 +13,7 @@ import settings
|
|||||||
from eve_api.models import EVEAccount, EVEPlayerCorporation
|
from eve_api.models import EVEAccount, EVEPlayerCorporation
|
||||||
from reddit.models import RedditAccount
|
from reddit.models import RedditAccount
|
||||||
|
|
||||||
from hr.forms import CreateRecommendationForm, CreateApplicationForm, CreateApplicationStatusForm, NoteForm
|
from hr.forms import CreateRecommendationForm, CreateApplicationForm, NoteForm
|
||||||
from hr.models import Recommendation, Application, Audit
|
from hr.models import Recommendation, Application, Audit
|
||||||
|
|
||||||
from app_defines import *
|
from app_defines import *
|
||||||
@@ -52,10 +52,7 @@ def view_applications(request):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def view_application(request, applicationid):
|
def view_application(request, applicationid):
|
||||||
try:
|
app = get_object_or_404(Application, id=applicationid)
|
||||||
app = Application.objects.get(id=applicationid)
|
|
||||||
except Application.DoesNotExist:
|
|
||||||
return HttpResponseRedirect(reverse('hr.views.index'))
|
|
||||||
|
|
||||||
if not app.user == request.user and not (request.user.is_staff or Group.objects.get(name=settings.HR_STAFF_GROUP) in request.user.groups.all()):
|
if not app.user == request.user and not (request.user.is_staff or Group.objects.get(name=settings.HR_STAFF_GROUP) in request.user.groups.all()):
|
||||||
return HttpResponseRedirect(reverse('hr.views.index'))
|
return HttpResponseRedirect(reverse('hr.views.index'))
|
||||||
@@ -65,11 +62,7 @@ def view_application(request, applicationid):
|
|||||||
audit = app.audit_set.all()
|
audit = app.audit_set.all()
|
||||||
else:
|
else:
|
||||||
hrstaff = False
|
hrstaff = False
|
||||||
audit = app.audit_set.filter(event__in=[AUDIT_EVENT_STATUSCHANGE, AUDIT_EVENT_REJECTION_REASON])
|
audit = app.audit_set.filter(event__in=[AUDIT_EVENT_STATUSCHANGE, AUDIT_EVENT_REJECTION, AUDIT_EVENT_ACCEPTED])
|
||||||
|
|
||||||
if hrstaff or app.status < 1:
|
|
||||||
appform = CreateApplicationStatusForm(hrstaff)
|
|
||||||
form = appform(initial={'application': app.id, 'new_status': app.status})
|
|
||||||
|
|
||||||
eveacc = app.user.eveaccount_set.all()
|
eveacc = app.user.eveaccount_set.all()
|
||||||
redditacc = app.user.redditaccount_set.all()
|
redditacc = app.user.redditaccount_set.all()
|
||||||
@@ -101,7 +94,7 @@ def add_application(request):
|
|||||||
app.save()
|
app.save()
|
||||||
|
|
||||||
request.user.message_set.create(message="Your application to %s has been created." % app.corporation)
|
request.user.message_set.create(message="Your application to %s has been created." % app.corporation)
|
||||||
return HttpResponseRedirect(reverse('hr.views.view_applications'))
|
return HttpResponseRedirect(reverse('hr.views.view_application', args=[app.id]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
form = clsform() # An unbound form
|
form = clsform() # An unbound form
|
||||||
@@ -120,10 +113,7 @@ def view_recommendations(request):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def view_recommendation(request, recommendationid):
|
def view_recommendation(request, recommendationid):
|
||||||
try:
|
rec = get_object_or_404(Recommendation, id=recommendationid, user=request.user)
|
||||||
rec = Recommendation.objects.get(id=recommendationid, user=request.user)
|
|
||||||
except Recommendation.DoesNotExist:
|
|
||||||
return HttpResponseRedirect(reverse('hr.views.index'))
|
|
||||||
return render_to_response('hr/recommendations/view.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('hr/recommendations/view.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -161,24 +151,16 @@ def admin_applications(request):
|
|||||||
return render_to_response('hr/applications/admin/view_list.html', locals(), context_instance=RequestContext(request))
|
return render_to_response('hr/applications/admin/view_list.html', locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def update_application(request, applicationid):
|
def update_application(request, applicationid, status):
|
||||||
if request.method == 'POST':
|
|
||||||
appform = CreateApplicationStatusForm(True)
|
|
||||||
form = appform(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
app = Application.objects.get(id=form.cleaned_data['application'])
|
|
||||||
|
|
||||||
hrstaff = (request.user.is_staff or Group.objects.get(name=settings.HR_STAFF_GROUP) in request.user.groups.all())
|
hrstaff = (request.user.is_staff or Group.objects.get(name=settings.HR_STAFF_GROUP) in request.user.groups.all())
|
||||||
if not hrstaff and int(form.cleaned_data['new_status']) > 1:
|
|
||||||
return HttpResponseRedirect(reverse('hr.views.index'))
|
|
||||||
|
|
||||||
if not app.status == form.cleaned_data['new_status']:
|
# Allow admins and users that are setting the application as awaiting review
|
||||||
|
if hrstaff or (app.user == request.user and status == APPLICATION_STATUS_AWAITINGREVIEW):
|
||||||
app.status = form.cleaned_data['new_status']
|
app = get_object_or_404(Application, id=applicationid)
|
||||||
app.save(user=request.user)
|
if not app.status == status:
|
||||||
|
app.status = status
|
||||||
if int(app.status) == APPLICATION_STATUS_ACCEPTED:
|
app.save(user=request.user)
|
||||||
send_message(app, 'accepted')
|
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('hr.views.view_application', args=[applicationid]))
|
return HttpResponseRedirect(reverse('hr.views.view_application', args=[applicationid]))
|
||||||
|
|
||||||
|
|||||||
@@ -14,18 +14,15 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3>Actions</h3>
|
<h3>Actions</h3>
|
||||||
{% if form %}
|
<p>
|
||||||
<form action="{% url hr.views.update_application app.id %}" method="post">
|
{% ifequal app.status 0 %}
|
||||||
<table>
|
<a href="{% url hr.views.update_application app.id 1 %}">Submit Application</a>
|
||||||
{{ form.as_table }}
|
{% endifequal %}
|
||||||
</table>
|
|
||||||
<input type="submit" value="Apply" />
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if hrstaff %}
|
{% if hrstaff %}
|
||||||
<p><a href="{% url hr.views.add_note app.id %}">Add Note</a>, <a href="{% url hr.views.reject_application app.id %}">Reject Application</a>, <a href="{% url hr.views.accept_application app.id %}">Accept Application</a></p>
|
<a href="{% url hr.views.add_note app.id %}">Add Note</a>, <a href="{% url hr.views.reject_application app.id %}">Reject Application</a>, <a href="{% url hr.views.accept_application app.id %}">Accept Application</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
|
||||||
{% if audit %}
|
{% if audit %}
|
||||||
<h3>Event Log</h3>
|
<h3>Event Log</h3>
|
||||||
|
|||||||
Reference in New Issue
Block a user