Add recent view organization
This commit is contained in:
parent
7a9dad71b4
commit
512bc92116
6 changed files with 101 additions and 1 deletions
27
judge/migrations/0134_auto_20221018_0124.py
Normal file
27
judge/migrations/0134_auto_20221018_0124.py
Normal file
File diff suppressed because one or more lines are too long
|
@ -9,6 +9,7 @@ from django.urls import reverse
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from requests import delete
|
||||||
from fernet_fields import EncryptedCharField
|
from fernet_fields import EncryptedCharField
|
||||||
from sortedm2m.fields import SortedManyToManyField
|
from sortedm2m.fields import SortedManyToManyField
|
||||||
|
|
||||||
|
@ -422,3 +423,50 @@ class Friend(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.current_user)
|
return str(self.current_user)
|
||||||
|
|
||||||
|
|
||||||
|
class OrganizationProfile(models.Model):
|
||||||
|
users = models.ForeignKey(
|
||||||
|
Profile,
|
||||||
|
verbose_name=_("user"),
|
||||||
|
related_name="last_visit",
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
db_index=True,
|
||||||
|
)
|
||||||
|
organization = models.ForeignKey(
|
||||||
|
Organization,
|
||||||
|
verbose_name=_("organization"),
|
||||||
|
related_name="last_vist",
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
db_index=True,
|
||||||
|
)
|
||||||
|
last_visit = models.AutoField(
|
||||||
|
verbose_name=_("last visit"),
|
||||||
|
primary_key=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def is_organization(self, users, organization):
|
||||||
|
return (
|
||||||
|
self.objects.filter(users=users)
|
||||||
|
.filter(organization=organization)
|
||||||
|
.exists()
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def remove_organization(self, users, organization):
|
||||||
|
organizationprofile = self.objects.filter(users=users).filter(
|
||||||
|
organization=organization
|
||||||
|
)
|
||||||
|
organizationprofile.delete()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def add_organization(self, users, organization):
|
||||||
|
if self.is_organization(users, organization):
|
||||||
|
self.remove_organization(users, organization)
|
||||||
|
new_organization = OrganizationProfile(users=users, organization=organization)
|
||||||
|
new_organization.save()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_organization(self, users):
|
||||||
|
return self.objects.filter(users=users).order_by("-last_visit")[:5]
|
||||||
|
|
|
@ -19,6 +19,7 @@ from judge.models import (
|
||||||
Submission,
|
Submission,
|
||||||
Ticket,
|
Ticket,
|
||||||
)
|
)
|
||||||
|
from judge.models.profile import Organization, OrganizationProfile
|
||||||
from judge.utils.cachedict import CacheDict
|
from judge.utils.cachedict import CacheDict
|
||||||
from judge.utils.diggpaginator import DiggPaginator
|
from judge.utils.diggpaginator import DiggPaginator
|
||||||
from judge.utils.problems import user_completed_ids
|
from judge.utils.problems import user_completed_ids
|
||||||
|
@ -74,10 +75,12 @@ class FeedView(ListView):
|
||||||
.filter(is_visible=True)
|
.filter(is_visible=True)
|
||||||
.order_by("start_time")
|
.order_by("start_time")
|
||||||
)
|
)
|
||||||
|
|
||||||
context["current_contests"] = visible_contests.filter(
|
context["current_contests"] = visible_contests.filter(
|
||||||
start_time__lte=now, end_time__gt=now
|
start_time__lte=now, end_time__gt=now
|
||||||
)
|
)
|
||||||
context["future_contests"] = visible_contests.filter(start_time__gt=now)
|
context["future_contests"] = visible_contests.filter(start_time__gt=now)
|
||||||
|
context["recent_organizations"] = OrganizationProfile.get_organization(self.request.profile)
|
||||||
context["top_rated"] = Profile.objects.filter(is_unlisted=False).order_by(
|
context["top_rated"] = Profile.objects.filter(is_unlisted=False).order_by(
|
||||||
"-rating"
|
"-rating"
|
||||||
)[:10]
|
)[:10]
|
||||||
|
|
|
@ -35,6 +35,7 @@ from django.views.generic.detail import (
|
||||||
SingleObjectTemplateResponseMixin,
|
SingleObjectTemplateResponseMixin,
|
||||||
)
|
)
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
|
from judge.models.profile import OrganizationProfile
|
||||||
from reversion import revisions
|
from reversion import revisions
|
||||||
|
|
||||||
from judge.forms import (
|
from judge.forms import (
|
||||||
|
@ -126,6 +127,7 @@ class OrganizationMixin(OrganizationBase):
|
||||||
context["logo_override_image"] = self.organization.logo_override_image
|
context["logo_override_image"] = self.organization.logo_override_image
|
||||||
if "organizations" in context:
|
if "organizations" in context:
|
||||||
context.pop("organizations")
|
context.pop("organizations")
|
||||||
|
OrganizationProfile.add_organization(self.request.profile, self.organization)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
@ -261,7 +263,6 @@ class OrganizationList(TitleMixin, ListView, OrganizationBase):
|
||||||
|
|
||||||
class OrganizationHome(OrganizationDetailView):
|
class OrganizationHome(OrganizationDetailView):
|
||||||
template_name = "organization/home.html"
|
template_name = "organization/home.html"
|
||||||
|
|
||||||
def get_posts(self):
|
def get_posts(self):
|
||||||
posts = (
|
posts = (
|
||||||
BlogPost.objects.filter(
|
BlogPost.objects.filter(
|
||||||
|
|
|
@ -123,6 +123,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% include 'contests-countdown.html' %}
|
{% include 'contests-countdown.html' %}
|
||||||
|
{% include 'recent-organization.html' %}
|
||||||
{% include 'top-users.html' %}
|
{% include 'top-users.html' %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
20
templates/recent-organization.html
Normal file
20
templates/recent-organization.html
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{% if recent_organizations %}
|
||||||
|
<div class="blog-sidebox sidebox">
|
||||||
|
<h3>{{ _('Recent Organization') }} <i class="fa fa-trophy"></i></h3>
|
||||||
|
<div class="sidebox-content" style="padding: 0; border: 0">
|
||||||
|
<table class="table feed-table">
|
||||||
|
<tbody>
|
||||||
|
{% for organization in recent_organizations %}
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 7px 2px">
|
||||||
|
<a href="{{ url('organization_home', organization.organization.pk, organization.organization.slug) }}">
|
||||||
|
<b> {{organization.organization}} </b>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
Loading…
Reference in a new issue