diff --git a/.gitignore b/.gitignore index 6a18ad4..53c49d0 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,7 @@ ENV/ # Rope project settings .ropeproject +# emacs +#*# +.#* +*~ diff --git a/linkstore/admin.py b/linkstore/admin.py index e9e3170..04248d0 100644 --- a/linkstore/admin.py +++ b/linkstore/admin.py @@ -1,5 +1,20 @@ from django.contrib import admin # Register your models here. -from .models import Link -admin.site.register(Link) \ No newline at end of file +from linkstore.models import Category, Link + + +class LinkInline(admin.TabularInline): + model = Link + extra = 4 + + +class CategoryAdmin(admin.ModelAdmin): + fieldset = [ + (None, {'fields': ['name']}), + ] + inlines = [LinkInline] + + +admin.site.register(Link) +admin.site.register(Category, CategoryAdmin) diff --git a/linkstore/migrations/0001_initial.py b/linkstore/migrations/0001_initial.py new file mode 100644 index 0000000..13af255 --- /dev/null +++ b/linkstore/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 2.1.7 on 2019-04-06 18:50 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Category', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=40)), + ], + ), + migrations.CreateModel( + name='Link', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('friendly_name', models.CharField(max_length=40)), + ('url', models.CharField(max_length=255)), + ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='linkstore.Category')), + ], + ), + ] diff --git a/linkstore/migrations/0002_auto_20190406_1546.py b/linkstore/migrations/0002_auto_20190406_1546.py new file mode 100644 index 0000000..0e13317 --- /dev/null +++ b/linkstore/migrations/0002_auto_20190406_1546.py @@ -0,0 +1,17 @@ +# Generated by Django 2.1.7 on 2019-04-06 20:46 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('linkstore', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='category', + options={'verbose_name_plural': 'categories'}, + ), + ] diff --git a/linkstore/migrations/__init__.py b/linkstore/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/linkstore/models.py b/linkstore/models.py index 78b0c67..f583e25 100644 --- a/linkstore/models.py +++ b/linkstore/models.py @@ -1,8 +1,22 @@ from django.db import models # Create your models here. + + +class Category(models.Model): + class Meta(object): + verbose_name_plural = "categories" + + name = models.CharField(max_length=40) + + def __str__(self): + return self.name + + class Link(models.Model): friendly_name = models.CharField(max_length=40) - url = models.CharField(max_length = 255) + url = models.CharField(max_length=255) + category = models.ForeignKey(Category, on_delete=models.CASCADE) + def __str__(self): - return self.url \ No newline at end of file + return self.url diff --git a/linkstore/static/linkstore/css/styles.css b/linkstore/static/linkstore/css/styles.css new file mode 100644 index 0000000..af5e0f5 --- /dev/null +++ b/linkstore/static/linkstore/css/styles.css @@ -0,0 +1,51 @@ +/* Style the button that is used to open and close the collapsible content */ +.collapsible { + background-color: #eee; + color: #444; + cursor: pointer; + padding: 18px; + width: 100%; + border: none; + text-align: left; + outline: none; + font-size: 15px; +} + +/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */ +.active, .collapsible:hover { + background-color: #ccc; +} +.collapsible:after { + content: '\02795'; /* Unicode character for "plus" sign (+) */ + font-size: 13px; + color: white; + float: right; + margin-left: 5px; +} +.active:after { + content: "\2796"; /* Unicode character for "minus" sign (-) */ +} +/* Style the collapsible content. Note: hidden by default */ +.content { + padding: 0 18px; + display: none; + overflow: hidden; + background-color: #f1f1f1; +} +ul.no_bullets { + list-style-type: none; +} +.collapsible-like { + background-color: #eee; + color: #444; + cursor: pointer; + padding: 18px; + width: 100%; + border: none; + text-align: left; + outline: none; + font-size: 15px; +} +.active, .collapsible-like:hover { + background-color: #ccc; +} diff --git a/linkstore/static/linkstore/js/collapse.js b/linkstore/static/linkstore/js/collapse.js new file mode 100644 index 0000000..d1b14df --- /dev/null +++ b/linkstore/static/linkstore/js/collapse.js @@ -0,0 +1,25 @@ +function set_interactive () { + var coll = document.getElementsByClassName("collapsible"); + var i; + + for (i = 0; i < coll.length; i++) { + coll[i].addEventListener("click", function() { + this.classList.toggle("active"); + var content = this.nextElementSibling; + if (content.style.display === "block") { + content.style.display = "none"; + } else { + content.style.display = "block"; + } + }); + } +} +function collapse_all () { + colls = document.getElementsByClassName("collapsible"); + for (i = 0; i < colls.length; i++) { + content = colls[i].nextElementSibling; + if (content.style.display === "block") { + content.style.display = "none"; + } + } +} diff --git a/linkstore/static/linkstore/styles.css b/linkstore/static/linkstore/styles.css deleted file mode 100644 index cc5a5f3..0000000 --- a/linkstore/static/linkstore/styles.css +++ /dev/null @@ -1,30 +0,0 @@ -.button { - /* margin: 25px 50px 75px 100px; */ - background-color: white; - color: black; - padding: 15px 32px; - font-size: 16px; - text-align: center; - border: 2px solid #4CAF50; /* Green */ - -webkit-transition-duration: 0.2s; /* Safari */ - transition-duration: 0.2s; - text-decoration: none; -} - -.button:hover { - background-color: #4CAF50; /* Green */ - color: white; -} - -li.button-div { - background: white; - margin-bottom: 50px; -} - -li.button-div:last-child { - margin-bottom: 0px; -} - -ul { - list-style-type: none; -} \ No newline at end of file diff --git a/linkstore/templates/linkstore/index.djhtml b/linkstore/templates/linkstore/index.djhtml new file mode 100644 index 0000000..7b5ea67 --- /dev/null +++ b/linkstore/templates/linkstore/index.djhtml @@ -0,0 +1,25 @@ + +{% load static %} + + + + + Landing + + +

Useful Links

+ + {% for category in categories %} + +
+ +
+ {% endfor %} + + diff --git a/linkstore/templates/linkstore/index.html b/linkstore/templates/linkstore/index.html deleted file mode 100644 index 659ec1e..0000000 --- a/linkstore/templates/linkstore/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - Useful links - {% load static %} - - - -

Useful Links

- {% if linklist %} - - {% else %} -

No links inputted

- {% endif %} - - \ No newline at end of file diff --git a/linkstore/urls.py b/linkstore/urls.py index 10b51ee..354308b 100644 --- a/linkstore/urls.py +++ b/linkstore/urls.py @@ -1,8 +1,8 @@ from django.urls import path -from . import views +from linkstore import views urlpatterns = [ path('', views.index, name='index'), # path('/static/*' -] \ No newline at end of file +] diff --git a/linkstore/views.py b/linkstore/views.py index 1155043..b3f62d3 100644 --- a/linkstore/views.py +++ b/linkstore/views.py @@ -1,9 +1,11 @@ from django.shortcuts import render from django.http import HttpResponse # Create your views here. -from .models import Link +from linkstore.models import Category + + def index(request): # return HttpResponse("links will show up here...") - linklist = Link.objects.all() - context = {'linklist':linklist} - return render(request,'linkstore/index.html',context) \ No newline at end of file + categories = Category.objects.all() + context = {'categories': categories} + return render(request, 'linkstore/index.djhtml', context) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d3e4ba5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +django diff --git a/setup.py b/setup.py index 8b13789..271b510 100644 --- a/setup.py +++ b/setup.py @@ -1 +1,14 @@ +from distutils.core import setup +with open('requirements.txt') as file: + INSTALL_REQUIRES = file.readlines() + +setup( + version='1.0', + name='linkstore', + description='Django app for collapsible link categories', + author='Raphael Roberts', + packages=['linkstore'], + author_email='raphael.roberts48@gmail.com', + install_requires=INSTALL_REQUIRES, +)