Skip to content
Snippets Groups Projects
Commit e229760b authored by jhyunsoo's avatar jhyunsoo
Browse files

Initial commit

parents
Branches master
No related tags found
No related merge requests found
Showing
with 101 additions and 0 deletions
File added
File added
File added
File added
File added
File added
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class ConceptMapConfig(AppConfig):
name = 'concept_map'
from django import forms
from .models import Node
class AddForm(forms.ModelForm):
class Meta:
model = Node
fields = ["text", "parent",]
labels = {"text": "Content", "parent": "ID of Parent Node",}
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2023-02-18 02:15
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='node',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.CharField(max_length=100)),
('parent', models.IntegerField(null=True)),
],
),
]
File added
File added
from django.db import models
class Node(models.Model):
text = models.CharField(max_length=100)
parent = models.IntegerField(null=True)
concept_map/static/concept_map/file.png

24.5 KiB

{% load static %}
<img src="{% static "concept_map/file.png" %}" alt="Mindmap"/>
<form method = "POST">
<fieldset>
<legend>Add Node</legend>
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">Add</button>
</fieldset>
</form>
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url
from concept_map import views
urlpatterns = [
url('', views.concept_map, name='concept_map'),
url(r'form', views.concept_map, name="form"),
]
from django.shortcuts import render
from concept_map.models import Node
import pygraphviz as pgv
from .forms import AddForm
def concept_map(request):
nodes = Node.objects.all()
if request.method == "POST":
form = AddForm(request.POST)
if form.is_valid():
text = request.POST.get("text")
parent = request.POST.get("parent")
if nodes.filter(id=parent).exists() or not parent:
node = Node(text=text, parent=parent)
node.save()
else:
form = AddForm()
G = pgv.AGraph()
G.graph_attr["overlap"] = "scalexy"
node_parent_list = []
for node in nodes:
if node.parent:
node_parent_list.append((node.id, node.parent))
G.add_node(node.id, label=node.text, xlabel=node.id)
for node in node_parent_list:
G.add_edge(node[0], node[1])
G.layout()
G.draw("concept_map/static/concept_map/file.png")
context = {
'form': form,
}
return render(request, 'concept_map.html', context)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment