Mercurial > hg > agora
changeset 184:b711f0087709
Use DESCRIPTION file for bundles (SCHEMA CHANGE)
* Added two new fields to the Bundle model:
* octave_format, which allows users to specify if their bundle has
been formatted according to octave packaging standards or not
* description_file, which points to a file named DESCRIPTION in
the root directory (or the next top-level directory), if the
octave_format checkbox is ticked and if one exists
* Fixed the uploader field for form by making it a hidden input and
preventing hidden inputs from showing up entirely
author | dellsystem <ilostwaldo@gmail.com> |
---|---|
date | Sat, 27 Oct 2012 15:58:08 -0400 |
parents | cdcbfaa65cfe |
children | 5abda22e4637 |
files | apps/bundle/forms.py apps/bundle/models.py apps/bundle/tasks.py static/css/agora.less templates/bundle/bundle.djhtml templates/bundle/form.djhtml |
diffstat | 6 files changed, 44 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/apps/bundle/forms.py +++ b/apps/bundle/forms.py @@ -8,6 +8,12 @@ model = Bundle fields = ('uploader', 'name', 'description', 'free_license', 'octave_format') + widgets = { + # Ideally, the uploader field should just not show up at all + # Not really possible if we want to validate the name + # This is the next best option (hidden fields just aren't shown) + 'uploader': forms.HiddenInput, + } file = forms.FileField(help_text=("Upload a plain text file or an \ archive file."))
--- a/apps/bundle/models.py +++ b/apps/bundle/models.py @@ -22,7 +22,12 @@ "Acceptable characters: alphanumeric characters, hyphens, and " + "underscores.")) uploader = models.ForeignKey(User) - description = models.TextField(max_length=32728, blank=True, null=True) + description = models.TextField(blank=True, null=True) + octave_format = models.BooleanField('Is the bundle formatted according' + ' to Octave package manager standards?', default=False) + # If octave_format is true and there is a DESCRIPTION file in the root + description_file = models.ForeignKey('BundleFile', blank=True, null=True, + related_name="described") free_license = models.ForeignKey(FreeLicense, default=1) pub_date = models.DateTimeField('date uploaded', auto_now_add=True) mod_date = models.DateTimeField('date last modified', auto_now=True)
--- a/apps/bundle/tasks.py +++ b/apps/bundle/tasks.py @@ -26,8 +26,6 @@ dir_contents = [os.path.join(dir_name, f) for f in os.listdir(dir_name)] dirs = filter(os.path.isdir, dir_contents) files = filter(os.path.isfile, dir_contents) - print "Directories: %s" % ", ".join(dirs) - print "Files: %s" % ", ".join(files) for file_path in sorted(dirs) + sorted(files): filename = os.path.basename(file_path) @@ -37,6 +35,7 @@ version=bundle.latest_version) if file_path in files: + is_desc = False bundle_file.is_dir = False bundle_file.file_size = os.path.getsize(file_path) @@ -47,6 +46,16 @@ # Store the contents of the file in the code field bundle_file.save_file_contents(file) + # DESCRIPTION file should be at most 1 level deep + single_parent = (parent_dir is not None or + '/' not in parent_dir) + is_desc = single_parent and filename == 'DESCRIPTION' + + # Check if this is the description file (if no description exists) + if bundle.octave_format and bundle.description == '' and is_desc: + bundle.description_file = bundle_file + bundle.save() + bundle_file.save() else: # It's a directory - call this function on it recursively
--- a/static/css/agora.less +++ b/static/css/agora.less @@ -398,7 +398,7 @@ #bundle-file { padding: 0 20px; - margin-left: 220px; + margin-left: 230px; h2 { padding-top: 0; @@ -420,3 +420,8 @@ .form-field { margin-bottom: 10px; } + +.bundle-description { + white-space: pre-wrap; + .hint; +}
--- a/templates/bundle/bundle.djhtml +++ b/templates/bundle/bundle.djhtml @@ -74,9 +74,21 @@ <p><a href="#">Download file (feature not yet available)</a></p> {% endif %} {% else %} - <p><strong>Description:</strong> {{ bundle.description|default:"N/A" }}</p> + <h2>Description</h2> + {% if bundle.description %} + <p>{{ bundle.description }}</p> + {% else %} + {% if bundle.description_file %} + <p class="bundle-description">{{ bundle.description_file.code|safe }}</p> + {% else %} + <p>N/A</p> + {% endif %} + {% endif %} + + {% if bundle.description %} <p><strong>License:</strong> {{ bundle.free_license }}</p> <p><strong>Latest version number:</strong> {{ bundle.latest_version }}</p> + {% endif %} {% if previous_versions %} <h3>Versions</h3> <ul>