~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/browser/archivesubscription.py

  • Committer: Curtis Hovey
  • Date: 2011-05-27 21:53:34 UTC
  • mto: This revision was merged to the branch mainline in revision 13136.
  • Revision ID: curtis.hovey@canonical.com-20110527215334-jqlkmt52nnl4bpeh
Moved launchpad.event into registry interfaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
from lp.registry.interfaces.person import IPersonSet
48
48
from lp.services.fields import PersonChoice
49
49
from lp.services.propertycache import cachedproperty
50
 
from lp.soyuz.browser.sourceslist import SourcesListEntriesWidget
 
50
from lp.soyuz.browser.sourceslist import (
 
51
    SourcesListEntries,
 
52
    SourcesListEntriesView,
 
53
    )
51
54
from lp.soyuz.interfaces.archive import IArchiveSet
 
55
from lp.soyuz.interfaces.archiveauthtoken import IArchiveAuthTokenSet
52
56
from lp.soyuz.interfaces.archivesubscriber import (
53
57
    IArchiveSubscriberSet,
54
58
    IPersonalArchiveSubscription,
152
156
    def subscriptions(self):
153
157
        """Return all the subscriptions for this archive."""
154
158
        result = list(getUtility(IArchiveSubscriberSet
155
 
            ).getByArchive(self.context))
 
159
            ).getByArchive( self.context))
156
160
        ids = set(map(attrgetter('subscriber_id'), result))
157
161
        list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(ids,
158
162
            need_validity=True))
333
337
        return personal_subscription_tokens
334
338
 
335
339
 
336
 
class PersonArchiveSubscriptionView(LaunchpadView, SourcesListEntriesWidget):
 
340
class PersonArchiveSubscriptionView(LaunchpadView):
337
341
    """Display a user's archive subscription and relevant info.
338
342
 
339
343
    This includes the current sources.list entries (if the subscription
349
353
    def initialize(self):
350
354
        """Process any posted actions."""
351
355
        super(PersonArchiveSubscriptionView, self).initialize()
352
 
        # Set the archive attribute so SourcesListEntriesWidget can be built
353
 
        # correctly.
354
 
        self.archive = self.context.archive
355
356
 
356
357
        # If an activation was requested and there isn't a currently
357
 
        # active token, then create a token, provide a notification
 
358
        # active token, then create a token, provided a notification
358
359
        # and redirect.
359
360
        if self.request.form.get('activate') and not self.active_token:
360
361
            self.context.archive.newAuthToken(self.context.subscriber)
376
377
                "\"sources.list\"." % self.context.archive.displayname)
377
378
 
378
379
            self.request.response.redirect(self.request.getURL())
 
380
 
 
381
    @cachedproperty
 
382
    def sources_list_entries(self):
 
383
        """Setup and return the sources list entries widget."""
 
384
        if self.active_token is None:
 
385
            return None
 
386
 
 
387
        comment = "Personal access of %s to %s" % (
 
388
            self.context.subscriber.displayname,
 
389
            self.context.archive.displayname)
 
390
 
 
391
        entries = SourcesListEntries(
 
392
            self.context.archive.distribution,
 
393
            self.active_token.archive_url,
 
394
            self.context.archive.series_with_sources)
 
395
 
 
396
        return SourcesListEntriesView(entries, self.request, comment=comment)
 
397
 
 
398
    @cachedproperty
 
399
    def active_token(self):
 
400
        """Returns the corresponding current token for this subscription."""
 
401
        token_set = getUtility(IArchiveAuthTokenSet)
 
402
        return token_set.getActiveTokenForArchiveAndPerson(
 
403
            self.context.archive, self.context.subscriber)