diff --git a/hr/__init__.py b/hr/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hr/admin.py b/hr/admin.py new file mode 100644 index 0000000..18dad44 --- /dev/null +++ b/hr/admin.py @@ -0,0 +1,17 @@ +from django.contrib import admin +from django.contrib.auth.models import User +from django.contrib.auth.admin import UserAdmin +from hr.models import Application, Recommendation + +class ApplicationAdmin(admin.ModelAdmin): + list_display = ('user', 'character', 'status') + search_fields = ['user', 'character', 'status'] + +admin.site.register(Application, ApplicationAdmin) + +class RecommendationAdmin(admin.ModelAdmin): + list_display = ('user', 'user_character') + search_fields = ['user_character'] + +admin.site.register(Recommendation, RecommendationAdmin) + diff --git a/hr/app_defines.py b/hr/app_defines.py new file mode 100644 index 0000000..60c81d0 --- /dev/null +++ b/hr/app_defines.py @@ -0,0 +1,16 @@ + +APPLICATION_STATUS_NOTSUBMITTED = 0 +APPLICATION_STATUS_AWAITINGREVIEW = 1 +APPLICATION_STATUS_REJECTED = 2 +APPLICATION_STATUS_ACCEPTED = 3 +APPLICATION_STATUS_QUERY = 4 +APPLICATION_STATUS_COMPLETED = 5 + +APPLICATION_STATUS_CHOICES = ( + (APPLICATION_STATUS_NOTSUBMITTED, 'Not Submitted'), + (APPLICATION_STATUS_AWAITINGREVIEW, 'Awaiting Review'), + (APPLICATION_STATUS_REJECTED, 'Rejected'), + (APPLICATION_STATUS_ACCEPTED, 'Accepted'), + (APPLICATION_STATUS_QUERY, 'In Query'), + (APPLICATION_STATUS_COMPLETED, 'Completed'), +) diff --git a/hr/forms.py b/hr/forms.py new file mode 100644 index 0000000..e3be592 --- /dev/null +++ b/hr/forms.py @@ -0,0 +1,34 @@ +from django import forms +import settings + +from hr.app_defines import * +from hr.models import Application +from eve_api.models import EVEPlayerCharacter + +def CreateRecommendationForm(user): + """ Generate a Recommendation form based on the user's permissions """ + + characters = EVEPlayerCharacter.objects.filter(eveaccount__user=user) + applications = Application.objects.filter(status=APPLICATION_STATUS_NOTSUBMITTED) + + class RecommendationForm(forms.Form): + """ Service Account Form """ + + character = forms.ModelChoiceField(queryset=characters, required=True, empty_label=None) + application = forms.ModelChoiceField(queryset=applications, required=True, empty_label=None) + + return RecommendationForm + + +def CreateApplicationForm(user): + """ Generate a Application form based on the user's permissions """ + + characters = EVEPlayerCharacter.objects.filter(eveaccount__user=user) + corporations = EVEPlayerCorporation.objects.filter(applications=True) + + class ApplicationForm(forms.Form): + character = forms.ModelChoiceField(queryset=characters, required=True, empty_label=None) + + return ApplicationForm + + diff --git a/hr/models.py b/hr/models.py new file mode 100644 index 0000000..66ae9a6 --- /dev/null +++ b/hr/models.py @@ -0,0 +1,40 @@ +from datetime import datetime + +from django.db import models +from django.contrib.auth.models import User + +from eve_api.models import EVEPlayerCharacter, EVEPlayerCorporation + +from hr.app_defines import * + +class Application(models.Model): + user = models.ForeignKey(User, blank=False, verbose_name="User") + character = models.ForeignKey(EVEPlayerCharacter, blank=False, verbose_name="Character") + corporation = models.ForeignKey(EVEPlayerCorporation, blank=False, verbose_name="Applying to Corporation") + status = models.IntegerField(choices=APPLICATION_STATUS_CHOICES, + default=APPLICATION_STATUS_NOTSUBMITTED, + verbose_name="Status", + help_text="Current status of this application request.") + + @property + def status_description(self): + for choice in APPLICATION_STATUS_CHOICES: + if choice[0] == self.status: + return choice[1] + + def __unicode__(self): + return self.character.name + + def __str__(self): + return self.__unicode__() + +class Recommendation(models.Model): + user = models.ForeignKey(User, blank=False, verbose_name="User") + user_character = models.ForeignKey(EVEPlayerCharacter, blank=False, verbose_name="Recommender") + application = models.ForeignKey(Application, blank=False, verbose_name="Recommended Application") + + def __unicode__(self): + return self.user_character.name + + def __str__(self): + return self.__unicode__() diff --git a/hr/tests.py b/hr/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/hr/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/hr/urls.py b/hr/urls.py new file mode 100644 index 0000000..68cd0c9 --- /dev/null +++ b/hr/urls.py @@ -0,0 +1,14 @@ +from django.conf.urls.defaults import * + +from hr import views + +urlpatterns = patterns('', + ('^$', views.index), + (r'^recommendations/$', views.view_recommendations), + (r'^recommendations/(?P.*)/$', views.view_recommendation), + (r'^applications/$', views.view_applications), + (r'^applications/(?P.*)/$', views.view_application), + + (r'^add/application/$', views.add_application), + (r'^add/recommendation/$', views.add_recommendation), +) diff --git a/hr/views.py b/hr/views.py new file mode 100644 index 0000000..c622a7a --- /dev/null +++ b/hr/views.py @@ -0,0 +1,102 @@ +import datetime + +from django.http import HttpResponseRedirect +from django.shortcuts import render_to_response +from django.core.urlresolvers import reverse +from django.contrib.auth.models import User +from django.contrib.auth.decorators import login_required +from django.template import RequestContext + +from hr.forms import CreateRecommendationForm, CreateApplicationForm +from hr.models import Recommendation, Application + + +def index(request): + if request.user.is_staff or 'hrstaff' in request.user.groups.all(): + hrstaff = True + + return render_to_response('hr/index.html', locals(), context_instance=RequestContext(request)) + +### Application Management + +@login_required +def view_applications(request): + apps = Application.objects.filter(user=request.user) + return render_to_response('hr/applications/view_list.html', locals(), context_instance=RequestContext(request)) + +@login_required +def view_application(request, applicationid): + try: + app = Application.objects.get(id=applicationid) + except Application.DoesNotExist: + return HttpResponseRedirect(reverse('hr.views.index')) + return render_to_response('hr/applications/view.html', locals(), context_instance=RequestContext(request)) + +@login_required +def add_application(request): + + clsform = CreateApplicationForm(request.user) + if request.method == 'POST': + form = clsform(request.POST) + if form.is_valid(): + app = Application() + + app.user = request.user + app.character = form.cleaned_data['character'] + app.corporation = form.cleaned_data['corporation'] + app.save() + + request.user.message_set.create(message="Application has been submitted." % rec.application ) + return HttpResponseRedirect(reverse('hr.views.view_applications')) + else: + return HttpResponseRedirect(reverse('hr.views.add_application')) + + else: + form = clsform() # An unbound form + + return render_to_response('hr/applications/add.html', locals(), context_instance=RequestContext(request)) + +### Recommendation Management + +@login_required +def view_recommendations(request): + recs = Recommendation.objects.filter(user=request.user, application__status=0) + return render_to_response('hr/recommendations/view_list.html', locals(), context_instance=RequestContext(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')) + return render_to_response('hr/recommendations/view.html', locals(), context_instance=RequestContext(request)) + +@login_required +def add_recommendation(request): + + clsform = CreateRecommendationForm(request.user) + + if request.method == 'POST': + form = clsform(request.POST) + if form.is_valid(): + rec = Recommendation() + + rec.user = request.user + rec.user_character = form.cleaned_data['character'] + rec.application = form.cleaned_data['application'] + rec.created_by = request.user + rec.last_updated_by = request.user + rec.save() + + request.user.message_set.create(message="Recommendation added to %s's application" % rec.application ) + return HttpResponseRedirect(reverse('hr.views.view_recommendations')) + else: + return HttpResponseRedirect(reverse('hr.views.add_recommendation')) + + else: + form = clsform() # An unbound form + + return render_to_response('hr/recommendations/add.html', locals(), context_instance=RequestContext(request)) + + + diff --git a/templates/base.html b/templates/base.html index 762855c..7c8b1b0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -15,17 +15,18 @@
diff --git a/templates/hr/applications/add.html b/templates/hr/applications/add.html new file mode 100644 index 0000000..4a14c5c --- /dev/null +++ b/templates/hr/applications/add.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}Add EVE API Key{% endblock %} + +{% block content %} +

Select a character you wish to recommend from, then select your friend's current application. + +The person you are recommending needs to have created their application before you can add a recommendation.

+ +
+ +{{ form.as_table }} +
+ +
+{% endblock %} diff --git a/templates/hr/applications/view_list.html b/templates/hr/applications/view_list.html new file mode 100644 index 0000000..743d700 --- /dev/null +++ b/templates/hr/applications/view_list.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% block title %}Recommendations{% endblock %} + +{% block content %} +

This list shows your current open recommendations that are yet to be submitted, as +soon as the recommended user submits their application your recommendation will be removed from this list.

+{% if recs %} + + + + + +{% for rec in recs %} + + + + + +{% endfor %} +
RecommenderRecommended ApplicationApplication Status
{{ rec.user_character }}{{ rec.application }}{{ rec.application.status_description }}
+{% else %} +

You have no current recommendations

+{% endif %} + +{% endblock %} diff --git a/templates/hr/index.html b/templates/hr/index.html new file mode 100644 index 0000000..f5cc749 --- /dev/null +++ b/templates/hr/index.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block title %}HR{% endblock %} + +{% block content %} +

Applications

+

View your current open applications
+Create a application

+

Recommendations

+

+View your current open recommendations
+Add a recommendation
+

+ +{% if hrstaff %} +

HR Admin

+

+View applications
+

+{% endif %} + +{% endblock %} diff --git a/templates/hr/recommendations/add.html b/templates/hr/recommendations/add.html new file mode 100644 index 0000000..4a14c5c --- /dev/null +++ b/templates/hr/recommendations/add.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}Add EVE API Key{% endblock %} + +{% block content %} +

Select a character you wish to recommend from, then select your friend's current application. + +The person you are recommending needs to have created their application before you can add a recommendation.

+ +
+ +{{ form.as_table }} +
+ +
+{% endblock %} diff --git a/templates/hr/recommendations/view_list.html b/templates/hr/recommendations/view_list.html new file mode 100644 index 0000000..743d700 --- /dev/null +++ b/templates/hr/recommendations/view_list.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% block title %}Recommendations{% endblock %} + +{% block content %} +

This list shows your current open recommendations that are yet to be submitted, as +soon as the recommended user submits their application your recommendation will be removed from this list.

+{% if recs %} + + + + + +{% for rec in recs %} + + + + + +{% endfor %} +
RecommenderRecommended ApplicationApplication Status
{{ rec.user_character }}{{ rec.application }}{{ rec.application.status_description }}
+{% else %} +

You have no current recommendations

+{% endif %} + +{% endblock %}