set access

This commit is contained in:
Egor Matveev 2022-02-03 00:10:17 +03:00
parent 3bde9c11b9
commit c22663d962
2 changed files with 12 additions and 0 deletions

View File

@ -1,6 +1,8 @@
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields import ArrayField
from django.db import models from django.db import models
from django.utils import timezone
from Main.models.set import Set from Main.models.set import Set
@ -10,3 +12,7 @@ class Group(models.Model):
creator = models.ForeignKey(User, null=True, on_delete=models.SET_NULL) creator = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
users = models.ManyToManyField(User, related_name='user_groups') users = models.ManyToManyField(User, related_name='user_groups')
editors = ArrayField(models.TextField(), default=list) editors = ArrayField(models.TextField(), default=list)
@property
def available_sets(self):
return self.sets.filter(opened=True, start_time__lte=timezone.now(), end_time__gte=timezone.now())

View File

@ -5,9 +5,15 @@
{% if group.creator %}Владелец группы: <img src="{{ group.creator.userinfo.profile_pic_url }}" width="30px" height="30px" style="border-radius: 50%; margin-right: 10px;"><a href="/account?username={{ group.creator.username }}">{{ group.creator.username }}</a> {% endif %} {% if group.creator %}Владелец группы: <img src="{{ group.creator.userinfo.profile_pic_url }}" width="30px" height="30px" style="border-radius: 50%; margin-right: 10px;"><a href="/account?username={{ group.creator.username }}">{{ group.creator.username }}</a> {% endif %}
<hr><hr> <hr><hr>
<h2>Сеты</h2> <h2>Сеты</h2>
{% if group.creator == user or user.username in group.editors %}
{% for set in group.sets.all %} {% for set in group.sets.all %}
<a href="/set?set_id={{ set.id }}">{{ set.name }}</a><br> <a href="/set?set_id={{ set.id }}">{{ set.name }}</a><br>
{% endfor %} {% endfor %}
{% else %}
{% for set in group.available_sets %}
<a href="/set?set_id={{ set.id }}">{{ set.name }}</a><br>
{% endfor %}
{% endif %}
{% if group.creator == user or user.username in group.editors %} {% if group.creator == user or user.username in group.editors %}
<button type="button" class="btn btn-primary" style="margin-top: 20px;" data-toggle="modal" data-target="#example"><i class="fa fa-pencil"></i> Редактировать</button> <button type="button" class="btn btn-primary" style="margin-top: 20px;" data-toggle="modal" data-target="#example"><i class="fa fa-pencil"></i> Редактировать</button>
<div class="modal fade" id="example" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true"> <div class="modal fade" id="example" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">