Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better code style + make Bazaar Exchange disappear #857

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions wouso/core/scoring/sm.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,13 @@ def update_points(player, game):
if level == player.level_no:
return

arguments = dict(level=level)
if level < player.level_no:
action_msg = 'level-downgrade'
signal_msg = ugettext_noop("downgraded to level {level}")
signals.addActivity.send(sender=None, user_from=player,
user_to=player, message=signal_msg,
arguments=dict(level=level),
game=game, action=action_msg)
else:
this_game = game
else:
action_msg = 'level-upgrade'
arguments = dict(level=level)
# Check if the user has previously reached this level
if level > player.max_level:
# Update the maximum reached level
Expand All @@ -168,17 +165,19 @@ def update_points(player, game):
else:
# The user should not receive additional gold
signal_msg = ugettext_noop("upgraded back to level {level}")
this_game = None

signals.addActivity.send(sender=None, user_from=player,
user_to=player, message=signal_msg,
arguments=dict(level=level),
game=game, action=action_msg)

signals.addActivity.send(sender=None, user_from=player,
user_to=player, message=signal_msg,
arguments=arguments, game=None,
action=action_msg)
player.level_no = level
player.save()


def score_simple(player, coin, amount, game=None, formula=None,
external_id=None, percents=100):
external_id=None, percents=100 ):
""" Give amount of coin to the player.
"""
if not isinstance(game, Game) and game is not None:
Expand Down Expand Up @@ -252,8 +251,7 @@ def sync_user(player):
""" Synchronise user points with database
"""
coin = Coin.get('points')
result = History.objects.filter(user=player.user,coin=coin).aggregate(total=models.Sum('amount'))
points = result['total'] if result['total'] is not None else 0
points = real_points(player)
if player.points != points and not player.magic.has_modifier('top-disguise'):
logging.debug('%s had %d instead of %d points' % (player, player.points, points))
player.points = points
Expand Down
5 changes: 2 additions & 3 deletions wouso/interface/apps/magic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def get_context_data(self, **kwargs):

# Disable exchange for real
exchange_disabled = BoolSetting.get('disable-Bazaar-Exchange').get_value()

try:
rate = scoring.calculate('gold-points-rate', gold=1)['points']
rate2 = round(1/scoring.calculate('points-gold-rate', points=1)['gold'])
Expand Down Expand Up @@ -65,9 +66,7 @@ def bazaar_exchange(request):

player = request.user.get_profile()
message, error = '', ''
if BoolSetting.get('disable-Bazaar-Exchange').get_value():
error = _("Exchange is disabled")
elif request.method == 'POST':
if request.method == 'POST':
try:
points = float(request.POST.get('points', 0))
gold = round(float(request.POST.get('gold', 0)))
Expand Down
9 changes: 0 additions & 9 deletions wouso/interface/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ def test_online_player(self):

self.assertTrue(player.user.username in str(last10_div))

def test_online_player(self):
player = self._get_player()
self.client.login(username=player.user.username, password='test')
response = self.client.get('/hub/')
soup = BeautifulSoup(response.content, "html.parser")
last10_div = soup.find_all(class_="widget")[0]

self.assertTrue(player.user.username in str(last10_div))

def test_profile_page(self):
admin = self._get_superuser()
self._client_superuser()
Expand Down
155 changes: 0 additions & 155 deletions wouso/resources/templates/magic/bazaar.html
Original file line number Diff line number Diff line change
@@ -1,155 +0,0 @@
{% extends 'interface/section_base.html' %}
{% load i18n %}
{% load artifacts %}
{% load user %}

{% block title %}{% trans 'Magic' %}{% endblock %}
{% block sectiontitle %}{% trans 'Magic' %}{% endblock %}

{% block scripts %}
<script type="text/javascript" src="{{ basepath }}/static/js/tabs.js"></script>
<link rel="stylesheet" type="text/css" href="{{ basepath }}/static/css/tabs.css" />
{% endblock %}

{% block sectioncontent %}

<ul class="tabs">
<li><a href="#spells" id="spells-click" class="no-redir">{% trans 'Bazaar' %}</a></li>
{% if not exchange_disabled %}
<li><a href="#exchange" id="exchange-click" class="no-redir">{% trans 'Exchange' %}</a></li>
{% endif %}
<li><a href="#summary" id="summary-click" class="no-redir">{% trans 'Summary' %}{% if unseen_count > 0 %}<sup class="unread-count">{{ unseen_count }}</sup>{% endif %}</a></li>
<li><a href="#activity" id="activity-click" class="no-redir">{% trans 'Activity' %}</a></li>
</ul>

<div class="tab_container">
<div id="spells" class="tab_content">
<br/>
<table>
{% for s in spells %}
{% if s.available %}
<div style="clear:both">
<tr>
<td width="100%">
<h3>{% artifact s %}{{ s.title }}</h3>
<p>{{ s.description }}</p>
</div>
</td>
<td nowrap="nowrap">
{% if s.due_days == 1 %}
{% trans '1 day' %}
{% else %}
{% if s.due_days > 1 %}
{{ s.due_days }} {% trans 'days' %}
{% endif %}
{% endif %}
</td>
<td align="right" >
{% coin_amount s.price 'gold' %}
</td>
<td>
{% if user.get_profile.level_no >= s.level_required %}
<a href="{% url bazaar_buy s.id %}" class="button">{% trans 'Buy' %}</a>
{% else %}
<span class="button">{% blocktrans with s.level_required as level %}Level {{level}} required{% endblocktrans %}</span>
{% endif %}
</td>
<td>
{% spell_stock player s %}
</td>
</tr>
</div>
{% endif %}
{% empty %}
{% trans 'Nothing' %}.
{% endfor %}
</table>
</div>

{% if not exchange_disabled %}
<div id="exchange" class="tab_content">
<br/>
<span class="points">{{ rate_text }}</span>
<p>{% trans 'Exchange points for gold or gold for points' %}</p>
<form method="post" action="{% url bazaar_exchange %}">
{% trans 'Points' %}: <input type="text" size="3" name="points" value="{{ rate }}" class="big" />
<div class="actions">
<button type="submit">{% trans 'Exchange' %}</button>
</div>
{% csrf_token %}
</form>

<form method="post" style="clear:both" action="{% url bazaar_exchange %}">
{% trans 'Gold' %}: <input type="text" size="3" name="gold" value="1" class="big" />
<div class="actions">
<button type="submit">{% trans 'Exchange' %}</button>
</div>
{% csrf_token %}
</form>
</div>
{% endif %}

<div id="activity" class="tab_content">
<br/>
<div id="wall">
{% include 'activity/stream.html' %}
{% include 'activity/stream_pagination.html' %}
</div>
</div>

<div id="summary" class="tab_content">
<br/>
<h3>{% trans 'Available' %}</h3>
{% if theowner.magic.spell_amounts.all %}
<table>
<tr><th>{% trans 'Spell' %}</th>
<th>{% trans 'Amount' %}</th>
</tr>
{% for s in theowner.magic.spell_amounts.all %}
<tr><td>{% artifact s.spell %} {{ s.spell.title }}</td>
<td align="right">{% spell_stock theowner s.spell %}</td>
</tr>
{% endfor %}
</table>
{% else %}
{% trans 'None.' %}
{% endif %}

{% if theowner.magic.spells.all %}
<h3>{% trans 'Active on me' %}</h3>
<table>
<tr><th>{% trans 'Spell' %}</th>
<th>{% trans 'Source' %}</th>
<th>{% trans 'Until' %}</th>
</tr>
{% for s in theowner.magic.spells.all %}
<tr>
<td>{% artifact s.spell %} {{ s.spell.title }}</td>
<td>{% player_simple s.source %}</td>
<td>{{ s.due }}</td>
</tr>
{% endfor %}
</table>
{% endif %}

{% if theowner.magic.spells_cast.all %}
<h3>{% trans 'Cast by me' %}</h3>
<table>
<tr><th>{% trans 'Spell' %}</th>
<th>{% trans 'Target' %}</th>
<th>{% trans 'Until' %}</th>
</tr>
{% for s in theowner.magic.spells_cast.all %}
<tr>
<td>{% artifact s.spell %} {{ s.spell.title }}</td>
<td>{% player_simple s.player %}</td>
<td>{{ s.due }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
</div>
{% endblock %}