def discography_list(request): me = rq.get_me(True, request) rutils.cleanup_my_private_directory(me, u'discography') my_path, _ = rutils.my_private_directory(me, u'discography') my_file = (u'%s/d%s%s' % (my_path, datetime.date.today(), u'.html')) context = { 'title': 'Full discography by artist', 'mlist': Musician.objects.all(), 'my_file': my_file } template_name = 'FHLReader/discography.html' content = render_to_string(template_name, context) try: with open(my_file, 'w') as static_file: static_file.write(content.encode('utf8')) except Exception as ex: # would eventually like to catch the correct message message = str('Error writing file %s' % (type(ex).__name__)) print(message) raise rutils.MyException(message) return render(request, template_name, context)
def get(self, request, pref): me = rq.get_me(False, request) lk = Q(likes__username=me) lv = Q(loves__username=me) if pref == 'liked': songs = Song.objects.filter(lk) title = 'Songs I like' elif pref == 'loved': songs = Song.objects.filter(lv) title = 'Songs I love' elif pref == 'both': songs = Song.objects.filter(lv | lk) title = 'All my Songs' elif pref == 'random': songs = Song.objects.filter(lv | lk).order_by('?') title = 'My Songs Radio' else: # should not happen songs = [] title = 'Error - no song preference' vargs = {'songs': songs, 'title': title} return vu.generic_collection_view(request, **vargs)
def get(self, request, pref): me = rq.get_me(False, request) lk = Q(likes__username=me) lv = Q(loves__username=me) if pref == 'liked': videos = Movie.objects.filter(lk) title = 'Videos I like' elif pref == 'loved': videos = Movie.objects.filter(lv) title = 'Videos I love' elif pref == 'both': videos = Movie.objects.filter(lk | lv) title = 'All My Videos' elif pref == 'random': videos = Movie.objects.filter(lk | lv).order_by('?') title = 'All My Videos' else: # should not happen videos = [] title = 'Error - no video preference' vargs = {'movies': videos, 'title': title} return vu.generic_collection_view(request, **vargs)
def get(self, request, pref): me = rq.get_me(False, request) lk = Q(likes__username=me) lv = Q(loves__username=me) if pref == 'liked': pictures = Picture.slide_objects.filter(lk) title = 'Pictures I Like' elif pref == 'loved': pictures = Picture.slide_objects.filter(lv) title = 'Pictures I Love' elif pref == 'both': pictures = Picture.slide_objects.filter(lk | lv) title = 'All My Pictures' elif pref == 'random': pictures = Picture.slide_objects.filter(lk | lv).order_by('?') title = 'All My Pictures' else: # should not happen pictures = [] title = 'Error - no picture preference' vargs = {'pictures': pictures, 'title': title} return vu.generic_collection_view(request, **vargs)
def send_to_slideshow(pictures, request): # default values to be replaced if option is in request playback = choices.FLIST random = False smut = False thumb = False if request.method == 'POST': if 'random' in request.POST: random = request.POST.get('random') if 'playback' in request.POST: playback = request.POST.get('playback') if 'thumb' in request.POST: thumb = request.POST.get('thumb') print('thumb') if 'smut' in request.POST: smut = request.POST.get('smut') print('smut') if request.method == 'GET': if 'random' in request.GET: random = request.GET.get('random') if 'thumb' in request.GET: thumb = request.GET.get('thumb') if 'smut' in request.GET: smut = request.GET.get('smut') if 'playback' in request.GET: playback = request.GET.get('playback') message = u'' if random: pictures = pictures.order_by('?') if not smut: pictures = pictures.exclude(collection__filePath__icontains='smut') if not thumb: pictures = pictures.exclude(fileName__iendswith=choices.picts[7]) if playback == choices.FLIST: pass elif playback == choices.CCAST: me = rq.get_me(True, request) cc.cast_slides_all(pictures, me, False) else: try: if kodi.playlist_select(pictures, playback, request): message = u'success - pictures sent to Kodi' except rutils.MyException as ex: message = ex.message print('Caught %s' % ex.message) print('pictures options random %s playback %s length %d' % (random, playback, pictures.count())) context = { 'title': 'date-added pictures', 'pictures': pictures, 'message': message, } template_name = 'FHLReader/picture_list.html' return render(request, template_name, context)
def get(self, request): #print("RandomList GET") rform = self.form_class() me = rq.get_me(True, request) if me is None: # hide field from anonymous user rform.fields['kind'].widget = HiddenInput() context = {'form': rform, 'title': 'Build a Radio Channel'} return render(request, self.template_name, context)
def transfer_favourites(request): me = rq.get_me(True, request) lk = Q(likes__username=me) lv = Q(loves__username=me) songs = Song.objects.filter(lv | lk) my_path = rutils.transfer_to_my_directory(me, songs) title = 'Transferred to directory ' + my_path vargs = {'songs': songs, 'title': title} return vu.generic_collection_view(request, **vargs)
def post(self, request): #print("RadioChannel POST") me = rq.get_me(True, request) mycache = cu.MyCache(request) if 'save-query' in request.POST: return redirect(reverse('cached_list')) rlist = [] bound_form = self.form_class(request.POST) if me is None: # hide field from anonymous user bound_form.fields['kind'].widget = HiddenInput() if bound_form.is_valid(): count = bound_form.cleaned_data['count'] kind = bound_form.cleaned_data['kind'] xmas = bound_form.cleaned_data['xmas'] recent = bound_form.cleaned_data['recent'] cl = bound_form.cleaned_data['classic'] justme = False if kind == choices.ME: justme = True if recent: rlist = rq.radio_recent(justme, me, cl, xmas, count) else: target = rq.radio_all(justme, me, cl, xmas) rlist = target[:count] cu.cache_list_bykind(rlist, choices.SONG, 'special_channel', mycache) if recent: # recent case simply move to cached list return redirect(reverse('cached_list')) # display the list as files with the form context = { 'form': bound_form, 'rlist': rlist, 'title': 'Build a Channel' } return render(request, self.template_name, context)
def get(self, request): # print("UserDetail GET") me = rq.get_me(True, request) context = {'me': me, 'choices': choices.VIDEO_CHOICES} return render(request, self.template_name, context)