Implement additional requests in #305

This commit is contained in:
Adarnof 2016-03-23 03:47:24 +00:00
parent eaa44c0254
commit a425d32405
4 changed files with 184 additions and 58 deletions

View File

@ -46,7 +46,7 @@ class Application(models.Model):
@property @property
def characters(self): def characters(self):
return EveCharacter.objects.filter(user=user) return EveCharacter.objects.filter(user=self.user)
@property @property
def apis(self): def apis(self):

View File

@ -2,6 +2,7 @@ from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404, redirect from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import user_passes_test
from django.shortcuts import HttpResponseRedirect from django.shortcuts import HttpResponseRedirect
from notifications import notify from notifications import notify
from models import HRApplication from models import HRApplication
@ -24,10 +25,18 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def create_application_test(user):
auth, c = AuthServicesInfo.objects.get_or_create(user=user)
if auth.main_char_id:
return True
else:
return False
@login_required @login_required
def hr_application_management_view(request): def hr_application_management_view(request):
logger.debug("hr_application_management_view called by user %s" % request.user) logger.debug("hr_application_management_view called by user %s" % request.user)
corp_applications = [] corp_applications = []
finished_corp_applications = []
auth_info, c = AuthServicesInfo.objects.get_or_create(user=request.user) auth_info, c = AuthServicesInfo.objects.get_or_create(user=request.user)
main_char = None main_char = None
if auth_info.main_char_id: if auth_info.main_char_id:
@ -41,14 +50,19 @@ def hr_application_management_view(request):
if ApplicationForm.objects.filter(corp__corporation_id=main_char.corporation_id).exists(): if ApplicationForm.objects.filter(corp__corporation_id=main_char.corporation_id).exists():
app_form = ApplicationForm.objects.get(corp__corporation_id=main_char.corporation_id) app_form = ApplicationForm.objects.get(corp__corporation_id=main_char.corporation_id)
corp_applications = Application.objects.filter(form=app_form).filter(approved=None) corp_applications = Application.objects.filter(form=app_form).filter(approved=None)
finished_corp_applications = Application.objects.filter(form=app_form).filter(approved__in=[True, False])
logger.debug("Retrieved %s personal, %s corp applications for %s" % (len(request.user.applications.all()), len(corp_applications), request.user)) logger.debug("Retrieved %s personal, %s corp applications for %s" % (len(request.user.applications.all()), len(corp_applications), request.user))
context = { context = {
'personal_apps': request.user.applications.all(), 'personal_apps': request.user.applications.all(),
'applications': corp_applications, 'applications': corp_applications,
'search_form': HRApplicationSearchForm()} 'finished_applications': finished_corp_applications,
'search_form': HRApplicationSearchForm(),
'create': create_application_test(request.user)
}
return render_to_response('registered/hrapplicationmanagement.html', context, context_instance=RequestContext(request)) return render_to_response('registered/hrapplicationmanagement.html', context, context_instance=RequestContext(request))
@login_required @login_required
@user_passes_test(create_application_test)
def hr_application_create_view(request, form_id=None): def hr_application_create_view(request, form_id=None):
if form_id: if form_id:
app_form = get_object_or_404(ApplicationForm, id=form_id) app_form = get_object_or_404(ApplicationForm, id=form_id)
@ -98,8 +112,11 @@ def hr_application_personal_removal(request, app_id):
logger.debug("hr_application_personal_removal called by user %s for app id %s" % (request.user, app_id)) logger.debug("hr_application_personal_removal called by user %s for app id %s" % (request.user, app_id))
app = get_object_or_404(Application, pk=app_id) app = get_object_or_404(Application, pk=app_id)
if app.user == request.user: if app.user == request.user:
if app.accepted == None:
logger.info("User %s deleting %s" % (request.user, app)) logger.info("User %s deleting %s" % (request.user, app))
app.delete() app.delete()
else:
logger.warn("User %s attempting to delete reviewed app %s" % (request.user, app))
else: else:
logger.warn("User %s not authorized to delete %s" % (request.user, app)) logger.warn("User %s not authorized to delete %s" % (request.user, app))
return redirect('auth_hrapplications_view') return redirect('auth_hrapplications_view')
@ -188,17 +205,35 @@ def hr_application_search(request):
form = HRApplicationSearchForm(request.POST) form = HRApplicationSearchForm(request.POST)
logger.debug("Request type POST contains form valid: %s" % form.is_valid()) logger.debug("Request type POST contains form valid: %s" % form.is_valid())
if form.is_valid(): if form.is_valid():
# Really dumb search and only checks character name searchstring = form.cleaned_data['search_string'].lower()
# This can be improved but it does the job for now
searchstring = form.cleaned_data['search_string']
applications = set([]) applications = set([])
logger.debug("Searching for application with character name %s for user %s" % (searchstring, request.user)) logger.debug("Searching for application with character name %s for user %s" % (searchstring, request.user))
app_list = []
for application in Application.objects.all(): if request.user.is_superuser:
app_list = Application.objects.all()
else:
auth_info = AuthServicesInfo.objects.get(user=request.user)
try:
character = EveCharacter.objects.get(character_id=auth_info.main_char_id)
app_list = Application.objects.filter(form__corp__corporation_id=character.corporation_id)
except:
logger.warn("User %s missing main character model: unable to filter applications to search" % request.user)
for application in app_list:
if application.main_character: if application.main_character:
if searchstring in application.main_character.character_name: if searchstring in application.main_character.character_name.lower():
applications.add(application) applications.add(application)
if searchstring in application.user.username: if searchstring in application.main_character.corporation_name.lower():
applications.add(application)
if searchstring in application.main_character.alliance_name.lower():\
applications.add(application)
for character in application.characters:
if searchstring in character.character_name.lower():
applications.add(application)
if searchstring in character.corporation_name.lower():
applications.add(application)
if searchstring in character.alliance_name.lower():
applications.add(application)
if searchstring in application.user.username.lower():
applications.add(application) applications.add(application)
logger.info("Found %s Applications for user %s matching search string %s" % (len(applications), request.user, searchstring)) logger.info("Found %s Applications for user %s matching search string %s" % (len(applications), request.user, searchstring))

View File

@ -12,13 +12,11 @@
{% if not perms.auth.member %} {% if not perms.auth.member %}
<h1 class="page-header text-center">Personal Applications <h1 class="page-header text-center">Personal Applications
<div class="text-right"> <div class="text-right">
<a href="{% url 'auth_hrapplication_create_view' %}"> {% if create %}
{% if personal_app %} <a href="{% url 'auth_hrapplication_create_view' %}"><button type="button" class="btn btn-success">Create Application</button></a>
<button type="button" class="btn btn-success" disabled>Create Application</button>
{% else %} {% else %}
<button type="button" class="btn btn-success">Create Application</button> <button type="button" class="btn btn-success" disabled>Create Application</button>
{% endif %} {% endif %}
</a>
</div> </div>
</h1> </h1>
<table class="table table-bordered table-condensed"> <table class="table table-bordered table-condensed">
@ -67,10 +65,16 @@
</button> </button>
</div> </div>
</h1> </h1>
<div class="container-fluid"> <ul class="nav nav-tabs">
<table class="table table-bordered"> <li class="active"><a data-toggle="tab" href="#pending">Pending</a></li>
<li><a data-toggle="tab" href="#reviewed">Reviewed</a></li>
</ul>
<div class="tab-content">
<div id="pending" class="tab-pane fade in active">
<div class="panel-body">
<table class="table">
<tr> <tr>
<th class="text-center">Application ID</th> <th class="text-center">Date</th>
<th class="text-center">Username</th> <th class="text-center">Username</th>
<th class="text-center">Main Character</th> <th class="text-center">Main Character</th>
<th class="text-center">Corporation</th> <th class="text-center">Corporation</th>
@ -79,17 +83,21 @@
</tr> </tr>
{% for app in applications %} {% for app in applications %}
<tr> <tr>
<td class="text-center">{{ app.id }}</td> <td class="text-center">{{ app.created }}</td>
<td class="text-center">{{ app.user.username }}</td> <td class="text-center">{{ app.user.username }}</td>
<td class="text-center">{{ app.main_character }}</td> <td class="text-center">{{ app.main_character }}</td>
<td class="text-center">{{ app.form.corp.corporation_name }}</td> <td class="text-center">{{ app.form.corp.corporation_name }}</td>
<td class="text-center"> <td class="text-center">
{% if app.approved_denied == None %} {% if app.approved_denied == None %}
<div class="panel panel-warning" role="alert">Pending</div> {% if app.reviewer_str %}
{% elif app.approved_denied == True %} <div class="label label-info">Reviewer: {{ app.reviewer_str }}</div>
<div class="panel panel-success" role="alert">Approved</div>
{% else %} {% else %}
<div class="panel panel-danger" role="alert">Rejected</div> <div class="label label-warning">Pending</div>
{% endif %}
{% elif app.approved_denied == True %}
<div class="label label-success">Approved</div>
{% else %}
<div class="label label-danger">Rejected</div>
{% endif %} {% endif %}
</td> </td>
<td class="text-center"> <td class="text-center">
@ -102,6 +110,49 @@
{% endfor %} {% endfor %}
</table> </table>
</div> </div>
</div>
<div id="reviewed" class="tab-pane fade">
<div class="panel-body">
<table class="table">
<tr>
<th class="text-center">Date</th>
<th class="text-center">Username</th>
<th class="text-center">Main Character</th>
<th class="text-center">Corporation</th>
<th class="text-center">Status</th>
<th class="text-center">Actions</th>
</tr>
{% for app in finished_applications %}
<tr>
<td class="text-center">{{ app.created }}</td>
<td class="text-center">{{ app.user.username }}</td>
<td class="text-center">{{ app.main_character }}</td>
<td class="text-center">{{ app.form.corp.corporation_name }}</td>
<td class="text-center">
{% if app.approved_denied == None %}
{% if app.reviewer_str %}
<div class="label label-info">Reviewer: {{ app.reviewer_str }}</div>
{% else %}
<div class="label label-warning">Pending</div>
{% endif %}
{% elif app.approved_denied == True %}
<div class="label label-success">Approved</div>
{% else %}
<div class="label label-danger">Rejected</div>
{% endif %}
</td>
<td class="text-center">
<a href="/hr_application_view/{{ app.id }}">
<button type="button" class="btn btn-primary"><span
class="glyphicon glyphicon-eye-open"></span></button>
</a>
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endif %} {% endif %}
</div> </div>

View File

@ -21,6 +21,44 @@
{% if app.reviewer_str %} {% if app.reviewer_str %}
<div class="alert alert-info">Reviewer: {{ app.reviewer_str }}</div> <div class="alert alert-info">Reviewer: {{ app.reviewer_str }}</div>
{% endif %} {% endif %}
</div>
<div class="row">
<div class="panel panel-info">
<div class="panel-heading">Applicant</div>
<table class="table">
<tr>
<th class="text-center">User</th>
<th class="text-center">Main Character</th>
</tr>
<tr>
<td class="text-center">{{ app.user }}</td>
<td class="text-center">{{ app.main_character }}</td>
</tr>
</table>
</div>
<div class="panel panel-info">
<div class="panel-heading">Characters</div>
<table class="table">
<tr>
<th class="text-center"></th>
<th class="text-center">Name</th>
<th class="text-center">Corp</th>
<th class="text-center">Alliance</th>
</tr>
{% for char in app.characters %}
<tr>
<td class="text-center">
<img class="ra-avatar img-responsive" src="https://image.eveonline.com/Character/{{ char.character_id }}_32.jpg">
</td>
<td class="text-center">{{ char.character_name }}</td>
<td class="text-center">{{ char.corporation_name }}</td>
<td class="text-center">{{ char.alliance_name }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
<div class="row">
{% for response in responses %} {% for response in responses %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">{{ response.question.title }}</div> <div class="panel-heading">{{ response.question.title }}</div>
@ -29,6 +67,7 @@
{% endfor %} {% endfor %}
</div> </div>
{% if buttons %} {% if buttons %}
<div class="row">
{% if perms.auth.human_resources %} {% if perms.auth.human_resources %}
<div class="panel panel-primary"> <div class="panel panel-primary">
<div class="panel-heading">Actions</div> <div class="panel-heading">Actions</div>
@ -83,6 +122,7 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
</div>
{% endif %} {% endif %}
</div> </div>
</div> </div>