~launchpad-pqm/launchpad/devel

8687.15.17 by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
2068 by Canonical.com Patch Queue Manager
[r=SteveA/trivial] import fascism, kill translationeffort, kill sshkey browser code, add __all__s to interfaces, other cleanings-up
3
4
__metaclass__ = type
622 by Canonical.com Patch Queue Manager
productreleases can now be added through the web
5
2071 by Canonical.com Patch Queue Manager
[trivial] add more __all__ statements, other minor tidyings-up
6
__all__ = [
7107.1.5 by Guilherme Salgado
New UI for deleting product releases.
7
    'ProductReleaseAddDownloadFileView',
8
    'ProductReleaseAddView',
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
9
    'ProductReleaseFromSeriesAddView',
2548 by Canonical.com Patch Queue Manager
r=bjornt, plus some [trivial], lots of menus work, special error page for request timeouts.
10
    'ProductReleaseContextMenu',
7107.1.5 by Guilherme Salgado
New UI for deleting product releases.
11
    'ProductReleaseDeleteView',
2313 by Canonical.com Patch Queue Manager
[trivial] fix bug 1810.
12
    'ProductReleaseEditView',
7107.1.5 by Guilherme Salgado
New UI for deleting product releases.
13
    'ProductReleaseNavigation',
2071 by Canonical.com Patch Queue Manager
[trivial] add more __all__ statements, other minor tidyings-up
14
    'ProductReleaseRdfView',
5157.1.3 by Brad Crittenden
Added list of download files for a release on the release page.
15
    'ProductReleaseView',
2071 by Canonical.com Patch Queue Manager
[trivial] add more __all__ statements, other minor tidyings-up
16
    ]
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
17
7675.111.4 by Curtis Hovey
Changes per review.
18
import cgi
5258.3.3 by Brad Crittenden
Added digital signatures to download files.
19
import mimetypes
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
20
2287 by Canonical.com Patch Queue Manager
[r=spiv] make ProductRelease use auto-gen add and edit forms
21
from zope.event import notify
6061.13.2 by Curtis Hovey
Include zope.component in zopeapi.zcml.
22
from zope.lifecycleevent import ObjectCreatedEvent
7140.3.1 by Guilherme Salgado
Change ProductReleaseEditView to inherit from LaunchpadEditFormView
23
from zope.app.form.browser import TextAreaWidget, TextWidget
7849.16.48 by Sidnei da Silva
- Merge trunk
24
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
25
from zope.formlib.form import FormFields
26
from zope.schema import Bool
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
27
from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
1558 by Canonical.com Patch Queue Manager
revamp rosetta url schema, traversals and template listings
28
7849.16.4 by Sidnei da Silva
- Import ViewPageTemplateFile from z3c.pt everywhere
29
from z3c.ptcompat import ViewPageTemplateFile
1558 by Canonical.com Patch Queue Manager
revamp rosetta url schema, traversals and template listings
30
7675.110.3 by Curtis Hovey
Ran the migration script to move registry code to lp.registry.
31
from lp.registry.interfaces.productrelease import (
7709.3.3 by Curtis Hovey
Fixed old tests and added new tests to verify that productreleases can manage their version field.
32
    IProductRelease, IProductReleaseFileAddForm)
2287 by Canonical.com Patch Queue Manager
[r=spiv] make ProductRelease use auto-gen add and edit forms
33
7675.118.19 by Edwin Grubbs
Degrade "Create milestone" link in IE.
34
from lazr.restful.interface import copy_field
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
35
from canonical.launchpad import _
9346.1.5 by Brad Crittenden
Added smartquote to labels per UI review.
36
from canonical.lazr.utils import smartquote
7675.110.3 by Curtis Hovey
Ran the migration script to move registry code to lp.registry.
37
from lp.registry.browser.product import ProductDownloadFileMixin
2548 by Canonical.com Patch Queue Manager
r=bjornt, plus some [trivial], lots of menus work, special error page for request timeouts.
38
from canonical.launchpad.webapp import (
7140.3.1 by Guilherme Salgado
Change ProductReleaseEditView to inherit from LaunchpadEditFormView
39
    action, canonical_url, ContextMenu, custom_widget,
40
    enabled_with_permission, LaunchpadEditFormView, LaunchpadFormView,
41
    LaunchpadView, Link, Navigation, stepthrough)
7675.111.4 by Curtis Hovey
Changes per review.
42
from canonical.launchpad.webapp.menu import structured
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
43
from canonical.widgets import DateTimeWidget
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
44
8602.1.1 by Curtis Hovey
Extracted the milestoneoverlay javasscript, and refactored it to accept work with other use cases. Fixed a broken windmill tests -- it was broken a few weeks ago when the series page changed.
45
from lp.registry.browser import MilestoneOverlayMixin, RegistryDeleteViewMixin
8255.11.2 by Curtis Hovey
Product series owners and drivers can delete mis-created series.
46
5157.2.5 by Brad Crittenden
Review comments
47
4294.1.1 by Diogo Matsubara
Fix 117403 (Broken traversal on ProductRelease page)
48
class ProductReleaseNavigation(Navigation):
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
49
50
    usedfor = IProductRelease
51
52
    @stepthrough('+download')
53
    def download(self, name):
6916.3.8 by Brad Crittenden
Post-review changes
54
        return self.context.getFileAliasByName(name)
3348.1.33 by Mark Shuttleworth
Additional tests along with better registry pages.
55
6916.3.1 by Brad Crittenden
Initial export of IProductReleaseFile.
56
    @stepthrough('+file')
57
    def fileaccess(self, name):
6916.3.8 by Brad Crittenden
Post-review changes
58
        return self.context.getProductReleaseFileByName(name)
6916.3.1 by Brad Crittenden
Initial export of IProductReleaseFile.
59
4294.1.1 by Diogo Matsubara
Fix 117403 (Broken traversal on ProductRelease page)
60
2548 by Canonical.com Patch Queue Manager
r=bjornt, plus some [trivial], lots of menus work, special error page for request timeouts.
61
class ProductReleaseContextMenu(ContextMenu):
62
63
    usedfor = IProductRelease
9394.1.8 by Curtis Hovey
Removed unused and invalid links.
64
    links = ('edit', 'add_file', 'download', 'delete')
2548 by Canonical.com Patch Queue Manager
r=bjornt, plus some [trivial], lots of menus work, special error page for request timeouts.
65
3348.1.33 by Mark Shuttleworth
Additional tests along with better registry pages.
66
    @enabled_with_permission('launchpad.Edit')
2548 by Canonical.com Patch Queue Manager
r=bjornt, plus some [trivial], lots of menus work, special error page for request timeouts.
67
    def edit(self):
9394.1.11 by Curtis Hovey
Updated tests to verify new milestone and release behaviour.
68
        text = 'Change release details'
8408.1.5 by Curtis Hovey
Fixed the icon, alt, and summary of the delete milestone and release links.
69
        summary = "Edit this release"
70
        return Link('+edit', text, summary=summary, icon='edit')
2548 by Canonical.com Patch Queue Manager
r=bjornt, plus some [trivial], lots of menus work, special error page for request timeouts.
71
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
72
    @enabled_with_permission('launchpad.Edit')
9378.4.2 by Curtis Hovey
Add a draft of new features for the new milestone page.
73
    def delete(self):
9378.4.6 by Curtis Hovey
Updated tests to verify new milestone layout.
74
        text = 'Delete this release'
9378.4.2 by Curtis Hovey
Add a draft of new features for the new milestone page.
75
        summary = "Delete this release"
76
        return Link('+delete', text, summary=summary, icon='remove')
77
78
    @enabled_with_permission('launchpad.Edit')
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
79
    def add_file(self):
80
        text = 'Add download file'
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
81
        return Link('+adddownloadfile', text, icon='add')
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
82
2548 by Canonical.com Patch Queue Manager
r=bjornt, plus some [trivial], lots of menus work, special error page for request timeouts.
83
    def download(self):
3847.2.15 by Mark Shuttleworth
Consistency in menu text and capitalisation
84
        text = 'Download RDF metadata'
2548 by Canonical.com Patch Queue Manager
r=bjornt, plus some [trivial], lots of menus work, special error page for request timeouts.
85
        return Link('+rdf', text, icon='download')
2287 by Canonical.com Patch Queue Manager
[r=spiv] make ProductRelease use auto-gen add and edit forms
86
7276.2.1 by Edwin Grubbs
Mostly working.
87
7675.119.3 by Edwin Grubbs
Handled review comments and fixed test.
88
class ProductReleaseAddViewBase(LaunchpadFormView):
89
    """Base class for creating a release from an existing or new milestone.
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
90
7675.118.2 by Edwin Grubbs
Added dynamic addmilestone form to addrelease form from series.
91
    Subclasses need to define the field_names a form action.
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
92
    """
93
    schema = IProductRelease
94
95
    custom_widget('datereleased', DateTimeWidget)
96
    custom_widget('release_notes', TextAreaWidget, height=7, width=62)
97
    custom_widget('changelog', TextAreaWidget, height=7, width=62)
98
7675.118.11 by Edwin Grubbs
Turned list of releases into links. Added "Create Milestone" button on
99
    def _prependKeepMilestoneActiveField(self):
100
        keep_milestone_active_checkbox = FormFields(
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
101
            Bool(
102
                __name__='keep_milestone_active',
7675.118.12 by Edwin Grubbs
Merged in RF.
103
                title=_("Keep the %s milestone active." % self.context.name),
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
104
                description=_(
105
                    "Only select this if bugs or blueprints still need "
7675.118.12 by Edwin Grubbs
Merged in RF.
106
                    "to be targeted to this project release's milestone.")),
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
107
            render_context=self.render_context)
7675.118.11 by Edwin Grubbs
Turned list of releases into links. Added "Create Milestone" button on
108
        self.form_fields = keep_milestone_active_checkbox + self.form_fields
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
109
110
    def _createRelease(self, milestone, data):
111
        """Create product release for this milestone."""
112
        newrelease = milestone.createProductRelease(
113
            self.user, changelog=data['changelog'],
114
            release_notes=data['release_notes'],
115
            datereleased=data['datereleased'])
116
        # Set Milestone.active to false, since bugs & blueprints
117
        # should not be targeted to a milestone in the past.
7675.118.15 by Edwin Grubbs
Fixed issues from review.
118
        if data.get('keep_milestone_active') is False:
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
119
            milestone.active = False
7675.111.4 by Curtis Hovey
Changes per review.
120
            milestone_link = '<a href="%s">%s milestone</a>' % (
7675.118.12 by Edwin Grubbs
Merged in RF.
121
                canonical_url(milestone), cgi.escape(milestone.name))
7675.111.4 by Curtis Hovey
Changes per review.
122
            self.request.response.addWarningNotification(structured(
123
                _("The %s for this project release was deactivated "
7675.111.1 by Curtis Hovey
Updated the title, heading, extra-info, hints, and notifications for add release.
124
                  "so that bugs and blueprints cannot be associated with "
7675.111.4 by Curtis Hovey
Changes per review.
125
                  "this release." % milestone_link)))
7675.233.2 by Curtis Hovey
Added a release takes you to the release page so that you can add files.
126
        self.next_url = canonical_url(newrelease.milestone)
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
127
        notify(ObjectCreatedEvent(newrelease))
128
129
    @property
130
    def label(self):
131
        """The form label."""
9346.1.5 by Brad Crittenden
Added smartquote to labels per UI review.
132
        return smartquote('Create a new release for %s' %
133
                          self.context.product.displayname)
7675.111.1 by Curtis Hovey
Updated the title, heading, extra-info, hints, and notifications for add release.
134
9346.1.5 by Brad Crittenden
Added smartquote to labels per UI review.
135
    page_title = label
9322.9.1 by Brad Crittenden
Update productrelease views to UI 3.0. This version has one broken test.
136
137
    @property
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
138
    def cancel_url(self):
139
        return canonical_url(self.context)
140
141
7675.119.3 by Edwin Grubbs
Handled review comments and fixed test.
142
class ProductReleaseAddView(ProductReleaseAddViewBase):
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
143
    """Create a product release.
144
145
    Also, deactivate the milestone it is attached to.
146
    """
147
7709.3.3 by Curtis Hovey
Fixed old tests and added new tests to verify that productreleases can manage their version field.
148
    field_names = [
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
149
        'datereleased',
150
        'release_notes',
151
        'changelog',
152
        ]
153
154
    def initialize(self):
155
        if self.context.product_release is not None:
156
            self.request.response.addErrorNotification(
7675.118.12 by Edwin Grubbs
Merged in RF.
157
                _("A project release already exists for this milestone."))
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
158
            self.request.response.redirect(
159
                canonical_url(self.context.product_release) + '/+edit')
160
        else:
161
            super(ProductReleaseAddView, self).initialize()
162
163
    def setUpFields(self):
164
        super(ProductReleaseAddView, self).setUpFields()
165
        if self.context.active is True:
7675.118.11 by Edwin Grubbs
Turned list of releases into links. Added "Create Milestone" button on
166
            self._prependKeepMilestoneActiveField()
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
167
168
    @action(_('Create release'), name='create')
169
    def createRelease(self, action, data):
170
        self._createRelease(self.context, data)
171
172
8602.1.1 by Curtis Hovey
Extracted the milestoneoverlay javasscript, and refactored it to accept work with other use cases. Fixed a broken windmill tests -- it was broken a few weeks ago when the series page changed.
173
class ProductReleaseFromSeriesAddView(ProductReleaseAddViewBase,
174
                                      MilestoneOverlayMixin):
7675.118.15 by Edwin Grubbs
Fixed issues from review.
175
    """Create a product release from an existing or new milestone.
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
176
177
    Also, deactivate the milestone it is attached to.
178
    """
179
180
    field_names = [
181
        'datereleased',
182
        'release_notes',
183
        'changelog',
184
        ]
185
7675.118.2 by Edwin Grubbs
Added dynamic addmilestone form to addrelease form from series.
186
    def initialize(self):
187
        # The dynamically loaded milestone form needs this javascript
188
        # enabled in the main-template.pt.
189
        self.request.needs_datepicker_iframe = True
190
        super(ProductReleaseFromSeriesAddView, self).initialize()
191
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
192
    def setUpFields(self):
193
        super(ProductReleaseFromSeriesAddView, self).setUpFields()
7675.118.11 by Edwin Grubbs
Turned list of releases into links. Added "Create Milestone" button on
194
        self._prependKeepMilestoneActiveField()
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
195
        self._prependMilestoneField()
196
197
    def _prependMilestoneField(self):
198
        """Add Milestone Choice field with custom terms."""
199
        terms = [
7675.118.11 by Edwin Grubbs
Turned list of releases into links. Added "Create Milestone" button on
200
            SimpleTerm(milestone, milestone.name, milestone.name)
7675.118.1 by Edwin Grubbs
Working form for creating a product release off of the series.
201
            for milestone in self.context.all_milestones
202
            if milestone.product_release is None]
203
        terms.insert(0, SimpleTerm(None, None, '- Select Milestone -'))
204
        milestone_field = FormFields(
205
            copy_field(
206
                IProductRelease['milestone'],
207
                __name__='milestone_for_release',
208
                vocabulary=SimpleVocabulary(terms)))
209
        self.form_fields = milestone_field + self.form_fields
210
211
    @action(_('Create release'), name='create')
212
    def createRelease(self, action, data):
213
        milestone = data['milestone_for_release']
214
        self._createRelease(milestone, data)
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
215
2287 by Canonical.com Patch Queue Manager
[r=spiv] make ProductRelease use auto-gen add and edit forms
216
7140.3.1 by Guilherme Salgado
Change ProductReleaseEditView to inherit from LaunchpadEditFormView
217
class ProductReleaseEditView(LaunchpadEditFormView):
2315 by Canonical.com Patch Queue Manager
[trivial] fix docstring.
218
    """Edit view for ProductRelease objects"""
643 by Canonical.com Patch Queue Manager
productrelease now core-complete with add/edit/view
219
7140.3.1 by Guilherme Salgado
Change ProductReleaseEditView to inherit from LaunchpadEditFormView
220
    schema = IProductRelease
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
221
    field_names = [
7675.85.2 by Jonathan Lange
Undo revision generated by step 2 of process.
222
        "datereleased",
223
        "release_notes",
224
        "changelog",
225
        ]
226
227
    custom_widget('datereleased', DateTimeWidget)
228
    custom_widget('release_notes', TextAreaWidget, height=7, width=62)
229
    custom_widget('changelog', TextAreaWidget, height=7, width=62)
7276.2.25 by Edwin Grubbs
Add date_released and release_notes arguments to milestone.createProductRelease().
230
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
231
    @property
232
    def label(self):
233
        """The form label."""
9346.1.5 by Brad Crittenden
Added smartquote to labels per UI review.
234
        return smartquote('Edit %s release details' % self.context.title)
9322.9.1 by Brad Crittenden
Update productrelease views to UI 3.0. This version has one broken test.
235
9346.1.4 by Brad Crittenden
Changes from code review
236
    page_title = label
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
237
7140.3.1 by Guilherme Salgado
Change ProductReleaseEditView to inherit from LaunchpadEditFormView
238
    @action('Change', name='change')
239
    def change_action(self, action, data):
240
        self.updateContextFromData(data)
241
        self.next_url = canonical_url(self.context)
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
242
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
243
    @property
244
    def cancel_url(self):
245
        return canonical_url(self.context)
246
2005 by Canonical.com Patch Queue Manager
[r=spiv] HatcheryRDFPublishing
247
248
class ProductReleaseRdfView(object):
249
    """A view that sets its mime-type to application/rdf+xml"""
2276 by Canonical.com Patch Queue Manager
r=jamesh Fix Bug 1603: RDF fails when a name has unicode chars
250
251
    template = ViewPageTemplateFile('../templates/productrelease-rdf.pt')
252
2005 by Canonical.com Patch Queue Manager
[r=spiv] HatcheryRDFPublishing
253
    def __init__(self, context, request):
254
        self.context = context
255
        self.request = request
2276 by Canonical.com Patch Queue Manager
r=jamesh Fix Bug 1603: RDF fails when a name has unicode chars
256
257
    def __call__(self):
258
        """Render RDF output, and return it as a string encoded in UTF-8.
259
260
        Render the page template to produce RDF output.
261
        The return value is string data encoded in UTF-8.
262
263
        As a side-effect, HTTP headers are set for the mime type
264
        and filename for download."""
265
        self.request.response.setHeader('Content-Type', 'application/rdf+xml')
5258.1.1 by Brad Crittenden
Fixes bug 172915 by adding a 'Delete Files' button to the download files listing on the productrelease page. Refactored a lot of code.
266
        self.request.response.setHeader(
267
            'Content-Disposition',
268
            'attachment; filename=%s-%s-%s.rdf' % (
269
                self.context.product.name,
270
                self.context.productseries.name,
271
                self.context.version))
2276 by Canonical.com Patch Queue Manager
r=jamesh Fix Bug 1603: RDF fails when a name has unicode chars
272
        unicodedata = self.template()
273
        encodeddata = unicodedata.encode('utf-8')
274
        return encodeddata
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
275
4294.1.1 by Diogo Matsubara
Fix 117403 (Broken traversal on ProductRelease page)
276
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
277
class ProductReleaseAddDownloadFileView(LaunchpadFormView):
5258.3.6 by Brad Crittenden
changes from db review
278
    """A view for adding a file to an `IProductRelease`."""
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
279
    schema = IProductReleaseFileAddForm
280
281
    custom_widget('description', TextWidget, width=62)
282
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
283
    @property
284
    def label(self):
285
        """The form label."""
9346.1.5 by Brad Crittenden
Added smartquote to labels per UI review.
286
        return smartquote('Add a download file to %s' % self.context.title)
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
287
9346.1.4 by Brad Crittenden
Changes from code review
288
    page_title = label
9322.9.1 by Brad Crittenden
Update productrelease views to UI 3.0. This version has one broken test.
289
5258.3.3 by Brad Crittenden
Added digital signatures to download files.
290
    @action('Upload', name='add')
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
291
    def add_action(self, action, data):
5258.3.6 by Brad Crittenden
changes from db review
292
        form = self.request.form
293
        file_upload = form.get(self.widgets['filecontent'].name)
294
        signature_upload = form.get(self.widgets['signature'].name)
295
        filetype = data['contenttype']
5258.3.10 by Brad Crittenden
Cleanup to silence lint.
296
        # XXX: BradCrittenden 2007-04-26 bug=115215 Write a proper upload
297
        # widget.
6935.4.7 by Edwin Grubbs
Protected ProductRelease.addReleaseFile() and ProductReleaseFile.destroySelf()
298
        if file_upload is not None and len(data['description']) > 0:
6935.4.11 by Edwin Grubbs
Added XXX comment for bug 268680.
299
            # XXX Edwin Grubbs 2008-09-10 bug=268680
300
            # Once python-magic is available on the production servers,
301
            # the content-type should be verified instead of trusting
302
            # the extension that mimetypes.guess_type() examines.
6935.4.8 by Edwin Grubbs
Fixed lint errors
303
            content_type, encoding = mimetypes.guess_type(
304
                file_upload.filename)
6935.4.7 by Edwin Grubbs
Protected ProductRelease.addReleaseFile() and ProductReleaseFile.destroySelf()
305
306
            if content_type is None:
307
                content_type = "text/plain"
308
6974.2.1 by Edwin Grubbs
Exported IProductSeries.addRelease and fixed two errors.
309
            # signature_upload is u'' if no file is specified in
310
            # the browser.
311
            if signature_upload:
312
                signature_filename = signature_upload.filename
6935.7.8 by Brad Crittenden
Merge from Edwin's changes.
313
                signature_content = data['signature']
6974.2.1 by Edwin Grubbs
Exported IProductSeries.addRelease and fixed two errors.
314
            else:
6935.4.7 by Edwin Grubbs
Protected ProductRelease.addReleaseFile() and ProductReleaseFile.destroySelf()
315
                signature_filename = None
316
                signature_content = None
317
318
            release_file = self.context.addReleaseFile(
319
                filename=file_upload.filename,
6935.7.8 by Brad Crittenden
Merge from Edwin's changes.
320
                file_content=data['filecontent'],
6935.4.7 by Edwin Grubbs
Protected ProductRelease.addReleaseFile() and ProductReleaseFile.destroySelf()
321
                content_type=content_type,
6935.4.13 by Edwin Grubbs
Fixed tests.
322
                uploader=self.user,
6935.4.7 by Edwin Grubbs
Protected ProductRelease.addReleaseFile() and ProductReleaseFile.destroySelf()
323
                signature_filename=signature_filename,
324
                signature_content=signature_content,
325
                file_type=filetype,
326
                description=data['description'])
327
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
328
            self.request.response.addNotification(
6935.4.7 by Edwin Grubbs
Protected ProductRelease.addReleaseFile() and ProductReleaseFile.destroySelf()
329
                "Your file '%s' has been uploaded."
330
                % release_file.libraryfile.filename)
331
4195.1.1 by Brad Crittenden
Implement upload and management of files associated with a product release.
332
        self.next_url = canonical_url(self.context)
5157.1.3 by Brad Crittenden
Added list of download files for a release on the release page.
333
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
334
    @property
335
    def cancel_url(self):
336
        return canonical_url(self.context)
337
5157.1.3 by Brad Crittenden
Added list of download files for a release on the release page.
338
5258.1.1 by Brad Crittenden
Fixes bug 172915 by adding a 'Delete Files' button to the download files listing on the productrelease page. Refactored a lot of code.
339
class ProductReleaseView(LaunchpadView, ProductDownloadFileMixin):
5157.1.3 by Brad Crittenden
Added list of download files for a release on the release page.
340
    """View for ProductRelease overview."""
341
    __used_for__ = IProductRelease
342
5258.1.1 by Brad Crittenden
Fixes bug 172915 by adding a 'Delete Files' button to the download files listing on the productrelease page. Refactored a lot of code.
343
    def initialize(self):
344
        self.form = self.request.form
345
        self.processDeleteFiles()
346
347
    def getReleases(self):
348
        """See `ProductDownloadFileMixin`."""
349
        return set([self.context])
7107.1.5 by Guilherme Salgado
New UI for deleting product releases.
350
351
8255.11.2 by Curtis Hovey
Product series owners and drivers can delete mis-created series.
352
class ProductReleaseDeleteView(LaunchpadFormView, RegistryDeleteViewMixin):
7107.1.5 by Guilherme Salgado
New UI for deleting product releases.
353
    """A view for deleting an `IProductRelease`."""
354
    schema = IProductRelease
355
    field_names = []
356
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
357
    @property
358
    def label(self):
359
        """The form label."""
9346.1.5 by Brad Crittenden
Added smartquote to labels per UI review.
360
        return smartquote('Delete %s' % self.context.title)
9322.9.1 by Brad Crittenden
Update productrelease views to UI 3.0. This version has one broken test.
361
9346.1.4 by Brad Crittenden
Changes from code review
362
    page_title = label
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
363
364
    @action('Delete this Release', name='delete')
8255.11.2 by Curtis Hovey
Product series owners and drivers can delete mis-created series.
365
    def delete_action(self, action, data):
366
        series = self.context.productseries
367
        version = self.context.version
368
        self._deleteRelease(self.context)
7107.1.5 by Guilherme Salgado
New UI for deleting product releases.
369
        self.request.response.addInfoNotification(
8255.11.2 by Curtis Hovey
Product series owners and drivers can delete mis-created series.
370
            "Release %s deleted." % version)
371
        self.next_url = canonical_url(series)
7709.3.2 by Curtis Hovey
Deleting a release now deletes the files attached to a release too. Updated the
372
373
    @property
374
    def cancel_url(self):
375
        return canonical_url(self.context)