Merge branch 'setup' of https://bitbucket.org/PekopT/archilance into setup
commit
ddc57455b4
60 changed files with 1881 additions and 1224 deletions
@ -0,0 +1,9 @@ |
||||
bind = '127.0.0.1:8046' |
||||
workers = 3 |
||||
user = "www-data" |
||||
reload = True |
||||
|
||||
try: |
||||
from local_gunicorn import * |
||||
except ImportError: |
||||
pass |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@ |
||||
# -*- coding: utf-8 -*- |
||||
# Generated by Django 1.9.7 on 2016-08-08 12:57 |
||||
from __future__ import unicode_literals |
||||
|
||||
import datetime |
||||
from django.db import migrations, models |
||||
from django.utils.timezone import utc |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('common', '0003_auto_20160729_1747'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='settings', |
||||
name='recalculation_rating_time', |
||||
field=models.TimeField(default=datetime.datetime(2016, 8, 8, 12, 57, 41, 160156, tzinfo=utc)), |
||||
preserve_default=False, |
||||
), |
||||
migrations.AddField( |
||||
model_name='settings', |
||||
name='recalculation_spec_time', |
||||
field=models.TimeField(default=datetime.datetime(2016, 8, 8, 12, 57, 52, 905906, tzinfo=utc)), |
||||
preserve_default=False, |
||||
), |
||||
] |
||||
@ -0,0 +1,20 @@ |
||||
# -*- coding: utf-8 -*- |
||||
# Generated by Django 1.9.7 on 2016-08-09 16:56 |
||||
from __future__ import unicode_literals |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('common', '0004_auto_20160808_1557'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='settings', |
||||
name='accountant_send_email', |
||||
field=models.EmailField(default='muhtarzubanchi05@gmail.com', max_length=100), |
||||
), |
||||
] |
||||
@ -1,25 +0,0 @@ |
||||
<ul class="rettList"> |
||||
<li><a href="javascript:void(0)">Рейтинг: <span> {{ ratings }}</span></a></li> |
||||
<li><a href="javascript:void(0)">Безопасные сделки: <span> 0</span></a></li> |
||||
<li> |
||||
<a href="javascript:void(0)"> |
||||
Отзывы: |
||||
<span> + 0</span> |
||||
<small> 0</small> |
||||
<mark> - 0</mark> |
||||
</a> |
||||
</li> |
||||
</ul> |
||||
|
||||
{#<ul class="rettList restList2">#} |
||||
{# <li>Рейтинг: <span> 1245</span></li>#} |
||||
{# <li>Безопасные сделки: <span> 5</span></li>#} |
||||
{# <li>#} |
||||
{# <a href="javascript:void(0)">Отзывы:#} |
||||
{# <span> + 385</span>#} |
||||
{# <small> 0</small>#} |
||||
{# <mark> - 0</mark>#} |
||||
{# </a>#} |
||||
{# </li>#} |
||||
{# </ul>#} |
||||
|
||||
@ -1,10 +0,0 @@ |
||||
from django import template |
||||
|
||||
register = template.Library() |
||||
|
||||
@register.inclusion_tag("templatetags/ratings_widget.html", takes_context=True) |
||||
def ratings_widget(context, user_id, class_name=None): |
||||
ratings = user_id |
||||
return { |
||||
'ratings': ratings, |
||||
} |
||||
@ -0,0 +1 @@ |
||||
default_app_config = 'ratings.apps.RatingsConfig' |
||||
@ -0,0 +1,23 @@ |
||||
from django.core.management import BaseCommand |
||||
from django.db.models import Sum |
||||
from specializations.models import Specialization |
||||
from ratings.models import HistoryRating |
||||
from users.models import User,Team |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
|
||||
def handle(self, *args, **options): |
||||
users = User.objects.filter(is_superuser=False) |
||||
for user in users: |
||||
current_rating_info = HistoryRating.objects.filter(user_id=user.pk).aggregate(Sum('rating')) |
||||
current_rating = current_rating_info['rating__sum'] or 0 |
||||
user.rating = current_rating |
||||
user.save() |
||||
|
||||
teams = Team.objects.all() |
||||
for team in teams: |
||||
current_rating_info = HistoryRating.objects.filter(team_id=team.pk).aggregate(Sum('rating')) |
||||
current_rating = current_rating_info['rating__sum'] or 0 |
||||
team.rating = current_rating |
||||
team.save() |
||||
@ -0,0 +1,43 @@ |
||||
from django.core.management import BaseCommand |
||||
from specializations.models import Specialization |
||||
from ratings.models import SpecializationRating |
||||
from users.models import User, Team |
||||
|
||||
|
||||
class Command(BaseCommand): |
||||
|
||||
def handle(self, *args, **options): |
||||
users = User.objects.values('pk', 'rating').filter(is_superuser=False).order_by('-rating') |
||||
teams = Team.objects.values('pk', 'rating').order_by('-rating') |
||||
result_list = [] |
||||
|
||||
for user in users: |
||||
result_list.append([user['rating'], 'user', user['pk']]) |
||||
|
||||
for team in teams: |
||||
result_list.append([team['rating'], 'team', team['pk'] ]) |
||||
|
||||
result_list = list(reversed(sorted(result_list))) |
||||
SpecializationRating.objects.all().delete() |
||||
specializations = Specialization.objects.all() |
||||
for spec in specializations: |
||||
i = 0 |
||||
for res in result_list: |
||||
if 'user' in res[1]: |
||||
user = User.objects.get(pk=res[2]) |
||||
team = None |
||||
specializations_current = user.contractor_specializations.all() |
||||
else: |
||||
team = Team.objects.get(pk=res[2]) |
||||
user = None |
||||
specializations_current = team.specializations.all() |
||||
|
||||
if spec in specializations_current: |
||||
i += 1 |
||||
spec_rating = SpecializationRating() |
||||
spec_rating.position = i |
||||
spec_rating.user = user |
||||
spec_rating.team = team |
||||
spec_rating.specialization = spec |
||||
spec_rating.save() |
||||
print('The end') |
||||
@ -0,0 +1,12 @@ |
||||
<ul class="rettList {{ class_name }}"> |
||||
<li><a href="javascript:void(0)">Рейтинг: <span> {{ ratings }}</span></a></li> |
||||
<li><a href="javascript:void(0)">Безопасные сделки: <span> 0</span></a></li> |
||||
<li> |
||||
<a href="javascript:void(0)"> |
||||
Отзывы: |
||||
<span> + 0</span> |
||||
<small> 0</small> |
||||
<mark> - 0</mark> |
||||
</a> |
||||
</li> |
||||
</ul> |
||||
@ -0,0 +1,9 @@ |
||||
<div class="dashedCol4"> |
||||
<p class="specUser">Специализации:</p> |
||||
{% for spec in specializations %} |
||||
<div class="insetSpec"> |
||||
<span>{{ spec.specialization.name }}</span> |
||||
<span>{{ spec.position }}-й</span> |
||||
</div> |
||||
{% endfor %} |
||||
</div> |
||||
@ -0,0 +1,41 @@ |
||||
from django import template |
||||
|
||||
from archilance import util |
||||
from users.models import User, Team |
||||
from ratings.models import SpecializationRating |
||||
|
||||
register = template.Library() |
||||
|
||||
@register.inclusion_tag('templatetags/specializations_widget.html', takes_context=True) |
||||
def specialization_widget(context, user_id): |
||||
user_id = int(user_id) |
||||
specializations = SpecializationRating.objects.select_related('specialization').filter(user_id=user_id) |
||||
return { |
||||
'specializations': specializations, |
||||
'user_id': user_id, |
||||
} |
||||
|
||||
@register.inclusion_tag('templatetags/specializations_widget.html', takes_context=True) |
||||
def specialization_team_widget(context, team_id): |
||||
team_id = int(team_id) |
||||
specializations = SpecializationRating.objects.select_related('specialization').filter(team_id=team_id) |
||||
return { |
||||
'specializations': specializations, |
||||
} |
||||
|
||||
|
||||
|
||||
@register.inclusion_tag("templatetags/ratings_widget.html", takes_context=True) |
||||
def ratings_widget(context, user_id, class_name=None): |
||||
ratings = User.objects.get(pk=user_id).rating |
||||
return { |
||||
'ratings': ratings, |
||||
'class_name': class_name |
||||
} |
||||
|
||||
@register.inclusion_tag("templatetags/ratings_widget.html", takes_context=True) |
||||
def ratings_team_widget(context, team_id): |
||||
ratings = Team.objects.get(pk=team_id).rating |
||||
return { |
||||
'ratings': ratings, |
||||
} |
||||
@ -1,21 +0,0 @@ |
||||
<div class="dashedCol4"> |
||||
<p class="specUser">Специализации:</p> |
||||
{% for spec in specializations %} |
||||
<div class="insetSpec"> |
||||
<span>{{ spec }}</span> |
||||
<span>2-й</span> |
||||
</div> |
||||
{% endfor %} |
||||
</div> |
||||
{# <div class="dashedCol4 dashedCol44 dashedColColor">#} |
||||
{# <p class="specUser">#} |
||||
{# Специализации:#} |
||||
{# </p>#} |
||||
{# <div class="insetSpec">#} |
||||
{# <span>Интерьеры</span>#} |
||||
{# </div>#} |
||||
{# #} |
||||
{# <div class="insetSpec">#} |
||||
{# <span>Визуализация/3D</span>#} |
||||
{# </div>#} |
||||
{# </div>#} |
||||
@ -1,20 +0,0 @@ |
||||
from django import template |
||||
|
||||
from archilance import util |
||||
from users.models import User |
||||
|
||||
|
||||
register = template.Library() |
||||
|
||||
@register.inclusion_tag('templatetags/specializations_widget.html', takes_context=True) |
||||
def specialization_widget(context, user_id): |
||||
user_id = int(user_id) |
||||
user = util.get_or_none(User, pk=user_id) |
||||
if user: |
||||
specializations = user.contractor_specializations.all() |
||||
else: |
||||
specializations = None |
||||
return { |
||||
'specializations': specializations, |
||||
'user_id': user_id, |
||||
} |
||||
@ -1,24 +1,32 @@ |
||||
{% extends 'partials/base.html' %} |
||||
|
||||
{% block content %} |
||||
<div class="col-lg-12"> |
||||
<p class="titleScore">Вход на сайт</p> |
||||
</div> |
||||
<div class="form-regestration"> |
||||
{{ form.errors }} |
||||
<form method="post">{% csrf_token %} |
||||
<div class="col-lg-12 select-reg"> |
||||
<input type="text" name="{{ form.username.name }}" class="box-sizing email-reg" placeholder="Электронная почта"> |
||||
</div> |
||||
<div class="col-lg-12 select-reg"> |
||||
<input type="password" name="{{ form.password.name }}" class="box-sizing pass-reg" placeholder="Пароль"> |
||||
</div> |
||||
<div class="col-lg-12 select-reg"> |
||||
<button class="reg-sub">Вход</button> |
||||
</div> |
||||
{% include 'partials/header.html' %} |
||||
<div class="container mainScore"> |
||||
<div class="row"> |
||||
<div class="col-lg-12"> |
||||
<p class="titleScore">Вход на сайт</p> |
||||
</div> |
||||
<div class="form-regestration"> |
||||
{{ form.errors }} |
||||
<form method="post">{% csrf_token %} |
||||
<div class="col-lg-12 select-reg"> |
||||
<input type="text" name="{{ form.username.name }}" class="box-sizing email-reg" |
||||
placeholder="Электронная почта"> |
||||
</div> |
||||
<div class="col-lg-12 select-reg"> |
||||
<input type="password" name="{{ form.password.name }}" class="box-sizing pass-reg" placeholder="Пароль"> |
||||
</div> |
||||
<div class="col-lg-12 select-reg"> |
||||
<button class="reg-sub">Вход</button> |
||||
</div> |
||||
|
||||
</form> |
||||
</form> |
||||
|
||||
</div> |
||||
{% include 'partials/footer.html' %} |
||||
</div> |
||||
</div> |
||||
|
||||
</div> |
||||
{% endblock %} |
||||
a |
||||
|
||||
|
||||
@ -0,0 +1,25 @@ |
||||
# -*- coding: utf-8 -*- |
||||
# Generated by Django 1.9.7 on 2016-08-08 12:57 |
||||
from __future__ import unicode_literals |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('users', '0006_auto_20160805_1442'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.RenameField( |
||||
model_name='user', |
||||
old_name='contractor_rating', |
||||
new_name='rating', |
||||
), |
||||
migrations.AddField( |
||||
model_name='team', |
||||
name='rating', |
||||
field=models.FloatField(default=0.0), |
||||
), |
||||
] |
||||
@ -1,5 +1,15 @@ |
||||
from django.contrib import admin |
||||
|
||||
from .models import InvoiceHistory |
||||
from .models import InvoiceHistory, WithDraw |
||||
|
||||
admin.site.register(InvoiceHistory) |
||||
|
||||
class InvoiceHistoryAdmin(admin.ModelAdmin): |
||||
list_display = ('comment', 'sum', 'user','balance',) |
||||
|
||||
|
||||
class WithDrawAdmin(admin.ModelAdmin): |
||||
list_display = ('sum','created','user',) |
||||
|
||||
|
||||
admin.site.register(InvoiceHistory, InvoiceHistoryAdmin) |
||||
admin.site.register(WithDraw, WithDrawAdmin) |
||||
|
||||
@ -0,0 +1,13 @@ |
||||
from django import forms |
||||
from .models import WithDraw |
||||
|
||||
|
||||
class WithDrawForm(forms.ModelForm): |
||||
|
||||
class Meta: |
||||
model = WithDraw |
||||
fields = ( |
||||
'sum', |
||||
'yandex_card', |
||||
'user', |
||||
) |
||||
@ -0,0 +1,20 @@ |
||||
# -*- coding: utf-8 -*- |
||||
# Generated by Django 1.9.7 on 2016-08-09 09:22 |
||||
from __future__ import unicode_literals |
||||
|
||||
from django.db import migrations, models |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
('wallets', '0003_auto_20160729_1209'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.AddField( |
||||
model_name='invoicehistory', |
||||
name='balance', |
||||
field=models.DecimalField(decimal_places=0, default=0, max_digits=10), |
||||
), |
||||
] |
||||
@ -0,0 +1,43 @@ |
||||
# -*- coding: utf-8 -*- |
||||
# Generated by Django 1.9.7 on 2016-08-09 14:27 |
||||
from __future__ import unicode_literals |
||||
|
||||
from django.conf import settings |
||||
from django.db import migrations, models |
||||
import django.db.models.deletion |
||||
import django.utils.timezone |
||||
|
||||
|
||||
class Migration(migrations.Migration): |
||||
|
||||
dependencies = [ |
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), |
||||
('wallets', '0004_invoicehistory_balance'), |
||||
] |
||||
|
||||
operations = [ |
||||
migrations.CreateModel( |
||||
name='WithDraw', |
||||
fields=[ |
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
||||
('sum', models.DecimalField(decimal_places=0, max_digits=10)), |
||||
('created', models.DateTimeField(default=django.utils.timezone.now)), |
||||
('yandex_card', models.CharField(max_length=30)), |
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='with_draw', to=settings.AUTH_USER_MODEL)), |
||||
], |
||||
options={ |
||||
'verbose_name_plural': 'Заявки на вывод средств', |
||||
'ordering': ('-created',), |
||||
'verbose_name': 'Заявка на вывод средств', |
||||
}, |
||||
), |
||||
migrations.AlterModelOptions( |
||||
name='invoicehistory', |
||||
options={'ordering': ('-created',), 'verbose_name': 'Счет(История)', 'verbose_name_plural': 'Счет(История)'}, |
||||
), |
||||
migrations.AlterField( |
||||
model_name='invoicehistory', |
||||
name='type', |
||||
field=models.CharField(blank=True, max_length=20, null=True), |
||||
), |
||||
] |
||||
@ -0,0 +1,20 @@ |
||||
from django.db.models.signals import post_save |
||||
from django.dispatch import receiver |
||||
from django.core.mail import send_mail, EmailMultiAlternatives |
||||
from django.template.loader import get_template, render_to_string |
||||
|
||||
from .models import WithDraw |
||||
|
||||
|
||||
@receiver(post_save, sender=WithDraw) |
||||
def send_for_accountant(sender, instance, created, **kwargs): |
||||
|
||||
if created: |
||||
ctx_dict = { |
||||
'username': instance.user.username, |
||||
} |
||||
subject, from_email, to = 'Заявка на распечатку', 'mukhtar@mukhtar', 'muhtarzubanchi05@gmail.com' |
||||
text_content = render_to_string('send_for_accountant.txt', ctx_dict) |
||||
html_content = get_template('send_for_accountant.html').render(ctx_dict) |
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) |
||||
msg.send() |
||||
@ -0,0 +1,126 @@ |
||||
{% extends 'partials/base.html' %} |
||||
|
||||
{% load staticfiles %} |
||||
{% load thumbnail %} |
||||
{% block content %} |
||||
|
||||
|
||||
{% include 'partials/header.html' %} |
||||
<div class="container mainScore"> |
||||
<div class="row"> |
||||
<div class="col-lg-12"> |
||||
<p class="titleScore">Ваш счет</p> |
||||
</div> |
||||
<div class="col-lg-12"> |
||||
<div class="scoreButtons disTab"> |
||||
<div class="triangle1"></div> |
||||
<p>{{ user_score_balance }} <i class="fa fa-rub"></i></p> |
||||
|
||||
{% if user_score.is_customer %} |
||||
<div class="col-lg-6"> |
||||
<a href="javascript:void(0)" class="linkS linkS1">пополнить</a> |
||||
</div> |
||||
{% endif %} |
||||
|
||||
<div class="col-lg-6"> |
||||
<a href="javascript:void(0)" data-toggle="modal" data-target="#withdraw-money" |
||||
class="linkS linkS2">вывести средства</a> |
||||
</div> |
||||
|
||||
<div id="withdraw-money" class="modal fade" role="dialog"> |
||||
<div class="modal-dialog" role="document" style="width:900px;"> |
||||
<div class="modal-content"> |
||||
|
||||
<div class="modal-header"> |
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× |
||||
</button> |
||||
<h4 class="modal-title">Вывод денег</h4> |
||||
</div> |
||||
<form id="withdraw-form" action="{% url 'wallets:withdraw-create' %}" method="POST">{% csrf_token %} |
||||
<div class="modal-body"> |
||||
<div style="height: 150px;"> |
||||
<div class="textAreaBlock2 text-nn box-sizing disTab"> |
||||
<p>Кол-во денег</p> |
||||
<input type="text" name="{{ form.sum.html_name }}"> |
||||
</div> |
||||
|
||||
<div class="textAreaBlock2 text-nn box-sizing disTab"> |
||||
<p>Номер Яндекс кошелька</p> |
||||
<input type="text" name="{{ form.yandex_card.html_name }}"> |
||||
<input type="hidden" name="{{ form.user.html_name }}" value="{{ user_score.pk }}"> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="modal-footer"> |
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button> |
||||
<button type="submit" class="btn btn-primary">Вывести</button> |
||||
</div> |
||||
</form> |
||||
|
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
|
||||
<table> |
||||
<tr> |
||||
<th>Дата</th> |
||||
<th>Описание</th> |
||||
<th>Поступление/Списание</th> |
||||
<th>Баланс</th> |
||||
</tr> |
||||
{% for history in user_score.invoice_history.all %} |
||||
<tr> |
||||
<td>{{ history.created }}</td> |
||||
<td> |
||||
{{ history.comment }} |
||||
</td> |
||||
<td> |
||||
{{ history.sum }} |
||||
<i class="fa fa-rub"></i> |
||||
</td> |
||||
<td> |
||||
{{ history.balance }} |
||||
<i class="fa fa-rub"></i> |
||||
</td> |
||||
</tr> |
||||
{% endfor %} |
||||
</table> |
||||
</div> |
||||
</div> |
||||
{% include 'partials/footer.html' %} |
||||
</div> |
||||
</div> |
||||
{% endblock %} |
||||
|
||||
{% block js_block %} |
||||
<script type="text/javascript"> |
||||
|
||||
$(function () { |
||||
$('#withdraw-form').on('submit', function (e) { |
||||
e.preventDefault(); |
||||
var dataSerializer = $(this).serialize() |
||||
$.ajax({ |
||||
url: '/wallets/withdraw/create/', |
||||
method: 'POST', |
||||
data: dataSerializer, |
||||
dataType: 'json', |
||||
success: function (data) { |
||||
console.log(data); |
||||
if (data.status == 'ok') { |
||||
location.reload(); |
||||
} |
||||
}, |
||||
error: function (jqXHR, exception) { |
||||
console.log(jqXHR); |
||||
console.log(exception); |
||||
console.log(jqXHR.statusCode); |
||||
} |
||||
|
||||
}) |
||||
}); |
||||
}); |
||||
|
||||
</script> |
||||
{% endblock %} |
||||
@ -0,0 +1 @@ |
||||
Заявка на вывод средств от {{ username }}! |
||||
@ -0,0 +1,2 @@ |
||||
Заявка на распечатку от {{ username }}! |
||||
|
||||
@ -0,0 +1,10 @@ |
||||
from django.conf import urls |
||||
from .views import ScoreDetailView, WithDrawCreate |
||||
|
||||
app_name = 'wallets' |
||||
|
||||
urlpatterns = [ |
||||
urls.url(r'^score/(?P<pk>\d+)/$', ScoreDetailView.as_view(), name='score-detail'), |
||||
urls.url(r'^withdraw/create/$', WithDrawCreate.as_view(), name='withdraw-create'), |
||||
|
||||
] |
||||
@ -1,3 +1,69 @@ |
||||
from django.shortcuts import render |
||||
from django.http import JsonResponse |
||||
from django.contrib import messages |
||||
from django.db.models import Sum |
||||
from django.views.generic import DetailView, CreateView |
||||
from users.models import User |
||||
from users.mixins import CheckForUserMixin |
||||
from .models import InvoiceHistory, WithDraw |
||||
from .forms import WithDrawForm |
||||
|
||||
# Create your views here. |
||||
|
||||
class ScoreDetailView(CheckForUserMixin, DetailView): |
||||
model = User |
||||
template_name = 'score-detail.html' |
||||
context_object_name = 'user_score' |
||||
|
||||
def get_context_data(self, **kwargs): |
||||
context = super().get_context_data(**kwargs) |
||||
user_score_balance = InvoiceHistory.objects.filter(user=self.get_object()).aggregate(Sum('sum')) |
||||
context['user_score_balance'] = user_score_balance['sum__sum'] or 0 |
||||
context['form'] = WithDrawForm |
||||
return context |
||||
|
||||
|
||||
class AjaxableResponseMixin(object): |
||||
def form_invalid(self, form): |
||||
response = super().form_invalid(form) |
||||
if self.request.is_ajax(): |
||||
return JsonResponse(form.errors, status=400) |
||||
else: |
||||
return response |
||||
|
||||
def form_valid(self, form): |
||||
# import code; code.interact(local=dict(globals(), **locals())) |
||||
response = super(AjaxableResponseMixin, self).form_valid(form) |
||||
if self.request.is_ajax(): |
||||
messages.info(self.request, 'Ваша заявка на вывод средств принята!') |
||||
data = { |
||||
'pk': self.object.pk, |
||||
'status': 'ok', |
||||
} |
||||
return JsonResponse(data) |
||||
else: |
||||
return response |
||||
|
||||
|
||||
# class WithDrawCreate(AjaxableResponseMixin, CreateView): |
||||
# model = WithDraw |
||||
# form_class = WithDrawForm |
||||
# success_url = '/' |
||||
|
||||
class WithDrawCreate(CreateView): |
||||
model = WithDraw |
||||
form_class = WithDrawForm |
||||
|
||||
def form_valid(self, form): |
||||
if self.request.is_ajax(): |
||||
self.object = form.save() |
||||
messages.info(self.request, 'Ваша заявка на вывод средств принята!') |
||||
data = { |
||||
'pk': self.object.pk, |
||||
'status': 'ok', |
||||
} |
||||
return JsonResponse(data) |
||||
return super().form_valid(form) |
||||
|
||||
def form_invalid(self, form): |
||||
if self.request.is_ajax(): |
||||
return JsonResponse(form.errors, status=400) |
||||
return super().form_invalid(form) |
||||
|
||||
Loading…
Reference in new issue