Exemple #1
0
def podcast_state_for_user_podcast(user, podcast):

    if not user:
        raise QueryParameterMissing('user')

    if not podcast:
        raise QueryParameterMissing('podcast')

    udb = get_userdata_database()

    p = get_single_result(udb, 'podcast_states/by_podcast',
                key          = [podcast.get_id(), user._id],
                limit        = 1,
                include_docs = True,
                schema       = PodcastUserState,
            )

    if not p:
        p = PodcastUserState()
        p.podcast = podcast.get_id()
        p.user = user._id
        p.ref_url = podcast.url
        p.settings[PUBLIC_SUB_PODCAST.name]=user.get_wksetting(PUBLIC_SUB_USER)

        p.set_device_state(user.devices)

    return p
Exemple #2
0
    def handle(self, *args, **options):

        docs = set()

        for username in options.get('users', []):
            user = User.get_user(username)

            # User
            docs.add(user._id)

            # Suggestions
            suggestions = Suggestions.for_user(user)
            docs.add(suggestions._id)

            # Podcast States
            for p_state in PodcastUserState.for_user(user):
                docs.add(p_state._id)

                # Categories
                for tag in p_state.tags:
                    c = Category.for_tag(tag)
                    if c: docs.add(c._id)

                # Podcast
                podcast = Podcast.get(p_state.podcast)
                docs.add(podcast._id)

                # Categories
                for s in podcast.tags:
                    for tag in podcast.tags[s]:
                        c = Category.for_tag(tag)
                        if c: docs.add(c._id)

                # Episodes
                for episode in podcast.get_episodes():
                    docs.add(episode._id)

                    # Episode States
                    e_state = episode.get_user_state(user)
                    if e_state._id:
                        docs.add(e_state._id)


        db = get_main_database()
        docs = sorted(docs)
        self.dump(docs, db)
Exemple #3
0
def delete_permanently(request, device):

    @repeat_on_conflict(['state'])
    def remove_device(state, dev):
        state.remove_device(dev)
        state.save()

    states = PodcastUserState.for_device(device.id)
    for state in states:
        remove_device(state=state, dev=device)

    @repeat_on_conflict(['user'])
    def _remove(user, device):
        user.remove_device(device)
        user.save()

    _remove(user=request.user, device=device)

    return HttpResponseRedirect(reverse('devices'))
Exemple #4
0
 def podcast_settings(user, url):
     podcast = Podcast.for_url(url)
     if not podcast:
         raise Http404
     obj = PodcastUserState.for_user_podcast(user, podcast)
     return obj, obj
Exemple #5
0
 def get_all_states(self):
     from mygpo.users.models import PodcastUserState
     return PodcastUserState.view('podcast_states/by_podcast',
         startkey = [self.get_id(), None],
         endkey   = [self.get_id(), {}],
         include_docs=True)
Exemple #6
0
 def get_user_state(self, user):
     from mygpo.users.models import PodcastUserState
     return PodcastUserState.for_user_podcast(user, self)