Commits

Petr...@gmail.com  committed 0135e5a

Some small caching and start of look and feel

  • Participants
  • Parent commits 88d3307

Comments (0)

Files changed (4)

File gadmin-static/css/style.css

     height: 100%;
     padding: 0;
     margin: 0;
+    font-family: sans-serif;
 }
 
-#Content {
-    /*margin: 40px 20px 80px 20px;*/
-    padding: 40px;
-    border: 1px solid #efefef;
+ul, li, form {
+    padding: 0;
+    margin: 0;
+    border: 0;
 }
 
+.clear {
+    clear: both;
+}
+
+.left {
+    float: left;
+}
+
+.right {
+    float: right;
+}
+
+body {
+    background-color: #cfcfda;
+}
+
+#Everything {
+    padding: 0 20px;
+}
+
+#Header {
+    padding: 5px 0;
+}
+
+#Header .logout {
+    font-size: 8pt;
+}
+
+#Header .logout a {
+    display: block;
+    background-color: #000;
+    float: right;
+    color: #fff;
+    text-decoration: none;
+    padding: 4px 8px;
+    margin-top: -4px;
+    border-radius: 3pt;
+    -moz-border-radius: 3pt;
+}
+
+#Footer {
+    height: 7px;
+    background-color: #000;
+}
+
+/* Menu */
+#TopMenu {
+    list-style-type: none;
+}
+
+#TopMenu li {
+    border-top-left-radius: 5pt;
+    border-top-right-radius: 5pt;
+    -moz-border-radius-topleft: 5pt;
+    -moz-border-radius-topright: 5pt;
+    background-color: #000;
+    font-size: 10pt;
+    font-weight: bold;
+    padding: 4pt 9pt 0 9pt;
+    float: left;
+}
+
+#TopMenu li a {
+    color: #cfcfda;
+    text-decoration: none;
+}
+
+#TopMenu li.active {
+    background-color: #fff;
+    border-bottom: 4px solid #fff;
+    margin-bottom: -4px;
+}
+
+#TopMenu li.active a {
+    color: #000;
+}
+
+/* Content */
+#Content {
+    border-top: 4px solid #000;
+    padding: 10px 30px 40px 30px;
+    background-color: #fff;
+}
+
+/* Tree */
 #Tree {
     padding: 0;
     margin: 0;
     background-color: #000;
 }
 
+/* Forms */
 label {
     display: block
 }

File gadmin/models/gpage.py

 # TODO: check all posible 'more than 1000' cases
 # TODO: profile and cache get_*
 
+# Not sure about tree construction in
+# get_descendants, get_branch, get_all
+# It is possible that all these functions
+# just makes too many datastore calls
+#
+# Maybe (just maybe) it should fetch all
+# pages at the beginning, parse it,
+# construct tree and forget datastore
+
+def _caching(func):
+    """ Caching decorator (Only for request lifetime)
+
+        Chache key only depends on first arg
+    """
+    cache = {}
+    def newfunc(*args):
+        if not args: return func(*args)
+        key = getattr(args[0], 'key', lambda: str(args[0]))()
+        if not key in cache:
+            cache[key] = func(*args)
+        return cache[key]
+    return newfunc
+
 def _draft_filter(func):
+    """ Decorator prevents acsesing draft pages """
     def newfunc(*args, **kwargs):
         ret = func(*args, **kwargs)
 
         return [p for p in ret if not p.draft]
     return newfunc
 
+@_caching
 def get_root():
     root = GPage.all().filter('level =', 0).get()
     if root:
     return get_descendants(page)
 
 @_draft_filter
+@_caching
 def get_children(page):
     return GPage.all().filter('top =', page.key()).order('order')
 
 @_draft_filter
+@_caching
 def get_prev(page):
     return GPage.all() \
             .filter('top =', page.top.key()) \
             .filter('order =', page.order - 1)
 
 @_draft_filter
+@_caching
 def get_next(page):
     return GPage.all() \
             .filter('top =', page.top.key()) \
             .filter('order =', page.order + 1)
 
 @_draft_filter
+@_caching
 def get_by_slug(slug=''):
     if slug:
         return GPage.all().filter('slug =', slug).get()
     return get_root()
 
-
 def get_descendants(page, depth=-1):
     if depth == 0:
         return []
         pages += [c] + get_descendants(c, depth)
     return pages
 
+@_draft_filter
+@_caching
 def get_breadcrumb(page):
     tops = []
     top = page
         p.put()
     page.delete()
 
-#def change_type(page, new_type):
-    #if page.class_name == new_type:
-        #return
-
 def reorder(neworder):
     """
     neworder must be [(key, level), (key, level), ..]

File templates/gadmin/base.html

   <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <title>Gadmin » {% block gd_title %}{% endblock %}</title>
   <link rel="stylesheet" href="/gadmin-static/css/style.css" type="text/css" media="screen" charset="utf-8"></link>
-  <script type="text/javascript" charset="utf-8"
-    src="/gadmin-static/js/mootools-1.2.4-core.js"></script>
-  <script type="text/javascript" charset="utf-8"
-    src="/gadmin-static/js/mootools-1.2.4.2-more.js"></script>
+  {% block gd_head_js %}
+    <script type="text/javascript" charset="utf-8"
+      src="/gadmin-static/js/mootools-1.2.4-core.js"></script>
+    <script type="text/javascript" charset="utf-8"
+      src="/gadmin-static/js/mootools-1.2.4.2-more.js"></script>
+  {% endblock %}
   {% block gd_head %}{% endblock %}
 </head>
 <body>
-  <div id="Content">
-    {% block gd_content %}{% endblock %}
+  <div id="Everything">
+    <div id="Header">
+      <div class="logout right">
+        <a class="logout" href="#">Logout</a>
+        TODO: Nickname&nbsp;
+      </div>
+      {% block gd_header %}
+      {% endblock %}
+      <div class="clear"></div>
+    </div>
+    {% block gd_menu %}
+      <ul id="TopMenu">
+        <li class="{% block gd_menu_site_tree %}{% endblock %}">
+          <a href="{% url gadmin:index %}">Site Tree</a>
+        </li>
+        <li class="active">
+          <a href="#">Foo</a>
+        </li>
+        <li class="">
+          <a href="#">Bar</a>
+        </li>
+        {% block gd_menu_items %}{% endblock %}
+      </ul>
+      <div class="clear"></div>
+    {% endblock %}
+    <div id="Content">{% block gd_content %}{% endblock %}</div>
+    <div id="Footer">{% block gd_footer %}{% endblock %}</div>
   </div>
-  {% block gd_footer %}{% endblock %}
 </body>
 </html>
 

File templates/gsite/gpage.html

   <ul>{% gsite_list_menu 'top-menu' 3 %}</ul>
   {{ current.content|safe }}
   <img src="{{ current.picture }}" alt="Picture" />
+  <ul>{% gsite_list_menu 'top-menu' 3 %}</ul>
 {% endblock %}