Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions zapisy/apps/effects/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Set

from django.db import models

from apps.enrollment.courses.models.course_instance import CourseInstance
Expand All @@ -14,16 +12,3 @@ class CompletedCourses(models.Model):

class Meta:
unique_together = ('student', 'course', 'program')

def get_completed_effects(student: Student) -> Set[str]:
completed_courses = (
CompletedCourses.objects.filter(student=student, program=student.program)
.select_related('course').prefetch_related('course__effects')
)

done_effects = set()
for record in completed_courses:
for effect in record.course.effects.all():
done_effects.add(effect.group_name)

return done_effects
8 changes: 0 additions & 8 deletions zapisy/apps/effects/templates/effects.html

This file was deleted.

44 changes: 3 additions & 41 deletions zapisy/apps/enrollment/courses/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from django.contrib import admin, messages
from django.contrib.admin import SimpleListFilter

from apps.enrollment.courses.models.classroom import Classroom
from apps.enrollment.courses.models.course_instance import CourseInstance
from apps.enrollment.courses.models.course_type import Type
from apps.enrollment.courses.models.effects import Effects
from apps.enrollment.courses.models.group import Group, GuaranteedSpots
from apps.enrollment.courses.models.semester import ChangedDay, Freeday, Semester
from apps.enrollment.courses.models.tag import Tag
from apps.enrollment.courses.models.tags import SpecialistTag, ThematicTag
from apps.enrollment.courses.models.term import Term
from apps.enrollment.records.models import GroupOpeningTimes, Record, RecordStatus, T0Times

Expand Down Expand Up @@ -74,26 +71,6 @@ class FreedayAdmin(admin.ModelAdmin):
ordering = ('-day',)


class EffectsListFilter(SimpleListFilter):
title = 'Grupa efektów kształcenia'

# Parameter for the filter that will be used in the URL query.
parameter_name = 'effects'

def lookups(self, request, model_admin):
result = []
for effect in Effects.objects.all():
result.append((str(effect.id), effect))

return result

def queryset(self, request, queryset):
if self.value():
return queryset.filter(effects=self.value())
else:
return queryset


class TermInline(admin.TabularInline):
model = Term
extra = 0
Expand Down Expand Up @@ -172,29 +149,14 @@ def get_queryset(self, request):
'course__semester').prefetch_related('term', 'record_set')


@admin.register(CourseInstance)
class CourseInstanceAdmin(admin.ModelAdmin):
list_filter = ('semester', 'course_type', ('owner', admin.RelatedOnlyFieldListFilter),
'tags', 'effects',)
list_display = ('name', 'owner', 'course_type', 'semester',)
search_fields = ('name', 'name_en')
ordering = ('semester', 'owner', 'offer')

def get_queryset(self, request):
qs = super().get_queryset(request)
return qs.select_related('owner', 'semester', 'offer')

inlines = [GroupInline, ]


class TypeAdmin(admin.ModelAdmin):
list_display = ('name', 'group', 'meta_type')
list_filter = ('group', 'meta_type')


admin.site.register(Group, GroupAdmin)
admin.site.register(Tag)
admin.site.register(Effects)
admin.site.register(ThematicTag)
admin.site.register(SpecialistTag)
admin.site.register(Classroom, ClassroomAdmin)
admin.site.register(Semester, SemesterAdmin)
admin.site.register(Freeday, FreedayAdmin)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by Django 3.1.14 on 2025-01-05 14:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('courses', '0036_auto_20211022_1641'),
]

operations = [
migrations.RemoveField(
model_name='courseinformation',
name='effects',
),
migrations.DeleteModel(
name='Effects',
),
migrations.CreateModel(
name='SpecialistTag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('short_name', models.CharField(max_length=50, verbose_name='nazwa skrócona')),
('full_name', models.CharField(max_length=250, verbose_name='nazwa pełna')),
('description', models.TextField(verbose_name='opis')),
],
options={
'verbose_name': 'Tag specjalistyczny (I st.)',
'verbose_name_plural': 'Tagi specjalistyczne (I st.)',
},
),
migrations.RenameModel(
old_name='Tag',
new_name='ThematicTag',
),
migrations.AlterModelOptions(
name='thematictag',
options={'verbose_name': 'Tag specjalistyczny (II st.)', 'verbose_name_plural': 'Tagi specjalistyczne (II st.)'},
),
Comment on lines +37 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To chyba odnosi się do zmiany opcji starego modelu tag, ale wartości tekstowe nie odpowiadają jego nowej nazwie thematictag. Być może to po prostu jakaś stara wersja migracji, ale trzeba coś z tym zrobić.

migrations.AddField(
model_name='courseinformation',
name='specialist_tags',
field=models.ManyToManyField(blank=True, to='courses.SpecialistTag', verbose_name='Tagi specjalistyczne (II st.)'),
),
migrations.RenameField(
model_name='courseinformation',
old_name='tags',
new_name='thematic_tags',
),
]
21 changes: 10 additions & 11 deletions zapisy/apps/enrollment/courses/models/course_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from apps.users.models import Employee

from .course_type import Type as CourseType
from .effects import Effects
from .tag import Tag
from .tags import SpecialistTag, ThematicTag


class Language(models.TextChoices):
Expand Down Expand Up @@ -72,8 +71,8 @@ class CourseInformation(models.Model):
year = models.CharField("rok studiów", max_length=50, blank=True)
discipline = models.CharField("dyscyplina", max_length=100, default="Informatyka")

tags = models.ManyToManyField(Tag, verbose_name="tagi", blank=True)
effects = models.ManyToManyField(Effects, verbose_name="grupy efektów kształcenia", blank=True)
thematic_tags = models.ManyToManyField(ThematicTag, verbose_name="Tagi tematyczne (I st.)", blank=True)
specialist_tags = models.ManyToManyField(SpecialistTag, verbose_name="Tagi specjalistyczne (II st.)", blank=True)

created = models.DateTimeField("Data utworzenia", auto_now_add=True)
modified = models.DateTimeField("Data modyfikacji", auto_now=True)
Expand Down Expand Up @@ -113,15 +112,15 @@ def __copy__(self) -> 'CourseInformation':
return copy

def __json__(self):
"""Returns a JSON-serializable dict with al course information."""
"""Returns a JSON-serializable dict with all course information."""
return {
'id': self.id,
'name': self.name,
'courseType': self.course_type_id,
'recommendedForFirstYear': self.recommended_for_first_year,
'owner': self.owner_id,
'effects': [effect.pk for effect in self.effects.all()],
'tags': [tag.pk for tag in self.tags.all()],
'thematic_tags': [tag.pk for tag in self.thematic_tags.all()],
'specialist_tags': [tag.pk for tag in self.specialist_tags.all()],
}

def get_short_name(self):
Expand All @@ -130,14 +129,14 @@ def get_short_name(self):
@staticmethod
def prepare_filter_data(qs: models.QuerySet) -> Dict:
"""Prepares the data for course filter based on a given queryset."""
all_effects = Effects.objects.all().values_list('id', 'group_name', named=True)
all_tags = Tag.objects.all().values_list('id', 'full_name', named=True)
all_thematic_tags = ThematicTag.objects.all().values_list('id', 'full_name', named=True)
all_specialist_tags = SpecialistTag.objects.all().values_list('id', 'full_name', named=True)
all_owners = qs.values_list(
'owner', 'owner__user__first_name', 'owner__user__last_name', named=True).distinct()
all_types = qs.values_list('course_type', 'course_type__name', named=True).distinct()
return {
'allEffects': {e.id: e.group_name for e in all_effects},
'allTags': {t.id: t.full_name for t in all_tags},
'allThematicTags': {t.id: t.full_name for t in all_thematic_tags},
'allSpecialistTags': {t.id: t.full_name for t in all_specialist_tags},
'allOwners': {
o.owner: [o.owner__user__first_name, o.owner__user__last_name] for o in all_owners
},
Expand Down
4 changes: 2 additions & 2 deletions zapisy/apps/enrollment/courses/models/course_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def create_proposal_instance(cls, proposal: Proposal, semester: Semester):

instance = cls(**proposal_dict)
instance.save()
instance.tags.set(proposal.tags.all())
instance.effects.set(proposal.effects.all())
instance.thematic_tags.set(proposal.thematic_tags.all())
instance.specialist_tags.set(proposal.specialist_tags.all())
return instance

@classmethod
Expand Down
21 changes: 0 additions & 21 deletions zapisy/apps/enrollment/courses/models/effects.py

This file was deleted.

23 changes: 0 additions & 23 deletions zapisy/apps/enrollment/courses/models/tag.py

This file was deleted.

35 changes: 35 additions & 0 deletions zapisy/apps/enrollment/courses/models/tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.db import models


class BaseTag(models.Model):
short_name = models.CharField(max_length=50, verbose_name='nazwa skrócona')
full_name = models.CharField(max_length=250, verbose_name='nazwa pełna')
description = models.TextField(verbose_name='opis')

class Meta:
abstract = True

def __str__(self):
return f"{self.short_name} ({self.full_name})"

def serialize_for_json(self):
return {
'id': self.pk,
'short_name': self.short_name,
'full_name': self.full_name,
'description': self.description,
}


class ThematicTag(BaseTag):
class Meta:
verbose_name = 'Tag tematyczny (I st.)'
verbose_name_plural = 'Tagi tematyczne (I st.)'
app_label = 'courses'


class SpecialistTag(BaseTag):
class Meta:
verbose_name = 'Tag specjalistyczny (II st.)'
verbose_name_plural = 'Tagi specjalistyczne (II st.)'
Comment on lines +26 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To może rewolucyjne, ale przy okazji sprawmy, żeby w systemie posługiwać się językiem polskim (i jednocześnie stosować nomenklaturę pojawiającą się w programie studiów) – plus oczywiście analogiczne zmiany w innych plikach.

Suggested change
verbose_name = 'Tag tematyczny (I st.)'
verbose_name_plural = 'Tagi tematyczne (I st.)'
app_label = 'courses'
class SpecialistTag(BaseTag):
class Meta:
verbose_name = 'Tag specjalistyczny (II st.)'
verbose_name_plural = 'Tagi specjalistyczne (II st.)'
verbose_name = "Znacznik tematyczny (I st.)"
verbose_name_plural = "Znaczniki tematyczne (I st.)"
app_label = 'courses'
class SpecialistTag(BaseTag):
class Meta:
verbose_name = "Znacznik specjalistyczny (II st.)"
verbose_name_plural = "Znaczniki specjalistyczne (II st.)"

(Podwójne cudzysłowy stosujemy dla napisów przeznaczonych "dla ludzkich oczu", a pojedyncze – dla tych przetwarzanych wewnętrznie w kodzie.)

app_label = 'courses'
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ <h1 class="d-inline-block">
<th scope="row">Egzamin</th>
<td>{{ course.has_exam|yesno|capfirst }}</td>
</tr>
{% if course.tags.all %}
{% if course.thematic_tags.all %}
<tr>
<th scope="row">Tagi</th>
<th scope="row">Tagi tematyczne</th>
<td class="badges">
<ul>
{% for tag in course.tags.all %}
{% for tag in course.thematic_tags.all %}
<li class="badge bg-success me-2">{{ tag }}</li>
{% endfor %}
</ul>
</td>
</tr>
{% endif %}
{% if course.effects.all %}
{% if course.specialist_tags.all %}
<tr>
<th>Grupy efektów kształcenia</th>
<th>Tagi specjalistyczne</th>
<td class="badges">
<ul>
{% for effect in course.effects.all %}
<li class="badge bg-info me-2">{{ effect }}</li>
{% for tag in course.specialist_tags.all %}
<li class="badge bg-info me-2">{{ tag }}</li>
{% endfor %}
</ul>
</td>
Expand Down
6 changes: 2 additions & 4 deletions zapisy/apps/enrollment/courses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def prepare_courses_list_data(semester: Optional[Semester]):
"""Returns a dict used by course list and filter in various views."""
qs = CourseInstance.objects.filter(semester=semester).order_by('name')
courses = []
for course in qs.prefetch_related('effects', 'tags'):
for course in qs.prefetch_related('thematic_tags', 'specialist_tags'):
course_dict = course.__json__()
course_dict.update({
'url': reverse('course-page', args=(course.slug,)),
Expand Down Expand Up @@ -68,7 +68,7 @@ def course_view_data(request, slug) -> Tuple[Optional[CourseInstance], Optional[
course: CourseInstance
try:
course = CourseInstance.objects.filter(slug=slug).select_related(
'semester', 'course_type').prefetch_related('tags', 'effects').get()
'semester', 'course_type').prefetch_related('thematic_tags', 'specialist_tags').get()
except CourseInstance.DoesNotExist:
return None, None

Expand Down Expand Up @@ -331,8 +331,6 @@ def get_all_group_ids_for_course_slug(slug, class_type: int = None):
try:
course = (
CourseInstance.objects.filter(slug=slug)
.select_related('semester', 'course_type')
.prefetch_related('tags', 'effects')
.get()
)
except CourseInstance.DoesNotExist:
Expand Down
Loading
Loading