Correct display of non-default CorpStats

Correct display of application comments
Beautify notifications panel
This commit is contained in:
Adarnof 2017-03-27 12:48:24 -04:00
parent 04053c8465
commit 3063355eb7
3 changed files with 96 additions and 77 deletions

View File

@ -8,6 +8,7 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.conf import settings from django.conf import settings
from eveonline.models import EveCharacter, EveCorporationInfo from eveonline.models import EveCharacter, EveCorporationInfo
from eveonline.managers import EveManager
from corputils.models import CorpStats from corputils.models import CorpStats
from esi.decorators import token_required from esi.decorators import token_required
from bravado.exception import HTTPError from bravado.exception import HTTPError
@ -41,9 +42,12 @@ def corpstats_add(request, token):
corp_id = EveCharacter.objects.get(character_id=token.character_id).corporation_id corp_id = EveCharacter.objects.get(character_id=token.character_id).corporation_id
else: else:
corp_id = \ corp_id = \
token.get_esi_client(Character='v4').Character.get_characters_character_id(character_id=token.character_id).result()[ token.get_esi_client(Character='v4').Character.get_characters_character_id(
'corporation_id'] character_id=token.character_id).result()['corporation_id']
corp = EveCorporationInfo.objects.get(corporation_id=corp_id) try:
corp = EveCorporationInfo.objects.get(corporation_id=corp_id)
except EveCorporationInfo.DoesNotExist:
corp = EveManager.create_corporation(corp_id)
cs = CorpStats.objects.create(token=token, corp=corp) cs = CorpStats.objects.create(token=token, corp=corp)
try: try:
cs.update() cs.update()
@ -52,8 +56,6 @@ def corpstats_add(request, token):
assert cs.pk # ensure update was successful assert cs.pk # ensure update was successful
if CorpStats.objects.filter(pk=cs.pk).visible_to(request.user).exists(): if CorpStats.objects.filter(pk=cs.pk).visible_to(request.user).exists():
return redirect('corputils:view_corp', corp_id=corp.corporation_id) return redirect('corputils:view_corp', corp_id=corp.corporation_id)
except EveCorporationInfo.DoesNotExist:
messages.error(request, _('Unrecognized corporation. Please ensure it is a member of the alliance or a blue.'))
except IntegrityError: except IntegrityError:
messages.error(request, _('Selected corp already has a statistics module.')) messages.error(request, _('Selected corp already has a statistics module.'))
except AssertionError: except AssertionError:
@ -81,7 +83,7 @@ def corpstats_view(request, corp_id=None):
# get default model if none requested # get default model if none requested
if not corp_id and available.count() == 1: if not corp_id and available.count() == 1:
corpstats = available[0] corpstats = available[0]
elif available.count() > 1 and request.user.profile.main_character: elif not corp_id and available.count() > 1 and request.user.profile.main_character:
# get their main corp if available # get their main corp if available
try: try:
corpstats = available.get(corp__corporation_id=request.user.profile.main_character.corporation_id) corpstats = available.get(corp__corporation_id=request.user.profile.main_character.corporation_id)
@ -134,7 +136,8 @@ def corpstats_search(request):
results = [] results = []
search_string = request.GET.get('search_string', None) search_string = request.GET.get('search_string', None)
if search_string: if search_string:
has_similar = CorpStats.objects.filter(members__character_name__icontains=search_string).visible_to(request.user).distinct() has_similar = CorpStats.objects.filter(members__character_name__icontains=search_string).visible_to(
request.user).distinct()
for corpstats in has_similar: for corpstats in has_similar:
similar = corpstats.members.filter(character_name__icontains=search_string) similar = corpstats.members.filter(character_name__icontains=search_string)
for s in similar: for s in similar:

View File

@ -109,7 +109,7 @@
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" <a class="collapsed" data-toggle="collapse" data-parent="#accordion"
href="#collapseThree" aria-expanded="false" href="#collapseThree" aria-expanded="false"
aria-controls="collapseThree"> aria-controls="collapseThree">
{% blocktrans %}Comments - {{ comments|length }}{% endblocktrans %} {% trans 'Comments' %} ({{ comments.count }})
</a> </a>
</h4> </h4>
</div> </div>
@ -119,7 +119,11 @@
{% for comment in comments %} {% for comment in comments %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading" role="tab" id=""> <div class="panel-heading" role="tab" id="">
<div class="panel-title">{{ comment.created }} - {{ comment.user }}</div> <div class="panel-title">
<div class="pull-right">{{ comment.created }}</div>
<div class="pull-left">{% if comment.user.profile.main_character %}{{ comment.user.profile.main_character }}{% else %}{{ comment.user }}{% endif %}</div>
<div class="clearfix"></div>
</div>
</div> </div>
<div class="panel-body">{{ comment.text|linebreaks }}</div> <div class="panel-body">{{ comment.text|linebreaks }}</div>
</div> </div>

View File

@ -5,79 +5,91 @@
{% block title %}{% trans "Notifications" %}{% endblock %} {% block title %}{% trans "Notifications" %}{% endblock %}
{% block content %} {% block content %}
<div class="col-lg-12"> <div class="col-lg-12">
<h1 class="page-header text-center">{% trans "Notifications" %}</h1> <h1 class="page-header text-center">{% trans "Notifications" %}</h1>
<div class="col-lg-12 container" id="example"> <div class="col-lg-12 container" id="example">
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<ul class="nav nav-tabs"> <div class="panel panel-default">
<li class="active"><a data-toggle="tab" href="#unread">{% trans "Unread" %} <b>({{unread|length}})</b></a></li> <div class="panel-heading">
<li><a data-toggle="tab" href="#read">{% trans "Read" %} <b>({{read|length}})</b></a></li> <ul class="nav nav-pills">
<div class="text-right"> <li class="active"><a data-toggle="pill" href="#unread">{% trans "Unread" %}
<a href="{% url 'auth_mark_all_notifications_read' %}" class="btn btn-primary">{% trans "Mark All Read" %}</a> <b>({{ unread|length }})</b></a></li>
<a href="{% url 'auth_delete_all_read_notifications' %}" class="btn btn-danger">{% trans "Delete All Read" %}</a> <li><a data-toggle="pill" href="#read">{% trans "Read" %} <b>({{ read|length }})</b></a>
</li>
<div class="pull-right">
<a href="{% url 'auth_mark_all_notifications_read' %}"
class="btn btn-primary">{% trans "Mark All Read" %}</a>
<a href="{% url 'auth_delete_all_read_notifications' %}"
class="btn btn-danger">{% trans "Delete All Read" %}</a>
</div>
</ul>
</div> </div>
</ul> <div class="panel-body">
<div class="tab-content"> <div class="tab-content">
<div id="unread" class="tab-pane fade in active"> <div id="unread" class="tab-pane fade in active">
<div class="panel-body"> <div class="table-responsive">
<div class="table-responsive"> {% if unread %}
{% if unread %} <table class="table table-condensed table-hover table-striped">
<table class="table table-condensed table-hover table-striped"> <tr>
<tr> <th class="text-center">{% trans "Timestamp" %}</th>
<th class="text-center">{% trans "Timestamp" %}</th> <th class="text-center">{% trans "Title" %}</th>
<th class="text-center">{% trans "Title" %}</th> <th class="text-center">{% trans "Action" %}</th>
<th class="text-center">{% trans "Action" %}</th> </tr>
</tr> {% for notif in unread %}
{% for notif in unread %} <tr class="{{ notif.level }}">
<tr class="{{ notif.level }}"> <td class="text-center">{{ notif.timestamp }}</td>
<td class="text-center">{{ notif.timestamp }}</td> <td class="text-center">{{ notif.title }}</td>
<td class="text-center">{{ notif.title }}</td> <td class="text-center">
<td class="text-center"> <a href="{% url 'auth_notification_view' notif.id %}"
<a href="{% url 'auth_notification_view' notif.id %}" class="btn btn-success" title="View"> class="btn btn-success" title="View">
<span class="glyphicon glyphicon-eye-open"></span> <span class="glyphicon glyphicon-eye-open"></span>
</a> </a>
<a href="{% url 'auth_remove_notification' notif.id %}" class="btn btn-danger" title="Remove"> <a href="{% url 'auth_remove_notification' notif.id %}"
<span class="glyphicon glyphicon-remove"></span> class="btn btn-danger" title="Remove">
</a> <span class="glyphicon glyphicon-remove"></span>
</td> </a>
</tr> </td>
{% endfor %} </tr>
</table> {% endfor %}
{% else %} </table>
<div class="alert alert-warning text-center">{% trans "No unread notifications." %}</div> {% else %}
{% endif %} <div class="alert alert-warning text-center">{% trans "No unread notifications." %}</div>
</div> {% endif %}
</div> </div>
</div> </div>
<div id="read" class="tab-pane fade"> <div id="read" class="tab-pane fade">
<div class="panel-body"> <div class="panel-body">
<div class="table-responsive"> <div class="table-responsive">
{% if read %} {% if read %}
<table class="table table-condensed table-hover table-striped"> <table class="table table-condensed table-hover table-striped">
<tr> <tr>
<th class="text-center">{% trans "Timestamp" %}</th> <th class="text-center">{% trans "Timestamp" %}</th>
<th class="text-center">{% trans "Title" %}</th> <th class="text-center">{% trans "Title" %}</th>
<th class="text-center">{% trans "Action" %}</th> <th class="text-center">{% trans "Action" %}</th>
</tr> </tr>
{% for notif in read %} {% for notif in read %}
<tr class="{{ notif.level }}"> <tr class="{{ notif.level }}">
<td class="text-center">{{ notif.timestamp }}</td> <td class="text-center">{{ notif.timestamp }}</td>
<td class="text-center">{{ notif.title }}</td> <td class="text-center">{{ notif.title }}</td>
<td class="text-center"> <td class="text-center">
<a href="{% url 'auth_notification_view' notif.id %}" class="btn btn-success" title="View"> <a href="{% url 'auth_notification_view' notif.id %}"
<span class="glyphicon glyphicon-eye-open"></span> class="btn btn-success" title="View">
</a> <span class="glyphicon glyphicon-eye-open"></span>
<a href="{% url 'auth_remove_notification' notif.id %}" class="btn btn-danger" title="remove"> </a>
<span class="glyphicon glyphicon-remove"></span> <a href="{% url 'auth_remove_notification' notif.id %}"
</a> class="btn btn-danger" title="remove">
</td> <span class="glyphicon glyphicon-remove"></span>
</tr> </a>
{% endfor %} </td>
</table> </tr>
{% else %} {% endfor %}
<div class="alert alert-warning text-center">{% trans "No read notifications." %}</div> </table>
{% endif %} {% else %}
<div class="alert alert-warning text-center">{% trans "No read notifications." %}</div>
{% endif %}
</div>
</div>
</div> </div>
</div> </div>
</div> </div>