diff --git a/hr/app_defines.py b/hr/app_defines.py index 60c81d0..f3c52b2 100644 --- a/hr/app_defines.py +++ b/hr/app_defines.py @@ -8,9 +8,14 @@ APPLICATION_STATUS_COMPLETED = 5 APPLICATION_STATUS_CHOICES = ( (APPLICATION_STATUS_NOTSUBMITTED, 'Not Submitted'), - (APPLICATION_STATUS_AWAITINGREVIEW, 'Awaiting Review'), + (APPLICATION_STATUS_AWAITINGREVIEW, 'Submitted'), (APPLICATION_STATUS_REJECTED, 'Rejected'), (APPLICATION_STATUS_ACCEPTED, 'Accepted'), (APPLICATION_STATUS_QUERY, 'In Query'), (APPLICATION_STATUS_COMPLETED, 'Completed'), ) + +APPLICATION_STATUS_CHOICES_USER = ( + (APPLICATION_STATUS_NOTSUBMITTED, 'Not Submitted'), + (APPLICATION_STATUS_AWAITINGREVIEW, 'Awaiting Review'), +) diff --git a/hr/forms.py b/hr/forms.py index 7134da6..3c7fc00 100644 --- a/hr/forms.py +++ b/hr/forms.py @@ -37,4 +37,20 @@ def CreateApplicationForm(user): return self.cleaned_data 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 diff --git a/hr/urls.py b/hr/urls.py index 68cd0c9..35c6b21 100644 --- a/hr/urls.py +++ b/hr/urls.py @@ -7,8 +7,11 @@ urlpatterns = patterns('', (r'^recommendations/$', views.view_recommendations), (r'^recommendations/(?P.*)/$', views.view_recommendation), (r'^applications/$', views.view_applications), - (r'^applications/(?P.*)/$', views.view_application), + (r'^applications/(?P\d+)/$', views.view_application), + (r'^applications/(?P\d+)/update/$', views.update_application), (r'^add/application/$', views.add_application), (r'^add/recommendation/$', views.add_recommendation), + + (r'^admin/applications/$', views.admin_applications), ) diff --git a/hr/views.py b/hr/views.py index a55e76a..28c05e2 100644 --- a/hr/views.py +++ b/hr/views.py @@ -12,9 +12,10 @@ import settings from eve_api.models import EVEAccount, EVEPlayerCorporation 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 app_defines import * def index(request): 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()): 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) redditacc = RedditAccount.objects.filter(user=app.user) recs = Recommendation.objects.filter(application=app) @@ -63,7 +73,7 @@ def add_application(request): app.corporation = form.cleaned_data['corporation'] 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')) else: @@ -114,5 +124,34 @@ def add_recommendation(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])) diff --git a/templates/hr/applications/view.html b/templates/hr/applications/view.html index 6b3e93d..e8080f4 100644 --- a/templates/hr/applications/view.html +++ b/templates/hr/applications/view.html @@ -11,6 +11,15 @@
  • Application Status: {{ app.status_description }}
  • +{% if form %} +
    + +{{ form.as_table }} +
    + +
    +{% endif %} + {% if recs %}

    Recommendations

      @@ -24,11 +33,18 @@
        {% for acc in eveacc %} {% for char in acc.characters.all %} -
      • {{ char.name }} - {{ char.corporation }}/{{ char.corporation.alliance }}
      • +
      • {{ char.name }} - {{ char.corporation }} / {{ char.corporation.alliance }}
      • {% endfor %} {% endfor %}
      +

      Reddit Accounts

      +
        +{% for acc in redditacc %} +
      • {{ acc.username }}{% if acc.validated %} - Validated{% endif %} - {{ acc.date_created }}
      • +{% endfor %} +
      +

      Reddit Posts

        {% for post in posts %}