Skip to content

Commit

Permalink
Merge remote-tracking branch 'znick_anytask/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailyumanov committed Mar 18, 2021
2 parents 1de7013 + bbb183a commit 521eecd
Show file tree
Hide file tree
Showing 20 changed files with 2,213 additions and 1,057 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[flake8]
count = True
exclude = .git,__pycache__,build,dist,anytask/media,debian,migrations
ignore =
W503
# W503 is deprecated, see https://www.python.org/dev/peps/pep-0008/#id20
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion anytask/anycontest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_contest_mark(self):
got_mark = True
except Exception as e:
logger.exception("Exception while request to Contest: '%s' : '%s', Exception: '%s'",
results_req.url, results_req.json(), e)
results_req.url, results_req.text, e)
got_mark = False
self.save()

Expand Down
2 changes: 2 additions & 0 deletions anytask/anyrb/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def upload_review(self):
description=description,
description_text_type='markdown',
target=settings.RB_API_USERNAME, public=True,
target_groups='teachers_{0}'.format(issue.task.course.pk),
target_people=issue.student.username
)
return review_request.id

Expand Down
30 changes: 16 additions & 14 deletions anytask/courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,19 @@ def user_can_see_attendance_log(self, user):
return self.has_attendance_log and self.user_is_teacher(user)

def save(self, *args, **kwargs):
created = self.id is None
super(Course, self).save(*args, **kwargs)
self.add_group_with_extern()

# Hack hack hack
# We need to triger add_default_issue_fields (m2m_change)
# for new courses
if created:
fields = IssueField.objects.all()
if fields.exists():
any_field = fields[0]
self.issue_fields.add(any_field)

def add_group_with_extern(self):
if self.group_with_extern is None and self.can_be_chosen_by_extern:
group, ok = Group.objects.get_or_create(year=self.year, name=u'%s - слушатели' % self.name)
Expand Down Expand Up @@ -292,24 +302,16 @@ class Meta:
def add_default_issue_fields(sender, instance, action, **kwargs):
default_issue_fields = DefaultIssueFields()
default_issue_fields.set_integrated(instance.rb_integrated, instance.contest_integrated)
pk_set = kwargs.get("pk_set", set())

if action not in ("post_add", "post_remove", "post_clear"):
return
if action in ("post_add", "post_remove", "post_clear"):
current_fields = set(instance.issue_fields.all())
default_fields = set(default_issue_fields.get_issue_fields())

if action in ("post_remove", "post_clear"):
if pk_set and set(pk_set) == default_issue_fields.get_deleted_pks():
fields_to_add = default_fields - current_fields
if not fields_to_add:
return

instance.issue_fields.add(*default_issue_fields.get_issue_fields())
return

if action == "post_add":
if pk_set and set(pk_set) == default_issue_fields.get_pks():
return

instance.issue_fields.remove(*default_issue_fields.get_deleted_issue_fields())
return
instance.issue_fields.add(*fields_to_add)


def update_rb_review_group(sender, instance, created, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions anytask/courses/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def test_course_create_filled(self):
teachers = [User.objects.create(username='test_teachers', password='password')]
groups = [Group.objects.create(name='name_groups', year=year)]
group_with_extern = Group.objects.create(name='name_group_with_extern', year=year)
issue_fields = [IssueField.objects.create(name='name_issue_fields')]
filename_extensions = [FilenameExtension.objects.create(name='name_filename_extensions')]
mark_system = CourseMarkSystem.objects.create(name='name_mark_system')

Expand All @@ -52,7 +51,6 @@ def test_course_create_filled(self):
course.save()
course.teachers = teachers
course.groups = groups
course.issue_fields.set(issue_fields, clear=True)
# course.contest_integrated = True
# course.send_rb_and_contest_together = True
# course.rb_integrated = True
Expand Down
60 changes: 60 additions & 0 deletions anytask/index/templates/archived_schools_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{% extends "base.html" %}
{% load i18n %}
{% load django_bootstrap_breadcrumbs %}

{% block title %}Anytask{% endblock %}

{% block scripts %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.matchHeight/0.7.0/jquery.matchHeight-min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.card-centered').matchHeight();
});
</script>
{% endblock %}

{% block navbar %}
<ul class="nav navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="">{% trans "arhiv" %}</a>
</li>
</ul>
{% endblock navbar %}

{% block breadcrumbs %}
{{ block.super }}
{% breadcrumb_for "" %}
{% trans "arhiv" %}
{% endbreadcrumb_for %}
{% endblock breadcrumbs %}

{% block content %}

{# <div class="jumbotron">#}
{# <h1 class="display-3">Anytask</h1>#}
{# <p class="lead">&beta;-{% trans "версия" %}</p>#}
{# <p>#}
{# {% trans "Платформа для взаимодействия преподавателей и студентов в процессе обучения." %}#}
{##}
{# {% trans "AnyTask &#151; сервис для учета выполнения студентами программы по учебным курсам." %}#}
{# <a href="/about">>></a> #}
{# </p>#}
{# <!-- <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p> -->#}
{# </div>#}

<div class="row">
{% for school in schools %}
<div class="col-md-6">
<div class="card">
<a class="card-link card-clickable" href="{% url "schools.views.archive_page" school.link %}">
<div class="card-block card-centered">
<h4 class="card-title">{{ school.name }}</h4>
{# <p class="card-text">Some text.</p>#}
</div>
</a>
</div>
</div>
{% endfor %}
</div>

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
</script>
{% endblock %}

{% block navbar %}
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{% url "index.views.archive_index" %}">{% trans "arhiv" %}</a>
</li>
</ul>
{% endblock navbar %}

{% block content %}

{% index_message %}
Expand Down
54 changes: 50 additions & 4 deletions anytask/index/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,57 @@
"""

from django.test import TestCase
from django.urls import reverse

from schools.models import School

class SimpleTest(TestCase):
def test_basic_addition(self):

class IndexTest(TestCase):
def test_schools_presence(self):
"""
Tests that 1 + 1 always equals 2.
Test that active/archieved schools are present in
active/archived indexes respectively and only there.
"""
self.assertEqual(1 + 1, 2)
# Create data
School.objects.create(
name='active_school', link='active_school', is_active=True)
School.objects.create(
name='archived_school', link='archived_school', is_active=False)
# Active index
response = self.client.get(reverse('index.views.index'))
self.assertQuerysetEqual(
response.context['schools'],
['<School: active_school>']
)
# Archive index
response = self.client.get(reverse('index.views.archive_index'))
self.assertQuerysetEqual(
response.context['schools'],
['<School: archived_school>']
)

def test_switch_lang(self):
for lang in ('en', 'ru'):
response = self.client.post(reverse('set_lang'), {'lang': lang})
self.assertEqual(response.status_code, 200)

response = self.client.get(reverse('get_lang'))
self.assertEqual(response.content, lang)

def test_switch_wrong(self):
response = self.client.get(reverse('get_lang'))
current_lang = response.content

# bad language
response = self.client.post(reverse('set_lang'), {'lang': 'no_such_lang'})
self.assertEqual(response.status_code, 404)

response = self.client.get(reverse('get_lang'))
self.assertEqual(response.content, current_lang) # language not changed

# bad request
response = self.client.post(reverse('set_lang'), {'lang': ''})
self.assertEqual(response.status_code, 400)

response = self.client.get(reverse('get_lang'))
self.assertEqual(response.content, current_lang) # language not changed
14 changes: 12 additions & 2 deletions anytask/index/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def index(request):
schools = School.objects.all().order_by('name')
schools = School.objects.all().filter(is_active=True).order_by('name')

# current_year = get_current_year()
# courses = Course.objects.filter(is_active=True).order_by('name')
Expand All @@ -13,4 +13,14 @@ def index(request):
'schools': schools,
}

return render(request, 'index.html', context)
return render(request, 'schools_page.html', context)


def archive_index(request):
schools = School.objects.all().filter(is_active=False).order_by('name')

context = {
'schools': schools,
}

return render(request, 'archived_schools_page.html', context)
Loading

0 comments on commit 521eecd

Please sign in to comment.