mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Initial commit of the HR management code
This commit is contained in:
0
hr/__init__.py
Normal file
0
hr/__init__.py
Normal file
17
hr/admin.py
Normal file
17
hr/admin.py
Normal file
@@ -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)
|
||||
|
||||
16
hr/app_defines.py
Normal file
16
hr/app_defines.py
Normal file
@@ -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'),
|
||||
)
|
||||
34
hr/forms.py
Normal file
34
hr/forms.py
Normal file
@@ -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
|
||||
|
||||
|
||||
40
hr/models.py
Normal file
40
hr/models.py
Normal file
@@ -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__()
|
||||
23
hr/tests.py
Normal file
23
hr/tests.py
Normal file
@@ -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
|
||||
"""}
|
||||
|
||||
14
hr/urls.py
Normal file
14
hr/urls.py
Normal file
@@ -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<recommendationid>.*)/$', views.view_recommendation),
|
||||
(r'^applications/$', views.view_applications),
|
||||
(r'^applications/(?P<applicationid>.*)/$', views.view_application),
|
||||
|
||||
(r'^add/application/$', views.add_application),
|
||||
(r'^add/recommendation/$', views.add_recommendation),
|
||||
)
|
||||
102
hr/views.py
Normal file
102
hr/views.py
Normal file
@@ -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))
|
||||
|
||||
|
||||
|
||||
@@ -15,17 +15,18 @@
|
||||
<div id="navigation">
|
||||
<ul>
|
||||
<li><a href="/">Home</a></li>
|
||||
{% if request.user %}
|
||||
<li><a href="/profile">Profile</a></li>
|
||||
<li><a href="/profile/characters">Characters</a></li>
|
||||
{% if request.user.is_staff %}
|
||||
<li><a href="/users">Lookup User</a></li>
|
||||
<li><a href="/admin">Admin</a></li>
|
||||
{% endif %}
|
||||
<li><a href="/logout">Logout</a></li>
|
||||
{% else %}
|
||||
<li><a href="/login">Login</a></li>
|
||||
{% endif %}
|
||||
{% if request.user %}
|
||||
<li><a href="/profile">Profile</a></li>
|
||||
<li><a href="/hr/">HR</a></li>
|
||||
<li><a href="/profile/characters">Characters</a></li>
|
||||
{% if request.user.is_staff %}
|
||||
<li><a href="/users">Lookup User</a></li>
|
||||
<li><a href="/admin">Admin</a></li>
|
||||
{% endif %}
|
||||
<li><a href="/logout">Logout</a></li>
|
||||
{% else %}
|
||||
<li><a href="/login">Login</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
||||
16
templates/hr/applications/add.html
Normal file
16
templates/hr/applications/add.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Add EVE API Key{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>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.</p>
|
||||
|
||||
<form action="/hr/add/recommendation/" method="post">
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Add Recommendation" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
26
templates/hr/applications/view_list.html
Normal file
26
templates/hr/applications/view_list.html
Normal file
@@ -0,0 +1,26 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Recommendations{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>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.</p>
|
||||
{% if recs %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>Recommender</th><th>Recommended Application</th><th>Application Status</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for rec in recs %}
|
||||
<tr><td>{{ rec.user_character }}</td>
|
||||
<td>{{ rec.application }}</td>
|
||||
<td>{{ rec.application.status_description }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<p>You have no current recommendations</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
22
templates/hr/index.html
Normal file
22
templates/hr/index.html
Normal file
@@ -0,0 +1,22 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}HR{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Applications</h3>
|
||||
<p><a href="/hr/applications/">View your current open applications</a><br/>
|
||||
<a href="/hr/add/application/">Create a application</a><br/></p>
|
||||
<h3>Recommendations</h3>
|
||||
<p>
|
||||
<a href="/hr/recommendations/">View your current open recommendations</a><br/>
|
||||
<a href="/hr/add/recommendation/">Add a recommendation</a><br/>
|
||||
</p>
|
||||
|
||||
{% if hrstaff %}
|
||||
<h3>HR Admin</h3>
|
||||
<p>
|
||||
<a href="/hr/admin/applications/">View applications</a><br/>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
16
templates/hr/recommendations/add.html
Normal file
16
templates/hr/recommendations/add.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Add EVE API Key{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>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.</p>
|
||||
|
||||
<form action="/hr/add/recommendation/" method="post">
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Add Recommendation" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
26
templates/hr/recommendations/view_list.html
Normal file
26
templates/hr/recommendations/view_list.html
Normal file
@@ -0,0 +1,26 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Recommendations{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>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.</p>
|
||||
{% if recs %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>Recommender</th><th>Recommended Application</th><th>Application Status</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for rec in recs %}
|
||||
<tr><td>{{ rec.user_character }}</td>
|
||||
<td>{{ rec.application }}</td>
|
||||
<td>{{ rec.application.status_description }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<p>You have no current recommendations</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user