Browse Source

Fix some bugs

devel
bashmak 8 years ago
parent
commit
791b21ee51
  1. 3
      abonapp/locale/ru/LC_MESSAGES/django.po
  2. 8
      abonapp/models.py
  3. 7
      abonapp/templates/abonapp/log.html
  4. 2
      abonapp/views.py
  5. 32
      clientsideapp/locale/ru/LC_MESSAGES/django.po
  6. 10
      clientsideapp/templates/clientsideapp/debt_buy.html
  7. 5
      clientsideapp/templates/clientsideapp/modal_service_buy.html
  8. 12
      clientsideapp/views.py
  9. 3
      devapp/models.py
  10. 2
      devapp/templates/devapp/devices.html
  11. 42
      djing/auth_backends.py
  12. 5
      djing/settings.py
  13. 6
      msg_app/models.py
  14. 5
      taskapp/context_proc.py
  15. 2
      taskapp/handle.py
  16. 2
      taskapp/locale/ru/LC_MESSAGES/django.po

3
abonapp/locale/ru/LC_MESSAGES/django.po

@ -1138,3 +1138,6 @@ msgstr "Абоненты"
msgid "Successfully saved"
msgstr "Успешно сохранено"
msgid "This user can not buy admin services"
msgstr "Этот пользователь не может назначать административные услуги"

8
abonapp/models.py

@ -202,8 +202,11 @@ class Abon(BaseAccount):
amount = round(tariff.amount, 2)
if not author.is_staff and tariff.is_admin:
raise LogicError(_('User that is no staff can not buy admin services'))
if tariff.is_admin:
if author is not None and not author.is_staff:
raise LogicError(_('User that is no staff can not buy admin services'))
else:
raise LogicError(_('This user can not buy admin services'))
if self.current_tariff is not None:
if self.current_tariff.tariff == tariff:
@ -347,7 +350,6 @@ class AllTimePayLogManager(models.Manager):
r = cur.fetchone()
if r is None: break
summ, dat = r
print(summ, dat)
yield {'summ': summ, 'pay_date': datetime.strptime(dat, '%Y-%m-%d')}

7
abonapp/templates/abonapp/log.html

@ -39,7 +39,12 @@
</td>
<td>{{ l.comment }}</td>
<td>{{ l.date|date:"D d E Y H:i:s" }}</td>
<td><a href="{% url 'acc_app:other_profile' l.author.id %}">{{ l.author.username }}</a></td>
<td>
{% if l.author %}
<a href="{% url 'acc_app:other_profile' l.author.id %}">{{ l.author.username }}</a></td>
{% else %}
---
{% endif %}
</tr>
{% empty %}
<tr>

2
abonapp/views.py

@ -402,8 +402,8 @@ def unsubscribe_service(request, gid, uid, abon_tariff_id):
try:
abon = get_object_or_404(models.Abon, pk=uid)
abon_tariff = get_object_or_404(models.AbonTariff, pk=int(abon_tariff_id))
abon_tariff.delete()
abon.sync_with_nas(created=False)
abon_tariff.delete()
messages.success(request, _('User has been detached from service'))
except NasFailedResult as e:
messages.error(request, e)

32
clientsideapp/locale/ru/LC_MESSAGES/django.po

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-03-08 14:24+0300\n"
"POT-Creation-Date: 2018-03-18 00:15+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Dmitry Novikov nerosketch@gmail.com\n"
"Language: ru\n"
@ -32,31 +32,25 @@ msgid "Are you sure you want to spend a payment?"
msgstr "Вы уверены что хотите провести платёж?"
#: templates/clientsideapp/debt_buy.html:21
#, fuzzy, python-format
#| msgid ""
#| "From your account, they withdraw funds in <b>%(amount)s</b> rub. <br/>\n"
#| "As a result, you will remain on your account %(ballance_after)s rubles. "
#| "<br/>\n"
#| "The administrator can immediately see that you shut down the debt."
#, python-format
msgid ""
"From your account, they withdraw funds in <b>%(amount)s</b> rub.<br/>\n"
"As a result, you will remain on your account %(ballance_after)s rubles.<br/"
">\n"
"The administrator can immediately see that you shut down the debt."
"From your account, they withdraw funds in <b>%(amount)s</b> rub.<br/> As a "
"result, you will remain on your account %(ballance_after)s rubles.<br/> The "
"administrator can immediately see that you shut down the debt."
msgstr ""
"С вашего счёта снимутся средства в размере <b>%(amount)s</b> руб.<br/>\n"
"В результате у вас на счету останется %(ballance_after)s руб.<br/>\n"
"Администратор сразу сможет видеть что у вас закрыта задолженность."
"С вашего счёта снимутся средства в размере <b>%(amount)s</b> руб.<br/>В "
"результате у вас на счету останется %(ballance_after)s руб.<br/"
">Администратор сразу сможет видеть что у вас закрыта задолженность."
#: templates/clientsideapp/debt_buy.html:24
#: templates/clientsideapp/debt_buy.html:26
msgid "Description of payment"
msgstr "Описание платежа"
#: templates/clientsideapp/debt_buy.html:32
#: templates/clientsideapp/debt_buy.html:34
msgid "Confirm"
msgstr "Подтвердить"
#: templates/clientsideapp/debt_buy.html:35
#: templates/clientsideapp/debt_buy.html:37
msgid "Cancel"
msgstr "Отменить"
@ -107,7 +101,7 @@ msgstr "У вас нет проведённых платежей"
#: templates/clientsideapp/services.html:25
msgid "currency"
msgstr ""
msgstr "руб."
#: views.py:51
#, python-format
@ -127,7 +121,7 @@ msgstr "Вы не уверены что хотите оплатить долг?"
msgid "Your account have not enough money"
msgstr "Недостаточно средств на счету"
#: views.py:90
#: views.py:89
#, python-format
msgid "%(username)s paid the debt %(amount).2f"
msgstr "%(username)s заплатил долг в размере %(amount).2f"

10
clientsideapp/templates/clientsideapp/debt_buy.html

@ -18,9 +18,11 @@
{% trans 'Are you sure you want to spend a payment?' %}
</label>
</div>
<p>{% blocktrans %}From your account, they withdraw funds in <b>{{ amount }}</b> rub.<br/>
As a result, you will remain on your account {{ ballance_after }} rubles.<br/>
The administrator can immediately see that you shut down the debt.{% endblocktrans %}</p>
<p>{% blocktrans trimmed %}
From your account, they withdraw funds in <b>{{ amount }}</b> rub.<br/>
As a result, you will remain on your account {{ ballance_after }} rubles.<br/>
The administrator can immediately see that you shut down the debt.
{% endblocktrans %}</p>
<h4>{% trans 'Description of payment' %}</h4>
<div class="alert alert-info">
@ -38,4 +40,4 @@ The administrator can immediately see that you shut down the debt.{% endblocktra
</form>
</div>
</div>
{% endblock %}
{% endblock %}

5
clientsideapp/templates/clientsideapp/modal_service_buy.html

@ -12,9 +12,10 @@
<p>{{ service.descr }}</p>
<!--<p>{% blocktrans with speedIn=service.speedIn speedOut=service.speedOut amount=service.amount %}Inbound speed: {{ speedIn }} MBit/s<br>
<!--<p>{# {% blocktrans trimmed with speedIn=service.speedIn speedOut=service.speedOut amount=service.amount %}
Inbound speed: {{ speedIn }} MBit/s<br>
Outgoing speed: {{ speedOut }} MBit/s<br>
Cost: {{ amount }} rubles.{% endblocktrans %}</p>-->
Cost: {{ amount }} rubles.{% endblocktrans %} #}</p>-->
<p>Стоимость {{ service.amount }} руб.</p>
</div>
<div class="modal-footer">

12
clientsideapp/views.py

@ -28,7 +28,7 @@ def pays(request):
@login_required
def services(request):
try:
abon = Abon.objects.get(pk=request.user.pk)
abon = request.user
all_tarifs = Tariff.objects.get_tariffs_by_group(abon.group.pk)
current_service = abon.active_tariff()
except Abon.DoesNotExist:
@ -43,14 +43,14 @@ def services(request):
@login_required
@transaction.atomic
def buy_service(request, srv_id):
abon = get_object_or_404(Abon, pk=request.user.pk)
abon = request.user
service = get_object_or_404(Tariff, pk=srv_id)
try:
current_service = abon.active_tariff()
if request.method == 'POST':
abon.pick_tariff(service, request.user, _("Buy the service via user side, service '%s'")
abon.pick_tariff(service, None, _("Buy the service via user side, service '%s'")
% service)
abon.abon.sync_with_nas(created=False)
abon.sync_with_nas(created=False)
messages.success(request, _("The service '%s' wan successfully activated") % service.title)
else:
return render_to_text('clientsideapp/modal_service_buy.html', {
@ -76,7 +76,7 @@ def debts_list(request):
@transaction.atomic
def debt_buy(request, d_id):
debt = get_object_or_404(InvoiceForPayment, id=d_id)
abon = get_object_or_404(Abon, id=request.user.id)
abon = request.user
if request.method == 'POST':
try:
sure = request.POST.get('sure')
@ -86,7 +86,7 @@ def debt_buy(request, d_id):
raise LogicError(_('Your account have not enough money'))
amount = -debt.amount
abon.add_ballance(request.user, amount, comment=gettext('%(username)s paid the debt %(amount).2f') % {
abon.add_ballance(None, amount, comment=gettext('%(username)s paid the debt %(amount).2f') % {
'username': abon.get_full_name(),
'amount': amount
})

3
devapp/models.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import requests
from django.db import models
from django.db import models, ProgrammingError
from djing.fields import MACAddressField
from .base_intr import DevBase
from mydefs import MyGenericIPAddressField, MyChoicesAdapter, ip2int
@ -107,6 +107,7 @@ class Device(models.Model):
def update_dhcp(self):
if self.devtype not in ('On','Dl'):
return
raise ProgrammingError('переделать это безобразие')
# FIXME: переделать это безобразие
grp = self.user_group.id
code = ''

2
devapp/templates/devapp/devices.html

@ -41,7 +41,7 @@
</thead>
<tbody>
{% with can_del_dev=perms.devapp.delete_device can_ch_dev=perms.devapp.change_device grpid=dev.group.pk %}
{% with can_del_dev=perms.devapp.delete_device can_ch_dev=perms.devapp.change_device grpid=group.id %}
{% for dev in devices %}
<tr>

42
djing/auth_backends.py

@ -0,0 +1,42 @@
from django.contrib.auth.backends import ModelBackend
from accounts_app.models import BaseAccount, UserProfile
from abonapp.models import Abon
class CustomAuthBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
if username is None:
username = kwargs.get(BaseAccount.USERNAME_FIELD)
print('username', username)
try:
user = BaseAccount._default_manager.get_by_natural_key(username)
print('user', user)
if user.check_password(password):
if user.is_admin:
print('is adm')
auser = UserProfile.objects.get_by_natural_key(username)
else:
print('no adm')
auser = Abon.objects.get_by_natural_key(username)
if self.user_can_authenticate(auser):
print('can auth')
return auser
print('no can auth')
else:
print('wrong password')
except BaseAccount.DoesNotExist:
print('does not exist')
# Run the default password hasher once to reduce the timing
# difference between an existing and a non-existing user (#20760).
BaseAccount().set_password(password)
def get_user(self, user_id):
try:
user = BaseAccount._default_manager.get(pk=user_id)
if user.is_admin:
user = UserProfile._default_manager.get(pk=user_id)
else:
user = Abon._default_manager.get(pk=user_id)
except BaseAccount.DoesNotExist:
return None
return user if self.user_can_authenticate(user) else None

5
djing/settings.py

@ -19,13 +19,14 @@ from django.urls import reverse_lazy
SECRET_KEY = local_settings.SECRET_KEY
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = local_settings.DEBUG or False
DEBUG = local_settings.DEBUG
ALLOWED_HOSTS = local_settings.ALLOWED_HOSTS
# required for django-guardian
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # default
'djing.auth_backends.CustomAuthBackend',
#'django.contrib.auth.backends.ModelBackend', # default
'guardian.backends.ObjectPermissionBackend'
)

6
msg_app/models.py

@ -124,8 +124,10 @@ class ConversationManager(models.Manager):
return conversation
def get_new_messages_count(self, account):
ms_count = MessageStatus.objects.filter(user=account, state='new').count()
return ms_count
if isinstance(account, UserProfile):
return MessageStatus.objects.filter(user=account, state='new').count()
else:
return 0
def fetch(self, account):
conversations = self.filter(models.Q(author=account) | models.Q(participants__in=[account])).annotate(

5
taskapp/context_proc.py

@ -1,12 +1,13 @@
from django.contrib.auth.models import AnonymousUser
from taskapp.models import Task
from accounts_app.models import UserProfile
def get_active_tasks_count(request):
tasks_count = 0
if not isinstance(request.user, AnonymousUser):
tasks_count = Task.objects.filter(recipients=request.user, state='S').count()
if isinstance(request.user, UserProfile):
tasks_count = Task.objects.filter(recipients__in=[request.user], state='S').count()
return {
'tasks_count': tasks_count
}

2
taskapp/handle.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from chatbot.telebot import send_notify
from chatbot.models import ChatException
from mydefs import MultipleException

2
taskapp/locale/ru/LC_MESSAGES/django.po

@ -34,7 +34,7 @@ msgstr "с. %s\n"
msgid ""
"address %(street)s %(house)s.\n"
"telephone %(telephone)s\n"
msgstr "по адресу %s %s тел. %s.\n"
msgstr "по адресу %(street)s %(house)s тел. %(telephone)s.\n"
#: handle.py:31 models.py:25
msgid "not chosen"

Loading…
Cancel
Save