Commit 764d3b48 authored by Thomas Mignot's avatar Thomas Mignot

DDP change message, including position. New publish queries.

parent c534e7be
......@@ -10,6 +10,29 @@ you first need to install:
then juste run ./manage.py runserver from the root directory of this project
for now, it's juste possible ton insert from the commad line in the ./manage.py shell
just the time to add some button ;)
What to do next?
Documentation for sure.
Plus a tutorial
Authentication:
- Without authentication and user specific filtering, it will remain a toy, a nice toy, but just a toy
- With authentication, publishing can filter output by user and that will be great!
- With authentication AND roles, it will become something really usable
Server Side Rendering:
- the first HTTP request should return a full HTML page
- all links should be 'a' tag that have no effect on current location
Automatic websocket reconnection and page reloading on success
Change the way methods works, maybe by importing a dict and assigning funcptr to method name
Errors handling: It won't ever be stable enough without good errors
Pagination: Very important too (maybe it could be implemented through subscriptions queries?)
Transcrypt would be nice to avoid switching to JS..
(S)CSS components?
- We could make scss-like class to be inherited in components? Seems like a good idea.
......@@ -25,7 +25,7 @@ SECRET_KEY = 'ti$t!2!q!c1b*^!zsldiys#&y-_gu1^mtpy$juoumc4*wk^o+_'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']
# Application definition
......
......@@ -7,5 +7,7 @@ class RyzomConfig(AppConfig):
def ready(self):
import ryzom.signals
from ryzom.pubsub import to_publish
Clients = self.get_model('Clients')
Clients.objects.all().delete()
for publication in to_publish:
publication.publish_all()
# Generated by Django 2.1.7 on 2019-03-08 14:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ryzom', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='publications',
name='name',
field=models.CharField(max_length=255, unique=True),
),
]
......@@ -44,18 +44,29 @@ class Subscriptions(models.Model):
send_insert(self, model_cls, tmpl_cls, _id)
def exec_query(self, model):
'''
limit, orderby, offset, fields(values), filter
'''
# such an ugly code!
# I really have to makes this clearer...and more robust!
# but it works for now
pub = self.publication
qs = model.objects.filter(**pub.query.get('filter', {}))
if 'order_by' in pub.query:
qs = qs.order_by(*pub.query.order_by)
if 'limit' in pub.query or 'offset' in pub.query:
limit = pub.query.get('limit')
offset = pub.query.get('offset', 0)
if limit:
qs = qs[offset:offset + limit]
else:
qs = qs[offset:]
qs = model.objects.all()
for q in pub.query:
for k, v in q.items():
if isinstance(v, list):
if v[0] == '$count':
v[0] = qs.count()
v = max(v[0] + v[1], 0)
elif v[0] == '$user':
v[0] = self.client.user.id
elif isinstance(v, dict):
for _k, _v in v.values():
if _v == '$user':
v[_k] = self.client.user.id
if k == 'filter':
qs = qs.filter(**v)
elif k == 'order_by':
qs = qs.order_by(v)
elif k == 'limit':
qs = qs[:v]
elif k == 'offset':
qs = qs[v:]
return qs
......@@ -3,15 +3,6 @@ from ryzom.models import Publications
to_publish = []
class Subscription():
def __init__(self, name, params):
pub = Publications.objects.get(name=name)
if pub:
self.name = name
self.params = params
self.publication = pub
class Publishable():
_published = False
_prepubs = {}
......@@ -31,14 +22,20 @@ class Publishable():
tmpl_mod = tmpl_mod[::-1]
tmpl_cls = tmpl_cls[::-1]
kwargs = {
'name': name,
'model_module': cls.__module__,
'model_class': cls.__name__,
'template_module': tmpl_mod,
'template_class': tmpl_cls,
'query': query
}
Publications.objects.update_or_create(**kwargs)
pub_exists = Publications.objects.filter(name=name).exists()
if pub_exists:
pub = Publications.objects.get(name=name)
for k, v in kwargs.items():
setattr(pub, k, v)
pub.save()
else:
Publications.objects.create(name=name, **kwargs)
@classmethod
def publish_all(cls):
......
......@@ -62,8 +62,9 @@
if (typeof(component.content) != 'string' && component.content.length) {
component.content.forEach(function(child) {
c = createDOMelement(child);
elem.appendChild(c);
var c = createDOMelement(child);
var prev = elem.childNodes[c.position]
elem.insertBefore(c, prev);
});
};
......@@ -92,21 +93,25 @@
data.forEach(function(component) {
var elem = createDOMelement(component);
getElementByUuid(component.parent).appendChild(elem);
var parent = getElementByUuid(component.parent)
var prev = parent.childNodes[component.position]
parent.insertBefore(elem, prev);
});
};
removeDOM = function(params) {
parentNode = getElementByUuid(params.parent);
node = getElementByUuid(params._id);
var parentNode = getElementByUuid(params.parent);
var node = getElementByUuid(params._id);
parentNode.removeChild(node);
};
changeDOM = function(params) {
prev_node = getElementByUuid(params._id);
cur_node = createDOMelement(params);
parent = getElementByUuid(params.parent);
parent.replaceChild(cur_node, prev_node);
var prev_node = getElementByUuid(params._id);
var cur_node = createDOMelement(params);
var parent = getElementByUuid(params.parent);
parent.removeChild(prev_node);
prev_node = parent.childNodes[params.position]
parent.insertBefore(cur_node, prev_node)
};
ws.onmessage = function(e) {
......
import json
from django.shortcuts import render
from ryzom.models import Clients
class View():
......@@ -28,7 +29,6 @@ class View():
def index(request, url=''):
print(json.dumps(request.GET))
return render(request, 'index.html', {
'url': url,
'query_string': request.GET.urlencode()
......
......@@ -11,5 +11,9 @@ class Tasks(models.Model, Publishable):
Tasks.publish(
name='tasks',
template='todos.components.tasks.Task',
query={'limit': 5}
query=[
{'order_by': 'about'},
{'offset': ('$count', -5)},
{'limit': 5},
]
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment