Large commit of HR application, users can submit, admin can accept/reject

This commit is contained in:
2010-04-18 02:51:00 +01:00
parent a09a1073ab
commit 91fe2967c3
5 changed files with 84 additions and 5 deletions

View File

@@ -8,9 +8,14 @@ APPLICATION_STATUS_COMPLETED = 5
APPLICATION_STATUS_CHOICES = ( APPLICATION_STATUS_CHOICES = (
(APPLICATION_STATUS_NOTSUBMITTED, 'Not Submitted'), (APPLICATION_STATUS_NOTSUBMITTED, 'Not Submitted'),
(APPLICATION_STATUS_AWAITINGREVIEW, 'Awaiting Review'), (APPLICATION_STATUS_AWAITINGREVIEW, 'Submitted'),
(APPLICATION_STATUS_REJECTED, 'Rejected'), (APPLICATION_STATUS_REJECTED, 'Rejected'),
(APPLICATION_STATUS_ACCEPTED, 'Accepted'), (APPLICATION_STATUS_ACCEPTED, 'Accepted'),
(APPLICATION_STATUS_QUERY, 'In Query'), (APPLICATION_STATUS_QUERY, 'In Query'),
(APPLICATION_STATUS_COMPLETED, 'Completed'), (APPLICATION_STATUS_COMPLETED, 'Completed'),
) )
APPLICATION_STATUS_CHOICES_USER = (
(APPLICATION_STATUS_NOTSUBMITTED, 'Not Submitted'),
(APPLICATION_STATUS_AWAITINGREVIEW, 'Awaiting Review'),
)

View File

@@ -37,4 +37,20 @@ 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
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

View File

@@ -7,8 +7,11 @@ urlpatterns = patterns('',
(r'^recommendations/$', views.view_recommendations), (r'^recommendations/$', views.view_recommendations),
(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>.*)/$', views.view_application), (r'^applications/(?P<applicationid>\d+)/$', views.view_application),
(r'^applications/(?P<applicationid>\d+)/update/$', views.update_application),
(r'^add/application/$', views.add_application), (r'^add/application/$', views.add_application),
(r'^add/recommendation/$', views.add_recommendation), (r'^add/recommendation/$', views.add_recommendation),
(r'^admin/applications/$', views.admin_applications),
) )

View File

@@ -12,9 +12,10 @@ 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 from hr.forms import CreateRecommendationForm, CreateApplicationForm, CreateApplicationStatusForm
from hr.models import Recommendation, Application from hr.models import Recommendation, Application
from app_defines import *
def index(request): def index(request):
if request.user.is_staff or settings.HR_STAFF_GROUP in request.user.groups.all(): if request.user.is_staff or settings.HR_STAFF_GROUP in request.user.groups.all():
@@ -39,6 +40,15 @@ def view_application(request, applicationid):
if not app.user == request.user and not (request.user.is_staff or settings.HR_STAFF_GROUP in request.user.groups.all()): if not app.user == request.user and not (request.user.is_staff or settings.HR_STAFF_GROUP in request.user.groups.all()):
return HttpResponseRedirect(reverse('hr.views.index')) return HttpResponseRedirect(reverse('hr.views.index'))
if request.user.is_staff or settings.HR_STAFF_GROUP in request.user.groups.all():
hrstaff = True
else:
hrstaff = False
if hrstaff or app.status < 1:
appform = CreateApplicationStatusForm(hrstaff)
form = appform(initial={'application': app.id, 'new_status': app.status})
eveacc = EVEAccount.objects.filter(user=app.user) eveacc = EVEAccount.objects.filter(user=app.user)
redditacc = RedditAccount.objects.filter(user=app.user) redditacc = RedditAccount.objects.filter(user=app.user)
recs = Recommendation.objects.filter(application=app) recs = Recommendation.objects.filter(application=app)
@@ -63,7 +73,7 @@ def add_application(request):
app.corporation = form.cleaned_data['corporation'] app.corporation = form.cleaned_data['corporation']
app.save() app.save()
request.user.message_set.create(message="Your application to %s has been submitted." % 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_applications'))
else: else:
@@ -114,5 +124,34 @@ def add_recommendation(request):
return render_to_response('hr/recommendations/add.html', locals(), context_instance=RequestContext(request)) return render_to_response('hr/recommendations/add.html', locals(), context_instance=RequestContext(request))
@login_required
def admin_applications(request):
if not (request.user.is_staff or settings.HR_STAFF_GROUP in request.user.groups.all()):
return HttpResponseRedirect(reverse('hr.views.index'))
apps = Application.objects.filter(status=APPLICATION_STATUS_AWAITINGREVIEW)
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'])
hrstaff = (request.user.is_staff or 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'))
app.status = form.cleaned_data['new_status']
app.save()
if app.status == APPLICATION_STATUS_AWAITINGREVIEW:
app.user.message_set.create(message="Your application for %s to %s has been submitted." % (app.character, app.corporation))
if app.status == APPLICATION_STATUS_ACCEPTED:
app.user.message_set.create(message="Your application for %s to %s has been accepted." % (app.character, app.corporation))
elif app.status == APPLICATION_STATUS_REJECTED:
app.user.message_set.create(message="Your application for %s to %s has been rejected." % (app.character, app.corporation))
return HttpResponseRedirect(reverse('hr.views.view_application', args=[applicationid]))

View File

@@ -11,6 +11,15 @@
<li>Application Status: <b>{{ app.status_description }}</b></li> <li>Application Status: <b>{{ app.status_description }}</b></li>
</ul> </ul>
{% if form %}
<form action="/hr/applications/{{ app.id }}/update/" method="post">
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Apply" />
</form>
{% endif %}
{% if recs %} {% if recs %}
<h3>Recommendations</h3> <h3>Recommendations</h3>
<ul> <ul>
@@ -24,11 +33,18 @@
<ul> <ul>
{% for acc in eveacc %} {% for acc in eveacc %}
{% for char in acc.characters.all %} {% for char in acc.characters.all %}
<li><a href="/profile/characters/{{ char.id }}/">{{ char.name }}</a> - {{ char.corporation }}/{{ char.corporation.alliance }} <button type="button" onclick="CCPEVE.showInfo('1377//{{ char.id }}')">Show In Eve</button></li> <li><a href="/profile/characters/{{ char.id }}/">{{ char.name }}</a> - {{ char.corporation }} / {{ char.corporation.alliance }} <button type="button" onclick="CCPEVE.showInfo('1377//{{ char.id }}')">Show In Eve</button></li>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
</ul> </ul>
<h3>Reddit Accounts</h3>
<ul>
{% for acc in redditacc %}
<li><a href="http://reddit.com/user/{{ acc.username }}/">{{ acc.username }}</a>{% if acc.validated %} - Validated{% endif %} - {{ acc.date_created }}</li>
{% endfor %}
</ul>
<h3>Reddit Posts</h3> <h3>Reddit Posts</h3>
<ul> <ul>
{% for post in posts %} {% for post in posts %}