Browse Source

jeebus it finally works

master
phryk 1 year ago
parent
commit
0171026f5c
5 changed files with 53 additions and 33 deletions
  1. +1
    -0
      poobrains/__init__.py
  2. +0
    -1
      poobrains/form/__init__.py
  3. +4
    -28
      poobrains/md/__init__.py
  4. +47
    -3
      poobrains/svg/plot.py
  5. +1
    -1
      poobrains/themes/default/form/dataeditor.jinja

+ 1
- 0
poobrains/__init__.py View File

@@ -180,6 +180,7 @@ class Session(werkzeug.datastructures.CallbackDict, flask.sessions.SessionMixin)

def save(self):

import pudb; pudb.set_trace()
self.sessiondata.expires = datetime.datetime.utcnow() + app.permanent_session_lifetime
self.sessiondata.data = self.crypto.encrypt(pickle.dumps(dict(self), pickle.HIGHEST_PROTOCOL))



+ 0
- 1
poobrains/form/__init__.py View File

@@ -72,7 +72,6 @@ class BaseForm(poobrains.rendering.Renderable, metaclass=FormMeta):
if not callable(value):
value = copy.deepcopy(value)
elif propname in ('default', 'choices'):
app.debugger.set_trace()
value = value() # handle arguments to Fields that are optionally callable; ex: Checkbox(default=lambda: bool(random.randint(0,1)))
kw[propname] = value



+ 4
- 28
poobrains/md/__init__.py View File

@@ -30,12 +30,12 @@ def magic_markdown_loader(storable, handle):
return False


class MarkdownString(str):
class MarkdownString(collections.UserString):

def __init__(self, obj=''):
def __init__(self, seq=''):

self._name = None
super(MarkdownString, self).__init__()
super(MarkdownString, self).__init__(seq)


def __get__(self, instance, cls):
@@ -45,6 +45,7 @@ class MarkdownString(str):
else:
return instance.__dict__[self._name]


def __set__(self, instance, value):
instance.__dict__[self._name] = type(self)(value)

@@ -65,31 +66,6 @@ class MarkdownString(str):
return self.__add__(other)


def __getattribute__(self, name):

if name in dir(str):

attr = getattr(super(), name)

if callable(attr):

def func(*args, **kwargs):

r = attr(*args, **kwargs) # self doesn't need to be passed because attr is a bound function (hopefully)
if isinstance(r, str) and not isinstance(r, type(self)):
r = type(self)(r)

return r

return func
else:
return attr

else:
return super().__getattribute__(name)

def render(self, mode='inline'): # mode is ignored anyways
return jinja2.Markup(md.convert(self))



+ 47
- 3
poobrains/svg/plot.py View File

@@ -78,6 +78,7 @@ class Dataset(poobrains.auth.Protected):
def name(self):
return type(self).__name__.lower()


@property
def authorized_datapoints(self):
return self.datapoints
@@ -107,13 +108,54 @@ class Dataset(poobrains.auth.Protected):


def plot(self):
return Plot(datasets=[self]).render('inline')
return Plot(datasets=[self]).render('raw')


def fill(self, *args):
raise NotImplementedError("%s.fill not implemented" % type(self).__name__)


def to_dict(self):

d = {
'name': self.name,
'title': self.title,
'description': self.description,
'label_x': self.label_x,
'label_y': self.label_y
}

datapoints = []
for datapoint in self.authorized_datapoints:
datapoints.append({
'x': datapoint.x,
'y': datapoint.y,
'error_lower': datapoint.error_lower,
'error_upper': datapoint.error_upper
})

d['datapoints'] = datapoints

return d


@classmethod
def from_dict(cls, d):

kwargs = {
'title': d['title'],
'description': d['description'],
'label_x': d['label_x'],
'label_y': d['label_y']
}

ds = cls(**kwargs)
for datapoint in d['datapoints']:
ds.add_datapoint(datapoint['x'], datapoint['y'], error_lower=datapoint['error_lower'], error_upper=datapoint['error_upper'])

return ds


def save(self, name=None, owner=None):

"""
@@ -473,7 +515,8 @@ class DataEditor(poobrains.auth.ProtectedForm):
return redirect(type(self)(handle=new_editor_handle()).url('full'))

if self.handle_string in session:
self.data = session[self.handle_string]
self.data = Dataset.from_dict(session[self.handle_string])
#self.data = session[self.handle_string]

return poobrains.helpers.ThemedPassthrough(super(DataEditor, self).view(mode=mode, **kwargs))

@@ -483,6 +526,7 @@ class DataEditor(poobrains.auth.ProtectedForm):
if submit == 'load_dataset':
app.debugger.set_trace()
self.data = load_dataset(self.fields['dataset'].value)
session[self.handle_string] = self.data
session[self.handle_string] = self.data.to_dict()
#session[self.handle_string] = self.data

return self

+ 1
- 1
poobrains/themes/default/form/dataeditor.jinja View File

@@ -2,7 +2,7 @@

{% block pre %}
{% if content.data %}
{{ content.data }}
{{ content.data.plot() }}
{% endif %}
{% endblock %}



Loading…
Cancel
Save