示例#1
0
    def post(self, request, slug):
        """ post request handles update from PictureForm """

        picture = get_object_or_404(models.Picture, slug__iexact=slug)
        playit = utility.object_path(picture)

        bound_form = self.form_class(request.POST,
                                     instance=picture,
                                     initial=query.my_preference_dict(
                                         picture, request.user))

        if 'UpdateObject' in request.POST:
            if bound_form.is_valid():
                new_picture = bound_form.save()
                picture.title = new_picture.title
                picture.year = new_picture.year

                #### this was not such a great idea -- too slow
                #                cast = bound_form.cleaned_data['cast']
                #                if len(cast):
                #                    #print('cast %s' % cast)
                #                    try:
                #                        message = u'success'
                #                        #print('view calls cast_picture')
                #                        chromecast.cast_picture(cast,picture)
                #                    except rutils.MyException as ex:
                #                        message = ex.message
                #                        #print('Caught %s' % ex.message)
                #########################################################
                # tag
                tq = bound_form.cleaned_data['tag']
                if len(tq):
                    tqSlug = slugify(str(tq))
                    new_tag = collection.add_tag(tq, tqSlug)
                    picture.tags.add(new_tag)

                pref = bound_form.cleaned_data['pref']
                # user selected a preference
                if len(pref):
                    query.handle_pref(picture, pref, request.user)

                picture.save()
                bound_form = self.form_class(instance=picture,
                                             initial=query.my_preference_dict(
                                                 picture, request.user))

                formContext = {
                    'picture': picture,
                    'playit': playit,
                    'objectForm': bound_form
                }
                return render(request, self.template_name, formContext)

        pictureContext = {
            'picture': picture,
            'playit': playit,
            'objectForm': bound_form
        }
        return render(request, self.template_name, pictureContext)
 def setUp(self):
     self.me = User.objects.create_user('tester', '*****@*****.**',
                                        'notreal')
     a = CollectionMixins()
     kind = choices.SONG
     xtag = collection.add_tag('christmas', 'christmas')
     _, _ = a.add_members('mp3s/Bruce_Cockburn', 2, kind, 'isa')
     xmas = Collection.objects.get(title__icontains='christmas')
     for s in xmas.songs.all():
         s.tags.add(xtag)
 def setUp(self):
     self.me = User.objects.create_user('tester', '*****@*****.**',
                                        'notreal')
     a = CollectionMixins()
     kind = choices.SONG
     xtag = collection.add_tag('christmas', 'christmas')
     _, _ = a.add_members('mp3s/Chris Isaak', 2, kind, 'isa')
     _, _ = a.add_members('mp3s/Blue_Rodeo', 2, kind, 'blu')
     _, _ = a.add_members('mp3s/Holly_Cole', 2, kind, 'goo')
     _, _ = a.add_members('mp3s/Dixie_Chicks', 2, kind, 'goo')
     xmas = Collection.objects.get(title__icontains='merrie')
     for s in xmas.songs.all():
         s.tags.add(xtag)
示例#4
0
    def post(self, request, slug):
        """
        Post handles updates from the SongForm
        as well as requests from kodi playback
        """
        song = get_object_or_404(models.Song, slug__iexact=slug)
        playit = utility.object_path(song)

        bound_form = self.form_class(request.POST, instance=song)
        if 'UpdateObject' in request.POST:
            if bound_form.is_valid():
                new_song = bound_form.save()
                song.title = new_song.title
                song.year = new_song.year

                # tag
                tq = bound_form.cleaned_data['tag']
                if len(tq):
                    tqSlug = slugify(str(tq))
                    new_tag = collection.add_tag(tq, tqSlug)
                    song.tags.add(new_tag)
                # new musician
                mus = bound_form.cleaned_data['musician']
                if len(mus):
                    mSlug = slugify(str(mus + '-mus'))
                    new_mus = collection.add_musician(mus, mSlug)
                    new_mus.songs.add(song)

                pref = bound_form.cleaned_data['pref']
                # user selected a preference
                if len(pref):
                    query.handle_pref(song, pref, request.user)

                song.save()
                bound_form = self.form_class(instance=song,
                                             initial=query.my_preference_dict(
                                                 song, request.user))
                formContext = {
                    'song': song,
                    'playit': playit,
                    'objectForm': bound_form
                }
                return render(request, self.template_name, formContext)
        _ = kodi.playback_requests(song, request)

        songContext = {
            'song': song,
            'playit': playit,
            'objectForm': bound_form
        }
        return render(request, self.template_name, songContext)
示例#5
0
 def setUp(self):
     self.me = User.objects.create_user('tester', '*****@*****.**',
                                        'notreal')
     a = CollectionMixins()
     kind = choices.SONG
     xtag = collection.add_tag('christmas', 'christmas')
     _, _ = a.add_members('mp3s/Chris Isaak', 2, kind, 'isa')
     _, _ = a.add_members('mp3s/Chris_Rea', 2, kind, 'rea')
     _, _ = a.add_members('mp3s/Good_Family', 2, kind, 'goo')
     _, _ = a.add_members('mp3s/Dixie_Chicks', 2, kind, 'goo')
     xmas = Collection.objects.get(title__icontains='christmas')
     for s in xmas.songs.all():
         s.tags.add(xtag)
     nosongq = Song.objects.filter(title__icontains='road')
     self.nosong = list(nosongq)
     for x in self.nosong:
         x.dislikes.add(self.me)
     self.assertFalse(len(self.nosong) == 0)
     self.mysong = []
def generic_collection_view(request, **kwargs):
    """
    Keep view details and playback requests in a single place
    so all collections view look the same and have the same options
    """

    if 'stopshow' in request.GET:
        slideshow = False
        return redirect(reverse('user_page'))

    template_name = 'FHLBuilder/collection_detail.html'
    slideshow = False

    # respond to playlist
    if 'playlist' in request.GET:
        asPlayList = True
    else:
        asPlayList = False

    # arguments and defaults
    songs = kwargs.get('songs', [])
    movies = kwargs.get('movies', [])
    pictures = kwargs.get('pictures', [])
    artists = kwargs.get('artists', [])
    title = kwargs.get('title', 'Collection View')
    allowChoice = kwargs.get('allowChoice', False)
    kind = kwargs.get('kind', choices.UNKNOWN)
    update = kwargs.get('update', None)
    sorder = kwargs.get('myorder', choices.NAME)

    allow_tag = True

    if kind == choices.SONG and not len(songs):
        # no tagging everything please
        allow_tag = False
        if sorder == choices.NEWEST:
            songs = models.Song.newest_objects.all()
        elif sorder == choices.OLDEST:
            songs = models.Song.oldest_objects.all()
        else:
            songs = models.Song.objects.all()

        title = ('All Songs %d' % songs.count())

    if sorder == choices.NEWEST:
        ob = '-date_added'
    elif sorder == choices.OLDEST:
        ob = 'date_added'
    else:
        ob = 'title'

    if kind in choices.videos and not len(movies):
        allow_tag = False
        # all movies view, can there be a faster option?
        olist, title = movies_bykind(kind)
        movies = olist.order_by(ob)

    # respond to slide show
    current_picture = 1
    picture = None
    filename = None

    picture_count = len(pictures)

    use_all = False
    if not picture_count and kind == choices.PICTURE:
        # all pictures view
        picture_count = models.Picture.slide_objects.all().count()
        use_all = True

    try:
        me = models.User.objects.get(username=request.user)
    except models.User.DoesNotExist:
        # anonymous user
        me = None
    except Exception as ex:
        utility.log("ERROR unhandled exception %s" % (type(ex).__name__))

    message = ''

    ccasts = []

    #print(request.GET)
    if 'options' in request.GET and not slideshow:
        ccasts = chromecast.find_chrome_casts()
        val = request.GET.get('options')
        if val == 'slideshow':
            slideshow = True
        elif val[:4] == 't___':
            dev = val[4:]
            chromecast.cast_slides(dev, pictures, me, True)
        elif val[:4] == 'cst_':
            dev = val[4:]
            chromecast.cast_slides(dev, pictures, me, False)
        elif val == 'CastAll-title':
            chromecast.cast_slides_all(pictures, me, True)
        elif val == 'CastAll':
            chromecast.cast_slides_all(pictures, me, False)
        else:
            # kodi playlist options
            try:
                res = kodi.playlist_requests_new(pictures, val, me, request)
                if res:
                    message = u'success - pictures sent'
            except rutils.MyException as ex:
                message = ex.message
                #print('Caught %s' % ex.message)

    if 'sNext' in request.GET and request.GET.get('sNext'):
        current_picture = int(request.GET.get('sNext'))
        slideshow = True
        current_picture = current_picture + 1
        if current_picture > picture_count:
            current_picture = 1
    if 'cNext' in request.GET and request.GET.get('cNext'):
        current_picture = int(request.GET.get('cNext'))
        current_picture = current_picture + 1
        if current_picture > picture_count:
            current_picture = 1
    elif 'cPrev' in request.GET and request.GET.get('cPrev'):
        current_picture = int(request.GET.get('cPrev'))
        if current_picture == 1:
            current_picture = picture_count
        else:
            current_picture = current_picture - 1

    if picture_count and not slideshow:
        ccasts = chromecast.find_chrome_casts()

    if use_all:
        # all pictures view
        allow_tag = False
        picture = models.Picture.slide_objects.all().order_by(
            ob)[current_picture]
        title = ('All Pictures %d' % picture_count)
        filename = utility.object_path(picture)
    elif picture_count:
        allow_tag = False
        picture = pictures[current_picture - 1]
        filename = utility.object_path(picture)

    # tags all objects
    if 'tq' in request.GET and request.GET['tq']:
        tq = request.GET['tq']
        tqSlug = slugify(str(tq))
        new_tag = collection.add_tag(tq, tqSlug)

        for obj in songs:
            obj.tags.add(new_tag)
        for obj in pictures:
            obj.tags.add(new_tag)
        for obj in movies:
            obj.tags.add(new_tag)

    # kodi playlist options
    try:
        if movies and kodi.playlist_requests(movies, request):
            message = u'success - movies sent'
        elif songs and kodi.playlist_requests(songs, request):
            message = u'success - songs sent'
        elif pictures and kodi.playlist_requests(pictures, request):
            message = u'success - pictures sent'

    except rutils.MyException as ex:
        message = ex.message
        print('Caught %s' % ex.message)

    context = {
        'title': title,
        'songlist': songs,
        'picture': picture,
        'pictureCount': picture_count,
        'filename': filename,
        'index': current_picture,
        'asPlayList': asPlayList,
        'movielist': movies,
        'update': update,
        'choices': choices.LIVE_CHOICES,
        'listkind': kind,
        'allowChoice': allowChoice,
        'artists': artists,
        'message': message,
        'allow_tag': allow_tag,
        'slideshow': slideshow,
        'ccasts': ccasts,
        'use_all': use_all
    }
    return render(request, template_name, context)
示例#7
0
    def post(self, request, slug):
        """
        post handles object update from the MovieForm
        """
        movie = get_object_or_404(models.Movie, slug__iexact=slug)

        #print ("MovieDetail POST for slug %s movie %s " % (slug,movie.title))
        playit = utility.object_path(movie)

        bound_form = self.form_class(request.POST,
                                     instance=movie,
                                     initial=query.my_preference_dict(
                                         movie, request.user))

        if 'UpdateObject' in request.POST:
            if bound_form.is_valid():
                new_movie = bound_form.save()
                movie.title = new_movie.title
                movie.year = new_movie.year

                # tag
                tq = bound_form.cleaned_data['tag']
                if len(tq):
                    tqSlug = slugify(str(tq))
                    new_tag = collection.add_tag(tq, tqSlug)
                    movie.tags.add(new_tag)
                # new actor
                act = bound_form.cleaned_data['actor']
                if len(act):
                    actSlug = slugify(str(act + '-act'))
                    new_actor = collection.add_actor(act, actSlug)
                    new_actor.movies.add(movie)
                # new director
                dtr = bound_form.cleaned_data['director']
                if len(dtr):
                    dtrSlug = slugify(str(dtr + '-dtr'))
                    new_dtr = collection.add_director(dtr, dtrSlug)
                    new_dtr.movies.add(movie)
                # new musician - for concerts
                mus = bound_form.cleaned_data['musician']
                if len(mus):
                    mSlug = slugify(str(mus + '-mus'))
                    new_mus = collection.add_musician(mus, mSlug)
                    new_mus.concerts.add(movie)

                pref = bound_form.cleaned_data['pref']
                # user selected a preference
                if len(pref):
                    query.handle_pref(movie, pref, request.user)

                movie.save()
                bound_form = self.form_class(instance=movie,
                                             initial=query.my_preference_dict(
                                                 movie, request.user))
                formContext = {
                    'movie': movie,
                    'playit': playit,
                    'objectForm': bound_form
                }
                return render(request, self.template_name, formContext)
        message = ''
        try:
            message = u'success'
            vlcPlugin = kodi.playback_requests(movie, request)
        except rutils.MyException as ex:
            message = ex.message
            print('Caught %s' % ex.message)
            vlcPlugin = False

        movieContext = {
            'movie': movie,
            'playit': playit,
            'objectForm': self.form_class(instance=movie),
            'vlcPlugin': vlcPlugin,
            'message': message
        }
        #print('render with message %s' % message)
        return render(request, self.template_name, movieContext)