Commits

Guido Draheim committed dfa7fc0

saven and update entry

Comments (0)

Files changed (5)

src/usernotes/notes_info.py

         session.flush()
         message = "modified field '%s' ('%s','%s') " % (note_field, note_typed, note_range)
         return self.do_fields(req, domain, message)
-    def do_search(self, req, domain):
+    def do_search(self, req, domain, message = None):
+        Item = collections.namedtuple("Item", ["note_user", "note_field", "note_string"])
         note_user = req.args.get("user", "")
         if not note_user:
             self.log.info("no 'user' on search")
         data["home_url"] = self.home_url(req, domain)
         data["note_user"] = note_user
         session = context(self.env)
-        q = session.query(NotesInfo)
+        q = session.query(NotesInfo.note_user, NotesInfo.note_field, NotesInfo.note_string)
         q = q.filter_by(note_user=note_user, note_domain=domain)
         q = q.order_by(desc(NotesInfo.modified_on))
-        datalist = []
+        fields = self.fields(domain)
+        values = {}
         for item in q.all():
-            datalist.append(item)
-        message = len(datalist)
-        data["datalist"] = datalist
-        data["fields"] = self.fields(domain)
+            elem = Item(*item)
+            values[elem.note_field] = item
+        for item in fields:
+            if item.note_field not in values:
+                values[elem.note_field] = Item(note_user, item.note_field, None)
+        if not message:
+            message = len(values)
         data["domains"] = self._domains(req)
+        data["fields"] = fields
+        data["values"] = values
+        data["empty"] = Item(None,None,None)
         data["title"] = TITLE
         data["domains"] = self._domains(req)
         data["message"] = message
         note_from = req.args.get("from", "")
         note_user = req.args.get("user", "")
         session = context(self.env)
+        updated = 0
         for arg in self.fields(domain):
             name = arg.note_field
             value = req.args.get("_%s" % name, None)
                 continue
             q = session.query(NotesInfo)
             q = q.filter_by(note_field = name, note_domain = domain, note_user = note_user)
-            updated = 0
             old = q.first()
             if old is None:
                 item = NotesInfo()
                 updated += 1
             if not old:
                 session.add(item)
-            message = u"updated"
-            return self.do_fields(req, domain, message)
+        message = u"updated"
+        return self.do_search(req, domain, message)
 

src/usernotes/templates/form_new_info.html

+<div class="create" xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:py="http://genshi.edgewall.org/"
+	xmlns:xi="http://www.w3.org/2001/XInclude">
+	<form method="post">
+		<table>
+			<tr>
+				<td colspan="2"><input type="hidden" name="op" value="save" />
+					<div>
+						<label for="from">FROM:</label> <input type="text" name="from"
+							value="${username}" />
+					</div>
+					<div>
+						<label for="user">USER:</label> <input type="text" name="user"
+							value="" />
+					</div></td>
+			</tr>
+			<tr py:for="item in fields">
+				<td><label for="${item.note_field}">${item.note_field}:</label>
+				</td>
+				<td><py:choose>
+						<py:when test="item.note_typed in ['select']">
+							<select name="_${item.note_field}">
+								<py:for each="option in item.note_range.split(',')">
+									<option>${option}</option>
+								</py:for>
+							</select>
+						</py:when>
+						<py:when test="item.note_typed in ['date']">
+							<input type="text" name="_${item.note_field}"
+								value="${format_datetime(None,'%Y-%m-%d %H:%M')}" size="30" />
+						</py:when>
+						<py:otherwise>
+							<input type="text" name="_${item.note_field}" value="" size="55" />
+						</py:otherwise>
+					</py:choose></td>
+			</tr>
+			<tr>
+				<td colspan="2"><input type="submit" value="SAVE NOTE" />
+				</td>
+			</tr>
+		</table>
+	</form>
+</div>

src/usernotes/templates/form_set_info.html

+<div class="create" xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:py="http://genshi.edgewall.org/"
+	xmlns:xi="http://www.w3.org/2001/XInclude">
+	<form method="post">
+		<table>
+			<tr>
+				<td colspan="2"><input type="hidden" name="op" value="save" />
+					<div>
+						<label for="user">USER:</label> <input type="text" name="user"
+							value="${note_user}" readonly="readonly"/>
+					</div></td>
+			</tr>
+			<tr py:for="item in fields">
+				<td><label for="${item.note_field}">${item.note_field}:</label>
+				</td>
+				<td><py:choose>
+						<py:when test="item.note_typed in ['select']">
+							<py:with
+								vars="value = values.get(item.note_field, empty).note_string">
+								<select name="_${item.note_field}">
+									<py:for each="option in item.note_range.split(',')">
+										<option selected="${(option == value or None)}">${option}</option>
+									</py:for>
+								</select>
+							</py:with>
+						</py:when>
+						<py:when test="item.note_typed in ['date']">
+							<py:with
+								vars="value = values.get(item.note_field, empty).note_string">
+								<input type="text" name="_${item.note_field}" value="${value}"
+									size="30" />
+							</py:with>
+						</py:when>
+						<py:otherwise>
+							<py:with
+								vars="value = values.get(item.note_field, empty).note_string">
+								<input type="text" name="_${item.note_field}" value="${value}"
+									size="55" />
+							</py:with>
+						</py:otherwise>
+					</py:choose></td>
+			</tr>
+			<tr>
+				<td colspan="2"><input type="submit" value="SAVE NOTE" />
+				</td>
+			</tr>
+		</table>
+	</form>
+</div>

src/usernotes/templates/notes_info_index.html

 		</table>
 		<div style="background-color: #DDD; padding: 1em">
 			<b>Neuer Eintrag:</b>
-			<form method="post">
-				<input type="hidden" name="op" value="save" />
-				<div>
-					<label for="from">FROM:</label> <input type="text" name="from"
-						value="${username}" />
-				</div>
-				<div>
-					<label for="user">USER:</label> <input type="text" name="user"
-						value="" />
-				</div>
-				<py:for each="item in fields">
-					<div>
-						<py:choose>
-							<py:when test="item.note_typed in ['select']">
-                                                                <label for="${item.note_field}">${item.note_field}:</label>
-                                                                <select name="_${item.note_field}">
-                                                                        <py:for each="value in item.note_range.split(',')">
-                                                                                <option>${value}</option>
-                                                                        </py:for>
-                                                                </select>
-							</py:when>
-                                                        <py:when test="item.note_typed in ['date']">
-                                                                <label for="${item.note_field}">${item.note_field}:</label>
-                                                                <input type="text" name="_${item.note_field}" value="${format_datetime(None,'%Y-%m-%d %H:%M')}" size="30" />
-                                                        </py:when>
-							<py:otherwise>
-								<label for="${item.note_field}">${item.note_field}:</label>
-								<input type="text" name="_${item.note_field}" value="" size="55" />
-							</py:otherwise>
-						</py:choose>
-					</div>
-				</py:for>
-				<input type="submit" value="SAVE NOTE" />
-			</form>
+			<xi:include href="form_new_info.html"></xi:include>
 		</div>
 	</div>
 </body>

src/usernotes/templates/notes_info_textlist.html

 	<div class="body">
 		${home_url}
 		<h3>SEARCH ${note_user}</h3>
-		<table class="resulttable">
-			<py:for each="item in datalist">
-				<tr valign="top">
-					<td><a
-						href="${base_url}?op=search&amp;user=${item.note_user}">${item.note_user}</a>
-					</td>
-					<td>
-					   ${item.note_field}
-					</td>
-					<td>
-                                           ${item.note_string}					
-					</td>
-				</tr>
-			</py:for>
-		</table>
+		<div><a href="${base_url}?op=search&amp;user=${note_user}">${note_user}</a></div>
+		<xi:include href="form_set_info.html"></xi:include>
 	</div>
 	<div class="summary">
-	   <span class="count">${len(datalist)}</span> entries
+		<span class="count">${len(values)}</span> entries
 	</div>
 </body>
 </html>