Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Course Guide Partial Update #576

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
17 changes: 17 additions & 0 deletions hknweb/academics/migrations/0003_alter_icsr_course_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.16 on 2024-12-04 02:31

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("academics", "0002_auto_20211223_1902"),
]

operations = [
migrations.AlterField(
model_name="icsr",
name="course_name",
field=models.TextField(default="", max_length=500),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.16 on 2024-12-04 02:31

from django.db import migrations
import markdownx.models


class Migration(migrations.Migration):
dependencies = [
("events", "0012_icalview"),
]

operations = [
migrations.AlterModelOptions(
name="icalview",
options={"verbose_name": "iCal view"},
),
migrations.AlterField(
model_name="event",
name="description",
field=markdownx.models.MarkdownxField(max_length=2000),
),
]
12 changes: 7 additions & 5 deletions hknweb/studentservices/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ class ToursAdmin(admin.ModelAdmin):

@admin.register(CourseGuideNode)
class CourseGuideNodeAdmin(admin.ModelAdmin):
fields = ["name", "is_title", "x_0", "y_0"]
list_display = ["name", "is_title", "x_0", "y_0"]
fields = ["name", "is_title", "x_0", "y_0", "link"]
list_display = ["name", "is_title", "x_0", "y_0", "link"]


@admin.register(CourseGuideAdjacencyList)
class CourseGuideAdjacencyListAdmin(admin.ModelAdmin):
fields = ["source", "targets"]
list_display = ["source"]
filter_horizontal = ["targets"]
fields = ["source", "target", "type"]
list_display = ["source", "type"]
filter_horizontal = ["target"]
list_filter = ["type"]


@admin.register(CourseGuideGroup)
class CourseGuideGroupAdmin(admin.ModelAdmin):
list_display = ["name"]
filter_horizontal = ["nodes"]


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.16 on 2024-12-04 02:31

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("studentservices", "0010_auto_20220421_0027"),
]

operations = [
migrations.AddField(
model_name="courseguideadjacencylist",
name="recommended",
field=models.ManyToManyField(
related_name="adjacency_list_recommended",
to="studentservices.courseguidenode",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.16 on 2024-12-04 02:33

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("studentservices", "0011_courseguideadjacencylist_recommended"),
]

operations = [
migrations.RenameField(
model_name="courseguideadjacencylist",
old_name="targets",
new_name="required",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.16 on 2024-12-05 03:56

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("studentservices", "0012_rename_targets_courseguideadjacencylist_required"),
]

operations = [
migrations.RenameField(
model_name="courseguideadjacencylist",
old_name="required",
new_name="target",
),
migrations.RemoveField(
model_name="courseguideadjacencylist",
name="recommended",
),
migrations.AddField(
model_name="courseguideadjacencylist",
name="type",
field=models.CharField(
choices=[("requried", "Required"), ("recommended", "Recommended")],
default="Required",
max_length=20,
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.16 on 2024-12-07 01:02

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"studentservices",
"0013_rename_required_courseguideadjacencylist_target_and_more",
),
]

operations = [
migrations.RemoveField(
model_name="courseguideadjacencylist",
name="type",
),
migrations.AddField(
model_name="courseguideadjacencylist",
name="recommended",
field=models.ManyToManyField(
related_name="adjacency_list_recommended",
to="studentservices.courseguidenode",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.16 on 2024-12-07 01:39

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("studentservices", "0014_remove_courseguideadjacencylist_type_and_more"),
]

operations = [
migrations.RemoveField(
model_name="courseguideadjacencylist",
name="recommended",
),
migrations.AddField(
model_name="courseguideadjacencylist",
name="type",
field=models.CharField(
choices=[("required", "Required"), ("recommended", "Recommended")],
default="Required",
max_length=20,
),
),
]
20 changes: 20 additions & 0 deletions hknweb/studentservices/migrations/0016_courseguidenode_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.16 on 2024-12-07 02:38

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"studentservices",
"0015_remove_courseguideadjacencylist_recommended_and_more",
),
]

operations = [
migrations.AddField(
model_name="courseguidenode",
name="link",
field=models.CharField(blank=True, max_length=255),
),
]
15 changes: 11 additions & 4 deletions hknweb/studentservices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CourseGuideNode(models.Model):
is_title = models.BooleanField(default=False)
x_0 = models.IntegerField(blank=True, null=True)
y_0 = models.IntegerField(blank=True, null=True)
link = models.CharField(max_length=MAX_STRLEN, blank=True)

def __str__(self):
return self.name
Expand All @@ -58,14 +59,20 @@ class CourseGuideAdjacencyList(models.Model):
source = models.ForeignKey(
CourseGuideNode, models.CASCADE, related_name="adjacency_list_source"
)
targets = models.ManyToManyField(
target = models.ManyToManyField(
CourseGuideNode, related_name="adjacency_list_target"
)


type = models.CharField(
max_length=20,
choices=[('required', 'Required'), ('recommended', 'Recommended')],
default='Required'
)

def __str__(self):
source = str(self.source)
targets = ", ".join(str(t) for t in self.targets.all())
return f"{source}: [{targets}]"
target = ", ".join(str(t) for t in self.target.all())
return f"{source}: [{target}]"


class CourseGuideGroup(models.Model):
Expand Down
39 changes: 27 additions & 12 deletions hknweb/studentservices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,37 @@ def course_guide_data(request):

graph = dict()
for adjacency_list in CourseGuideAdjacencyList.objects.all():

if adjacency_list.source.name not in node_groups:
continue

graph[adjacency_list.source.name] = [
node.name
for node in adjacency_list.targets.all()
if node.name in node_groups
]

course_surveys_link = reverse("course_surveys:index")
link_template = f"{course_surveys_link}?search_by=courses&search_value="
if adjacency_list.source.name in graph:
graph[adjacency_list.source.name].extend([
(node.name, adjacency_list.type)
for node in adjacency_list.target.all()
if node.name in node_groups

])
else:
graph[adjacency_list.source.name] = [
(node.name, adjacency_list.type)
for node in adjacency_list.target.all()
if node.name in node_groups
]



# ORIGINAL LINK SETUP
# course_surveys_link = reverse("course_surveys:index")
# link_template = f"{course_surveys_link}?search_by=courses&search_value="
nodes = []
for n in CourseGuideNode.objects.all():
if n.name not in node_groups:
continue

node_attrs = {
"id": n.name,
"link": link_template + n.name,
#"link": link_template + n.name,
"link" : n.link,
"title": n.is_title,
"group": node_groups[n.name],
"fx": n.x_0,
Expand All @@ -160,12 +172,15 @@ def course_guide_data(request):
links.append(
{
"source": s,
"target": e,
"target": e[0],
"source_group": node_groups[s],
"target_group": node_groups[e],
"target_group": node_groups[e[0]],
"type": e[1],
}
)



data = {
"nodes": nodes,
"links": links,
Expand Down
17 changes: 15 additions & 2 deletions hknweb/templates/studentservices/course_guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
{% for group in groups %}
<input type="checkbox" id="{{ group }}" {% if group in request.GET.groups %} checked {% endif %} onclick="action('{{ group }}')"> {{ group }}
{% endfor %}

</div>

<h2 style="text-align: center;">
Expand All @@ -77,6 +78,7 @@ <h2 style="text-align: center;">
</h2>

<div style="width: 100%; overflow: scroll;">
<!-- Originally 2000 by 1200 -->
<svg class="graph" width="2000" height="1200"></svg>
</div>

Expand All @@ -98,14 +100,25 @@ <h2 style="text-align: center;">
function renderd3(groups) {
d3.json("{% url 'studentservices:course_guide_data' %}?groups=" + groups, function(error, graph) {
if (error) throw error;
console.log(graph);

var link = svg
.append("g")
.attr("class", "links")
.selectAll("line")
.data(graph.links)
.enter().append("line")
.attr("stroke-width", 2);
.attr("stroke-width", 2)
.attr("stroke-dasharray", function(d) {
return d.type == "recommended" ? "4, 4" : "none";

})
.attr("stroke", function(d) {
return d.type == "required" ? "gray" : "none";

});



var node = svg
.append("g")
Expand Down Expand Up @@ -189,7 +202,7 @@ <h2 style="text-align: center;">

var labels = node
.append("a")
.attr("xlink:href", function (d) { return d.link; })
.attr("xlink:href", function (d) { return d.link})
.attr("target", "_blank")
.append("text")
.text(function(d) { return d.id; })
Expand Down
Loading