all repos — comments @ 6607ea6d0de103d6b4cf98abcd81699f1ec92595

django app for embedding comment threads in a static site via iframes

ext.py (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# comments/ext.py
# (c) 2020 Derek Stevens <nilix@nilfm.cc>

# this is a helper script to initialize comment threads externally
# move this to the project directory and change the settings imports accordingly

import sys
from django.conf import settings
import nilfm.settings as nilfm_settings

settings.configure(INSTALLED_APPS=nilfm_settings.INSTALLED_APPS, DATABASES=nilfm_settings.DATABASES)

import django
django.setup()

from comments.models import Comment, Thread

def echo(*args):
  threads = Thread.objects.all();
  for t in threads:
    print(t)
    c = t.root_comment
    print(c)
    if c:
      c = c.next
      print(c)

def create(id):
  x = Thread(thread_id=id, )
  x.save()

def postTo(**kwargs):
  id = kwargs["id"]
  name = kwargs["name"]
  mail = kwargs["mail"]
  data = kwargs["data"]
  t = Thread.objects.get(pk=id)
  current = t.root_comment
  if current:
    while current:
      current = current.next
  current = Comment(comment_author=name, comment_author_email=mail, comment_data=data)
  current.save()

options = {
	"echo": echo,
	"create": create,
	"postTo": postTo
	}

options[sys.argv[1]](sys.argv[2:])