notifications
This commit is contained in:
parent
5a3e696eac
commit
b28490697f
18
Main/migrations/0008_userinfo_notification_friends.py
Normal file
18
Main/migrations/0008_userinfo_notification_friends.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.2.4 on 2021-12-19 15:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('Main', '0007_friendship'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='userinfo',
|
||||
name='notification_friends',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
@ -5,6 +5,7 @@ from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
|
||||
from Main.models.friendship import Friendship
|
||||
from Main.models.set import Set
|
||||
from Main.models.group import Group
|
||||
from Main.models.settask import SetTask
|
||||
@ -24,6 +25,7 @@ class UserInfo(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True)
|
||||
telegram_chat_id = models.TextField(default="")
|
||||
notification_solution_result = models.BooleanField(default=False)
|
||||
notification_friends = models.BooleanField(default=False)
|
||||
code = models.IntegerField(null=True)
|
||||
verified = models.BooleanField(default=False)
|
||||
|
||||
@ -33,10 +35,7 @@ class UserInfo(models.Model):
|
||||
|
||||
@cached_property
|
||||
def friends(self):
|
||||
return User.objects.filter(
|
||||
Q(to_friendship__to_user=self, to_friendship__verified=True)
|
||||
| Q(from_friendship__from_user=self, from_friendship__verified=True)
|
||||
)
|
||||
return Friendship.objects.filter(Q(to_user=self.user) | Q(from_user=self.user))
|
||||
|
||||
@property
|
||||
def favourite_language(self):
|
||||
|
@ -44,6 +44,7 @@ class AccountView(BaseView):
|
||||
).first()
|
||||
if friendship is None:
|
||||
Friendship.objects.create(from_user=self.request.user, to_user=self.context["account"])
|
||||
if self.context["account"].userinfo.notification_friends:
|
||||
bot.send_message(self.context["account"].userinfo.telegram_chat_id, f"Пользователь {self.request.user.username} хочет добавить тебя в друзья")
|
||||
elif friendship.verified or friendship.from_user == self.request.user:
|
||||
friendship.delete()
|
||||
@ -51,10 +52,12 @@ class AccountView(BaseView):
|
||||
if self.request.POST["to_do"] == "yes":
|
||||
friendship.verified = True
|
||||
friendship.save()
|
||||
if self.context["account"].userinfo.notification_friends:
|
||||
bot.send_message(self.context["account"].userinfo.telegram_chat_id,
|
||||
f"Пользователь {self.request.user.username} добавил тебя в друзья")
|
||||
else:
|
||||
friendship.delete()
|
||||
if self.context["account"].userinfo.notification_friends:
|
||||
bot.send_message(self.context["account"].userinfo.telegram_chat_id,
|
||||
f"Пользователь {self.request.user.username} отклонил твою заявку")
|
||||
return "/account?username=" + self.request.GET["username"]
|
||||
|
@ -23,11 +23,11 @@
|
||||
<div class="col-9">
|
||||
<h3>
|
||||
{{ account.userinfo.surname }} {{ account.userinfo.name }}
|
||||
<span style="margin-left: 15px;" class="badge badge-{% if account.userinfo.activity_status == online_status %}success{% else %}secondary{% endif %}">{{ account.userinfo.activity_status }}</span>
|
||||
<span style="margin-left: 15px; margin-bottom: 20px;" class="badge badge-{% if account.userinfo.activity_status == online_status %}success{% else %}secondary{% endif %}">{{ account.userinfo.activity_status }}</span>
|
||||
{% if not owner %}
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="friendship">
|
||||
{% if not owner %}
|
||||
{% if friendship_status == 0 %}
|
||||
<button type="submit" class="btn btn-primary" name="to_do" value="add">Добавить в друзья</button>
|
||||
{% else %}{% if friendship_status == 1 %}
|
||||
@ -37,8 +37,8 @@
|
||||
{% else %}
|
||||
<button class="btn btn-info" type="submit" name="to_do" value="yes">Принять</button> <button class="btn btn-danger" type="submit" name="to_do" value="no">Отклонить</button>
|
||||
{% endif %}{% endif %}{% endif %}
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
{% if user.is_superuser and owner %}
|
||||
<a style="margin-left: 15px;" href="/admin/" class="badge badge-secondary">Админ</a>
|
||||
{% endif %}
|
||||
@ -125,9 +125,24 @@
|
||||
<input type="checkbox" name="notification_solution_result" {% if user.userinfo.notification_solution_result %}checked{% endif %}>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width: 200px;">
|
||||
Заявки в друзья
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" name="notification_friends" {% if user.userinfo.notification_friends %}checked{% endif %}>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<button type="submit" class="btn btn-light" style="margin-top: 15px;"><i class="fa fa-save"></i> Сохранить</button>
|
||||
|
||||
</form>
|
||||
<hr><hr>
|
||||
<h2 style="margin-bottom: 20px;">Друзья</h2>
|
||||
<h5>
|
||||
{% for friendship in user.userinfo.friends %}
|
||||
<i class="fa fa-user"></i> <a href="/account?username={% if friendship.to_user == user %}{{ friendship.from_user.username }}{% else %}{{ friendship.to_user.username }}{% endif %}">{% if friendship.to_user == user %}{{ friendship.from_user.username }}{% else %}{{ friendship.to_user.username }}{% endif %}</a><br>
|
||||
{% endfor %}
|
||||
</h5>
|
||||
{% endif %}
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user