Browse Source

jeebus it finally works

master
phryk 7 months ago
parent
commit
0171026f5c

+ 1
- 0
poobrains/__init__.py View File

@@ -180,6 +180,7 @@ class Session(werkzeug.datastructures.CallbackDict, flask.sessions.SessionMixin)
180 180
 
181 181
     def save(self):
182 182
 
183
+        import pudb; pudb.set_trace()
183 184
         self.sessiondata.expires = datetime.datetime.utcnow() + app.permanent_session_lifetime
184 185
         self.sessiondata.data = self.crypto.encrypt(pickle.dumps(dict(self), pickle.HIGHEST_PROTOCOL))
185 186
 

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

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

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

@@ -30,12 +30,12 @@ def magic_markdown_loader(storable, handle):
30 30
     return False
31 31
 
32 32
 
33
-class MarkdownString(str):
33
+class MarkdownString(collections.UserString):
34 34
 
35
-    def __init__(self, obj=''):
35
+    def __init__(self, seq=''):
36 36
 
37 37
         self._name = None
38
-        super(MarkdownString, self).__init__()
38
+        super(MarkdownString, self).__init__(seq)
39 39
 
40 40
 
41 41
     def __get__(self, instance, cls):
@@ -45,6 +45,7 @@ class MarkdownString(str):
45 45
         else:
46 46
             return instance.__dict__[self._name]
47 47
 
48
+
48 49
     def __set__(self, instance, value):
49 50
         instance.__dict__[self._name] = type(self)(value)
50 51
 
@@ -65,31 +66,6 @@ class MarkdownString(str):
65 66
         return self.__add__(other)
66 67
 
67 68
 
68
-    def __getattribute__(self, name):
69
-
70
-        if name in dir(str):
71
-
72
-            attr = getattr(super(), name)
73
-
74
-            if callable(attr):
75
-
76
-                def func(*args, **kwargs):
77
-
78
-                    r = attr(*args, **kwargs) # self doesn't need to be passed because attr is a bound function (hopefully)
79
-                    if isinstance(r, str) and not isinstance(r, type(self)):
80
-                        r = type(self)(r)
81
-
82
-                    return r
83
-
84
-                return func
85
-            
86
-            else:
87
-                return attr
88
-
89
-        else:
90
-            return super().__getattribute__(name)
91
-                
92
-
93 69
     def render(self, mode='inline'): # mode is ignored anyways
94 70
         return jinja2.Markup(md.convert(self))
95 71
 

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

@@ -78,6 +78,7 @@ class Dataset(poobrains.auth.Protected):
78 78
     def name(self):
79 79
         return type(self).__name__.lower()
80 80
 
81
+
81 82
     @property
82 83
     def authorized_datapoints(self):
83 84
         return self.datapoints
@@ -107,13 +108,54 @@ class Dataset(poobrains.auth.Protected):
107 108
 
108 109
 
109 110
     def plot(self):
110
-        return Plot(datasets=[self]).render('inline')
111
+        return Plot(datasets=[self]).render('raw')
111 112
 
112 113
 
113 114
     def fill(self, *args):
114 115
         raise NotImplementedError("%s.fill not implemented" % type(self).__name__)
115 116
 
116 117
 
118
+    def to_dict(self):
119
+
120
+        d = {
121
+            'name': self.name,
122
+            'title': self.title,
123
+            'description': self.description,
124
+            'label_x': self.label_x,
125
+            'label_y': self.label_y
126
+        }
127
+
128
+        datapoints = []
129
+        for datapoint in self.authorized_datapoints:
130
+            datapoints.append({
131
+                'x': datapoint.x,
132
+                'y': datapoint.y,
133
+                'error_lower': datapoint.error_lower,
134
+                'error_upper': datapoint.error_upper
135
+            })
136
+
137
+        d['datapoints'] = datapoints
138
+
139
+        return d
140
+
141
+
142
+    @classmethod
143
+    def from_dict(cls, d):
144
+
145
+        kwargs = {
146
+            'title': d['title'],
147
+            'description': d['description'],
148
+            'label_x': d['label_x'],
149
+            'label_y': d['label_y']
150
+        }
151
+
152
+        ds = cls(**kwargs)
153
+        for datapoint in d['datapoints']:
154
+            ds.add_datapoint(datapoint['x'], datapoint['y'], error_lower=datapoint['error_lower'], error_upper=datapoint['error_upper'])
155
+
156
+        return ds
157
+
158
+
117 159
     def save(self, name=None, owner=None):
118 160
 
119 161
         """
@@ -473,7 +515,8 @@ class DataEditor(poobrains.auth.ProtectedForm):
473 515
             return redirect(type(self)(handle=new_editor_handle()).url('full'))
474 516
 
475 517
         if self.handle_string in session:
476
-            self.data = session[self.handle_string]
518
+            self.data = Dataset.from_dict(session[self.handle_string])
519
+            #self.data = session[self.handle_string]
477 520
 
478 521
         return poobrains.helpers.ThemedPassthrough(super(DataEditor, self).view(mode=mode, **kwargs))
479 522
 
@@ -483,6 +526,7 @@ class DataEditor(poobrains.auth.ProtectedForm):
483 526
         if submit == 'load_dataset':
484 527
             app.debugger.set_trace()
485 528
             self.data = load_dataset(self.fields['dataset'].value)
486
-            session[self.handle_string] = self.data
529
+            session[self.handle_string] = self.data.to_dict()
530
+            #session[self.handle_string] = self.data
487 531
 
488 532
         return self

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

@@ -2,7 +2,7 @@
2 2
 
3 3
 {% block pre %}
4 4
     {% if content.data %}
5
-        {{ content.data }}
5
+        {{ content.data.plot() }}
6 6
     {% endif %}
7 7
 {% endblock %}
8 8
 

Loading…
Cancel
Save