Contact page should be new

This commit is contained in:
Zergling_man 2021-12-12 21:52:02 +11:00
parent e80bbc2329
commit 34085a3882
3 changed files with 19 additions and 13 deletions

View File

@ -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)
admin.site.register(Update)

View File

@ -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)

View File

@ -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"<a href='{link}'>{name}</a>"
if note: name=f"{name} ({note})"
return f"<li>{proto}: {name}</li>"
def lii(obj):
name=obj.name
if obj.url: name=f"<a href='{obj.url}'>{name}</a>"
if obj.comment: name=f"{name} ({obj.comment})"
return f"<li>{obj.proto}: {name}</li>"
@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<br/>"
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<p><h4>{k}</h4>\n<ul>"
out2+='\n'.join([lii(*l) for l in v])
out2=f"\n<p><h4>{Contact.groups[k]}</h4>\n<ul>"
out2+='\n'.join(map(lii,v))
out2+="\n</ul></p>"
out3+=out2
return {'title':'Contact','content':head+out3,'date':Updates.objects.get(page='contact').date}
return {'title':'Contact','content':head+out3,'date':Update.objects.get(page='contact').date}
def specs(req):
with open('main/pages/specs') as b: