Browse Source

Some CSS/layout updates

Getty Ritter 1 year ago
parent
commit
2e853be578
9 changed files with 124 additions and 12 deletions
  1. 10 1
      lc/app.py
  2. 6 1
      lc/model.py
  3. 3 1
      lc/request.py
  4. 65 0
      lc/static/main.css
  5. 8 1
      scripts/populate.py
  6. 5 5
      templates/add_link.mustache
  7. 14 3
      templates/login.mustache
  8. 7 0
      templates/main.mustache
  9. 6 0
      templates/message.mustache

+ 10 - 1
lc/app.py

@@ -15,7 +15,16 @@ app = c.app
 @endpoint("/")
 class Index(Endpoint):
     def html(self):
-        return render("main", title="main", content="whoo", user=self.user)
+        return render(
+            "main",
+            title="main",
+            content=render(
+                "message",
+                title="Lament Configuration",
+                message="Bookmark organizing for real pinheads.",
+            ),
+            user=self.user,
+        )
 
 
 @endpoint("/auth")

+ 6 - 1
lc/model.py

@@ -25,6 +25,7 @@ class User(Model):
 
     name = peewee.TextField(unique=True)
     passhash = peewee.TextField()
+    is_admin = peewee.BooleanField(default=False)
 
     @staticmethod
     def from_request(user: r.User) -> "User":
@@ -37,6 +38,10 @@ class User(Model):
     def authenticate(self, password: str) -> bool:
         return pwd.verify(password, self.passhash)
 
+    def set_as_admin(self):
+        self.is_admin = True
+        self.save()
+
     @staticmethod
     def login(user: r.User) -> "User":
         u = User.by_slug(user.name)
@@ -92,7 +97,7 @@ class Link(Model):
             name=link.name,
             description=link.description,
             private=link.private,
-            created=datetime.datetime.now(),
+            created=link.created or datetime.datetime.now(),
             user=user,
         )
         for tag_name in link.tags:

+ 3 - 1
lc/request.py

@@ -1,6 +1,7 @@
 from dataclasses import dataclass
 from dataclasses_json import dataclass_json
-from typing import List
+from datetime import datetime
+from typing import List, Optional
 
 
 @dataclass_json
@@ -22,6 +23,7 @@ class Link:
     description: str
     private: bool
     tags: List[str]
+    created: Optional[datetime] = None
 
     @classmethod
     def from_form(cls, form):

+ 65 - 0
lc/static/main.css

@@ -15,6 +15,13 @@ body {
     padding: 0em 1em;
 }
 
+.addlink {
+    padding: 0em 1em;
+}
+.login {
+    padding: 0em 1em;
+}
+
 .user a {
     text-decoration: none;
 }
@@ -63,6 +70,18 @@ a {
     border-bottom: solid black;
     padding: 0.2em 2em;
     margin: 0em 1em;
+    justify-content: space-between;
+}
+
+.header .left {
+    align-items: center;
+    display: flex;
+}
+
+.header .right {
+    align-items: center;
+    display: flex;
+    justify-content: flex-end;
 }
 
 .logo {
@@ -81,3 +100,49 @@ a {
     color: #000;
     text-decoration: none;
 }
+
+.loginform {
+    padding: 2em;
+    display: flex;
+    justify-content: center;
+}
+
+label {
+    display: inline-block;
+    width: 6em;
+    text-align: right;
+    padding-right: 0.6em;
+}
+
+input[type="text"] {
+    width: 40em;
+}
+
+input[type="password"] {
+    width: 40em;
+}
+
+input[type="submit"] {
+    width: 10em;
+}
+
+form > div {
+    padding: 0.2em;
+}
+
+.submit {
+    text-align: center;
+}
+
+.msgpage {
+    padding: 4em;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+}
+
+.msgpage h1 {
+    font-family: league-spartan;
+    text-transform: uppercase;
+    letter-spacing: 0.2em;
+}

+ 8 - 1
scripts/populate.py

@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
 
+import datetime
 import json
 
 import lc.config
@@ -13,17 +14,23 @@ def main():
 
     u = m.User.get_or_none(name="gdritter")
     if not u:
-        u = m.User.from_request(r.User(name="gdritter", password="behest",))
+        u = m.User.from_request(r.User(
+            name="gdritter",
+            password="behest",
+        ))
+        u.set_as_admin()
 
     with open("scripts/aisamanra.json") as f:
         links = json.load(f)
     for l in links:
+        time = datetime.datetime.strptime(l["time"], "%Y-%m-%dT%H:%M:%SZ")
         req = r.Link(
             url=l["href"],
             name=l["description"],
             description=l["extended"],
             private=l["shared"] == "yes",
             tags=l["tags"].split(),
+            created=time,
         )
         print(m.Link.from_request(u, req))
 

+ 5 - 5
templates/add_link.mustache

@@ -1,24 +1,24 @@
 <div class="loginform">
   <form name="login" method="POST">
     <div class="url">
-      <input name="url" type="text" />
       <label for="url">URL</label>
+      <input name="url" type="text" />
     </div>
     <div class="name">
-      <input name="name" type="text" />
       <label for="name">Link Name</label>
+      <input name="name" type="text" />
     </div>
     <div class="description">
-      <input name="description" type="text" />
       <label for="description">Description</label>
+      <input name="description" type="text" />
     </div>
     <div class="private">
-      <input name=private" type="checkbox"/>
       <label for="private">Private?</label>
+      <input name=private" type="checkbox"/>
     </div>
     <div class="tags">
-      <input name="tags" type="text" />
       <label for="tags">Tags</label>
+      <input name="tags" type="text" />
     </div>
 
     <div class="submit">

+ 14 - 3
templates/login.mustache

@@ -1,7 +1,18 @@
 <div class="loginform">
   <form name="login" method="POST">
-    <div class="user"><input name="username" type="text" /></div>
-    <div class="password"><input name="password" type="password" /></div>
-    <div class="submit"><input type="submit" value="Login" /></div>
+
+    <div class="userform">
+      <label for="username">User</label>
+      <input name="username" type="text" />
+    </div>
+
+    <div class="password">
+      <label for="password">Password</label>
+      <input name="password" type="password" />
+    </div>
+
+    <div class="submit">
+      <input type="submit" value="Login" />
+    </div>
   </form>
 </div>

+ 7 - 0
templates/main.mustache

@@ -8,6 +8,7 @@
   </head>
   <body>
     <div class="header">
+      <div class="left">
       <span class="logo">
         <a href="/"><img src="/static/lc_32.png" alt="Lament Configuration" /></a></span>
       <span class="sitename"><a href="/">Lament Configuration</a></span>
@@ -17,6 +18,11 @@
       {{^user}}
         <span class="user">not logged in</span>
       {{/user}}
+      </div>
+      <div class="right">
+        <div class="srclink">
+          <a href="https://git.infinitenegativeutility.com/getty/lament-configuration">source</a>
+        </div>
       {{#user}}
         <div class="addlink">
           <a href="/u/{{name}}/l">add link</a>
@@ -30,6 +36,7 @@
           <a href="/login">log in</a>
         </div>
       {{/user}}
+      </div>
     </div>
     <div class="content">
       {{{ content }}}

+ 6 - 0
templates/message.mustache

@@ -0,0 +1,6 @@
+<div class="msgpage">
+  <div class="message">
+    <h1>{{title}}</h1>
+    <p>{{message}}</p>
+  </div>
+</div>