Commits

jaux  committed ccd2c6d

Add 'Nice Name' to upload form.

File list would display nice name as well if possible.

  • Participants
  • Parent commits 61d0e8b

Comments (0)

Files changed (12)

     author_email='jaux@mowak.net',
     url='http://bitbucket.org/jaux/skypieamc/',
     install_requires=[
-        "Pylons>=0.9.7,<=0.9.7.99",
+        "Pylons>=0.9.7",
         "SQLAlchemy>=0.5,<=0.5.99",
     ],
     setup_requires=["PasteScript>=1.6.3"],

File skypieamc/config/routing.py

 
     map.connect('login', '/login', controller='account', action='login')
     map.connect('logout', '/logout', controller='account', action='logout')
+    map.connect('admin', '/admin', controller='account', action='admin')
     map.connect('/{controller}/{action}')
     map.connect('/{controller}/{action}/{id}')
     map.connect('root', '/', controller='file', action='list');

File skypieamc/controllers/account.py

         session.save()
         redirect(h.url('root'))
 
-    def list(self, id=None):
+    def admin(self, id=None):
         if not request.environ.get('REMOTE_USER'):
             if request.query_string:
                 session['referer'] = \
             page=request.params.get('page', 1),
             items_per_page=10,
             controller='account',
-            action='list'
+            action='admin'
         )
         c.tags = meta.Session.query(model.Tag).all()
-        return render('/derived/account/list.mako')
+        return render('/derived/account/admin.mako')

File skypieamc/controllers/file.py

         not_empty=True,
         messages={'empty': u'Please specify a file to upload.'}
     )
+    nice_name = String()
     tags = TagsConverter(create_if_not_exist=True);
 
 class SearchForm(Schema):
         mfile.name = ifile.filename
         mfile.safename = safename
         mfile.size = os.stat(pfile_path).st_size
+        if form_result['nice_name']:
+            mfile.nicename = form_result['nice_name']
         if form_result['tags']:
             mfile.tags = form_result['tags']
         meta.Session.add(mfile)
         mfile = id and meta.Session.query(model.File).get(id)
         if mfile is None:
             abort(404, u'File not found')
+        # Clear file system
+        dir = app_globals.upload_dir
+        try:
+            os.remove(os.path.join(dir, mfile.safename))
+            if mfile.playable:
+                os.remove(os.path.join(dir, mfile.playable))
+        except (IOError, OSError) as why:
+            log.info('Cannot clear file {0} | {1} | {2}'.\
+                format(mfile.name, mfile.safename, mfile.playable))
+        # Clear db
         meta.Session.execute(delete(model.file_tag_table,
                                     model.file_tag_table.c.fileid == id))
         meta.Session.delete(mfile)
         meta.Session.commit()
+
         session['flash_msg'] = u'"{0}" has been deleted!'.format(mfile.name)
         session.save()
-        return redirect(h.url(controller='account', action='list'))
+        return redirect(h.url('admin'))

File skypieamc/model/__init__.py

                   schema.Sequence('file_id_seq', optional=True),
                   primary_key=True),
     schema.Column('name', types.Unicode(255), nullable=False),
+    schema.Column('nicename', types.Unicode(255)),
     schema.Column('safename', types.String(127), nullable=False),
     schema.Column('size', types.Integer(), nullable=False),
     schema.Column('uploaded', types.DateTime(), default=h.now),

File skypieamc/public/css/upload.css

 #file-uploader dt {
-  width: 45px;
+  width: 85px;
+}
+
+#file-uploader dd input.file_meta {
+  width: 172px;
+  height: 18px;
+  margin-right: 1px;
 }
 
 #file-uploader #tags {
   float: left;
-  width: 172px;
-  height: 18px;
-  margin-right: 1px;
 }
 
 #file-uploader label {
 }
 
 #file-uploader #btn_submit {
+  font-weight: bold;
+  font-size: 108%;
   width: 82px;
+  height: 45px;
+  position: relative;
+  top: -22px;
 }
 
 #status {

File skypieamc/templates/base.mako

         <p>
           %if session.has_key('user'):
             Hi, ${h.link_to(session['user'],
-                            h.url(controller='account', action='list'))}
+                            h.url(controller='account', action='admin'))}
             | ${h.link_to('Logout', h.url('logout'))}
           %else:
             ${h.link_to('Login', h.url('login'))}
 
 <%def name="flash_message()">
   %if session.has_key('flash_msg'):
-    <div id="flash-msg"><p>${session['flash_msg'].encode('utf-8')}</p></div>
+    <div id="flash-msg"><p>${session['flash_msg']}</p></div>
     <%
       del session['flash_msg']
       session.save()

File skypieamc/templates/component/file/file_list.mako

+<%def name="create(actions, addon_content)">
+  %if len(c.paginator):
+    <table id="file-list">
+      <% count = 0 %>
+      %for f in c.paginator:
+        <tr id="${f.id}" class="${'odd' if count % 2 else 'even'}">
+          <td class="file-info">${self.file_info(f)}</td>
+          ${actions(f)}
+        </tr>
+        ${addon_content(f)}
+        <% count += 1 %>
+      %endfor
+    </table>
+    <div id="pager">
+      ${c.paginator.pager('$link_previous ~3~ $link_next')}
+    </div>
+  %else:
+    <p>No files have been uploaded yet,
+       ${h.link_to('add one',
+                   h.url(controller='file', action='upload'))}?</p>
+  %endif
+</%def>
+
+<%def name="file_info(mfile)">
+  <%
+    fname = mfile.nicename or mfile.name
+  %>
+  <dl>
+    <dt>${h.link_to(fname,
+                    h.url(controller='file',
+                          action='download',
+                          id=mfile.id),
+                    title=mfile.name)}</dt>
+    <dd>
+      <span class="mime-icon">${self.mime_icon(mfile.name)}</span>
+      Uploaded: ${mfile.uploaded.strftime('%Y/%m/%d')}
+      | Size: ${h.readable_filesize(mfile.size)}
+      | ${mfile.download_count} Downloads
+      %if len(mfile.tags) > 0:
+        <%
+          mfile.tags.sort(
+            lambda t1, t2: cmp(t1.file_count, t2.file_count),
+            reverse=True
+          )
+        %>
+        | <div class="tags"><span class="text">
+          %for tag in mfile.tags[:3]:
+            ${h.link_to(
+                tag.name,
+                h.url(controller='file', action='search', id=tag.id)
+              )}
+          %endfor
+        </span></div>
+      %endif
+    </dd>
+  </dl>
+</%def>
+
+<%def name="mime_icon(fname)">
+  ${h.image(h.url('/images/icon_{0}.png'.format(h.file_type(fname))), None)}
+</%def>

File skypieamc/templates/derived/account/admin.mako

+<%inherit file="/base.mako" />
+<%namespace name="file_list" file="/component/file/file_list.mako"
+            import="create" />
+
+<%def name="css()">
+  ${parent.css()}
+  ${h.stylesheet_link(h.url('/css/list.css'))}
+</%def>
+
+${file_list.create(self.actions, self.addon_content)}
+
+<%def name="actions(mfile)">
+  <td class="button">
+    <a class="btn_edit"
+       href="${h.url(controller='file', action='edit', id=mfile.id)}">
+      <span class="text">Edit</span>
+    </a>
+  </td>
+  <td class="button">
+    <a class="btn_delete"
+       href="${h.url(controller='file', action='delete', id=mfile.id)}">
+      <span class="text">Delete</span>
+    </a>
+  </td>
+</%def>
+
+<%def name="addon_content(mfile)"></%def>
+
+<%def name="sidebar()"></%def>

File skypieamc/templates/derived/account/list.mako

-<%inherit file="/derived/file/list.mako" />
-
-<%def name="actions(mfile)">
-  <td class="button">
-    <a class="btn_edit"
-       href="${h.url(controller='file', action='edit', id=mfile.id)}">
-      <span class="text">Edit</span>
-    </a>
-  </td>
-  <td class="button">
-    <a class="btn_delete"
-       href="${h.url(controller='file', action='delete', id=mfile.id)}">
-      <span class="text">Delete</span>
-    </a>
-  </td>
-</%def>
-
-<%def name="addon_content(mfile)"></%def>

File skypieamc/templates/derived/file/list.mako

 <%inherit file="/base.mako" />
+<%namespace name="file_list" file="/component/file/file_list.mako"
+            import="create" />
 
 <%def name="css()">
   ${parent.css()}
                       h.url('/js/list.js'))}
 </%def>
 
-%if len(c.paginator):
-  <table id="file-list">
-    <% count = 0 %>
-    %for f in c.paginator:
-      <tr id="${f.id}" class="${'odd' if count % 2 else 'even'}">
-        <td class="file-info">${self.file_info(f)}</td>
-        ${self.actions(f)}
-      </tr>
-      ${self.addon_content(f)}
-      <% count += 1 %>
-    %endfor
-  </table>
-  <div id="pager">
-    ${c.paginator.pager('$link_previous ~3~ $link_next')}
-  </div>
-%else:
-  <p>No files have been uploaded yet,
-     ${h.link_to('add one',
-                 h.url(controller='file', action='upload'))}?</p>
-%endif
+${file_list.create(self.actions, self.addon_content)}
 
-<%def name="file_info(mfile)">
-  <% fname = mfile.name.encode('utf-8') %>
-  <dl>
-    <dt>${fname}</dt>
-    <dd>
-      <span class="mime-icon">${self.mime_icon(mfile.name)}</span>
-      Uploaded: ${mfile.uploaded.strftime('%Y/%m/%d')}
-      | Size: ${h.readable_filesize(mfile.size)}
-      | ${mfile.download_count} Downloads
-      %if len(mfile.tags) > 0:
-        <%
-          mfile.tags.sort(
-            lambda t1, t2: cmp(t1.file_count, t2.file_count),
-            reverse=True
-          )
-        %>
-        | <div class="tags"><span class="text">
-          %for tag in mfile.tags[:3]:
-            ${h.link_to(
-                tag.name.encode('utf-8'),
-                h.url(controller='file', action='search', id=tag.id)
-              )}
-          %endfor
-        </span></div>
-      %endif
-    </dd>
-  </dl>
-</%def>
-
-<%def name="mime_icon(fname)">
-  ${h.image(h.url('/images/icon_{0}.png'.format(h.file_type(fname))), None)}
-</%def>
 <%def name="actions(mfile)">
   <td class="button">
     %if mfile.playable is not None:
     <tr id="player_container-${mfile.id}" class="player-container hidden">
       <td colspan="3">
         ${h.link_to(
-            mfile.name.encode('utf-8'), 
+            mfile.name,
             h.url(controller='file',
-                      action='download',
-                      id=mfile.id,
-                      playable='true'),
+                  action='download',
+                  id=mfile.id,
+                  playable='true'),
             id='player-{0}'.format(mfile.id))}
       </td>
     </tr>
               font_size = 'median'
           %>
           ${h.link_to(
-              tag.name.encode('utf-8'),
+              tag.name,
               h.url(controller='file', action='search', id=tag.id),
               class_=font_size
             )}

File skypieamc/templates/derived/file/upload.mako

     method='post', multipart=True, id='file-uploader'
   )}
   <dl>
-    <dt><label for="upload_file">File:</label></dt>
+    <dt><label for="upload_file">Select File:</label></dt>
     <dd>${h.file('upload_file')}</dd>
+    <dt><label for="nice_name">Nice Name:</label></dt>
+    <dd>${h.text('nice_name', class_='file_meta')}</dd>
     <dt><label for="tags">Tags:</label></dt>
-    <dd>${h.text('tags')}</dd>
+    <dd>${h.text('tags', class_='file_meta')}</dd>
   </dl>
   ${h.submit('btn_submit', value='Upload')}
 ${h.end_form()}
     <h2>Tips:</h2>
     <ol>
       <li>
+        <p>"Nice Name" and "Tags" are optional</p>
+      </li>
+      <li>
         <p>Separate tags by commas or spaces</p>
       </li>
       <li>