mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +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_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_NOTSUBMITTED: 'Not 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 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 Meta:
|
||||
|
||||
@@ -8,7 +8,7 @@ urlpatterns = patterns('',
|
||||
(r'^recommendations/(?P<recommendationid>.*)/$', views.view_recommendation),
|
||||
(r'^applications/$', views.view_applications),
|
||||
(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+)/reject/$', views.reject_application),
|
||||
(r'^applications/(?P<applicationid>\d+)/accept/$', views.accept_application),
|
||||
|
||||
46
hr/views.py
46
hr/views.py
@@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
|
||||
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.contrib.auth.models import User, Group
|
||||
from django.contrib.auth.decorators import login_required
|
||||
@@ -13,7 +13,7 @@ import settings
|
||||
from eve_api.models import EVEAccount, EVEPlayerCorporation
|
||||
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 app_defines import *
|
||||
@@ -52,10 +52,7 @@ def view_applications(request):
|
||||
|
||||
@login_required
|
||||
def view_application(request, applicationid):
|
||||
try:
|
||||
app = Application.objects.get(id=applicationid)
|
||||
except Application.DoesNotExist:
|
||||
return HttpResponseRedirect(reverse('hr.views.index'))
|
||||
app = get_object_or_404(Application, id=applicationid)
|
||||
|
||||
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'))
|
||||
@@ -65,11 +62,7 @@ def view_application(request, applicationid):
|
||||
audit = app.audit_set.all()
|
||||
else:
|
||||
hrstaff = False
|
||||
audit = app.audit_set.filter(event__in=[AUDIT_EVENT_STATUSCHANGE, AUDIT_EVENT_REJECTION_REASON])
|
||||
|
||||
if hrstaff or app.status < 1:
|
||||
appform = CreateApplicationStatusForm(hrstaff)
|
||||
form = appform(initial={'application': app.id, 'new_status': app.status})
|
||||
audit = app.audit_set.filter(event__in=[AUDIT_EVENT_STATUSCHANGE, AUDIT_EVENT_REJECTION, AUDIT_EVENT_ACCEPTED])
|
||||
|
||||
eveacc = app.user.eveaccount_set.all()
|
||||
redditacc = app.user.redditaccount_set.all()
|
||||
@@ -101,7 +94,7 @@ def add_application(request):
|
||||
app.save()
|
||||
|
||||
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:
|
||||
form = clsform() # An unbound form
|
||||
@@ -120,10 +113,7 @@ def view_recommendations(request):
|
||||
|
||||
@login_required
|
||||
def view_recommendation(request, recommendationid):
|
||||
try:
|
||||
rec = Recommendation.objects.get(id=recommendationid, user=request.user)
|
||||
except Recommendation.DoesNotExist:
|
||||
return HttpResponseRedirect(reverse('hr.views.index'))
|
||||
rec = get_object_or_404(Recommendation, id=recommendationid, user=request.user)
|
||||
return render_to_response('hr/recommendations/view.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
@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))
|
||||
|
||||
@login_required
|
||||
def update_application(request, applicationid):
|
||||
if request.method == 'POST':
|
||||
appform = CreateApplicationStatusForm(True)
|
||||
form = appform(request.POST)
|
||||
if form.is_valid():
|
||||
app = Application.objects.get(id=form.cleaned_data['application'])
|
||||
def update_application(request, applicationid, status):
|
||||
|
||||
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'))
|
||||
hrstaff = (request.user.is_staff or Group.objects.get(name=settings.HR_STAFF_GROUP) in request.user.groups.all())
|
||||
|
||||
if not app.status == form.cleaned_data['new_status']:
|
||||
|
||||
app.status = form.cleaned_data['new_status']
|
||||
app.save(user=request.user)
|
||||
|
||||
if int(app.status) == APPLICATION_STATUS_ACCEPTED:
|
||||
send_message(app, 'accepted')
|
||||
# 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 = get_object_or_404(Application, id=applicationid)
|
||||
if not app.status == status:
|
||||
app.status = status
|
||||
app.save(user=request.user)
|
||||
|
||||
return HttpResponseRedirect(reverse('hr.views.view_application', args=[applicationid]))
|
||||
|
||||
|
||||
@@ -14,18 +14,15 @@
|
||||
</ul>
|
||||
|
||||
<h3>Actions</h3>
|
||||
{% if form %}
|
||||
<form action="{% url hr.views.update_application app.id %}" method="post">
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Apply" />
|
||||
</form>
|
||||
{% endif %}
|
||||
<p>
|
||||
{% ifequal app.status 0 %}
|
||||
<a href="{% url hr.views.update_application app.id 1 %}">Submit Application</a>
|
||||
{% endifequal %}
|
||||
|
||||
{% 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 %}
|
||||
</p>
|
||||
|
||||
{% if audit %}
|
||||
<h3>Event Log</h3>
|
||||
|
||||
Reference in New Issue
Block a user