From 34085a3882e0dd61734125cb91733f50b1f740a7 Mon Sep 17 00:00:00 2001 From: Zergling_man Date: Sun, 12 Dec 2021 21:52:02 +1100 Subject: [PATCH] Contact page should be new --- main/admin.py | 4 ++-- main/models.py | 5 +++-- main/views.py | 23 ++++++++++++++--------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/main/admin.py b/main/admin.py index 001c531..3f7a7e4 100644 --- a/main/admin.py +++ b/main/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin # Register your models here. -from .models import Page,Contact,Updates +from .models import Page,Contact,Update admin.site.register(Page) admin.site.register(Contact) -admin.site.register(Updates) \ No newline at end of file +admin.site.register(Update) \ No newline at end of file diff --git a/main/models.py b/main/models.py index a6fea18..b16d250 100644 --- a/main/models.py +++ b/main/models.py @@ -17,11 +17,12 @@ class Contact(models.Model): url=models.CharField(max_length=500,blank=True) proto=models.CharField(max_length=100) comment=models.CharField(max_length=100,blank=True) - group=models.IntegerField(choices=list({0:'Preferred',1:'Suitable',2:'Discouraged',3:'Ignored',4:'Discontinued',5:'NSFW'}.items())) + groups={0:'Preferred',1:'Suitable',2:'Discouraged',3:'Ignored',4:'Discontinued',5:'NSFW'} + group=models.IntegerField(choices=list(groups.items())) priority=models.IntegerField() def save(self,*args,**kwargs): - a,_=Updates.objects.get_or_create(page='contact') + a,_=Update.objects.get_or_create(page='contact') a.date=date.today() a.save() super().save(*args,**kwargs) diff --git a/main/views.py b/main/views.py index 3a630be..7cc70a3 100644 --- a/main/views.py +++ b/main/views.py @@ -4,7 +4,7 @@ from django.template import loader import random as ra import asyncio from . import mdl -from .models import Page,Contact,Updates +from .models import Page,Contact,Update import functools @@ -56,22 +56,27 @@ def index(): stuff=stuff.format(ra.choice(ids)) return {'title':'Home','content':stuff,'date':'2021/09/20'} -def lii(name,proto,link='',note=''): - if link: name=f"{name}" - if note: name=f"{name} ({note})" - return f"
  • {proto}: {name}
  • " +def lii(obj): + name=obj.name + if obj.url: name=f"{name}" + if obj.comment: name=f"{name} ({obj.comment})" + return f"
  • {obj.proto}: {name}
  • " @rerender def contact(): head="Certain people keep asking me about the best ways to contact me. So here they are, in rough order of most to least preferred. More to come as I remember them/feel like it
    " - out=parsecat('contacts',4) + contacts=sorted(models.Contact.objects.all(),key=lambda x:(x.group,x.priority)) + out={} + for n in contacts: + if n.group in out: out[n.group].append(n) + else: out[n.group]=[n] out3='' for k,v in out.items(): - out2=f"\n

    {k}

    \n