def pack(request, username, pack_id): try: pack = Pack.objects.select_related().annotate(num_sounds=Count('sound')).get(user__username__iexact=username, id=pack_id) except Pack.DoesNotExist: raise Http404 qs = Sound.objects.select_related('pack', 'user', 'license', 'geotag').filter(pack=pack, moderation_state="OK", processing_state="OK") num_sounds_ok = len(qs) # TODO: refactor: This list of geotags is only used to determine if we need to show the geotag map or not pack_geotags = Sound.public.select_related('license', 'pack', 'geotag', 'user', 'user__profile').filter(pack=pack).exclude(geotag=None).exists() google_api_key = settings.GOOGLE_API_KEY if num_sounds_ok == 0 and pack.num_sounds != 0: messages.add_message(request, messages.INFO, 'The sounds of this pack have <b>not been moderated</b> yet.') else : if num_sounds_ok < pack.num_sounds : messages.add_message(request, messages.INFO, 'This pack contains more sounds that have <b>not been moderated</b> yet.') # If user is owner of pack, display form to add description enable_description_form = False if request.user.username == username: enable_description_form = True form = PackDescriptionForm(instance = pack) # Manage POST info (if adding a description) if request.method == 'POST': form = PackDescriptionForm(request.POST, pack) if form.is_valid(): pack.description = form.cleaned_data['description'] pack.save() else: pass file_exists = os.path.exists(pack.locations("license_path")) return render_to_response('sounds/pack.html', combine_dicts(locals(), paginate(request, qs, settings.SOUNDS_PER_PAGE)), context_instance=RequestContext(request))
def pack(request, username, pack_id): try: pack = Pack.objects.select_related().get(id=pack_id) if pack.user.username.lower() != username.lower(): raise Http404 except Pack.DoesNotExist: raise Http404 qs = Sound.objects.select_related('pack', 'user', 'license', 'geotag').filter(pack=pack, moderation_state="OK", processing_state="OK") num_sounds_ok = len(qs) # TODO: refactor: This list of geotags is only used to determine if we need to show the geotag map or not pack_geotags = Sound.public.select_related( 'license', 'pack', 'geotag', 'user', 'user__profile').filter(pack=pack).exclude(geotag=None).exists() google_api_key = settings.GOOGLE_API_KEY if num_sounds_ok == 0 and pack.num_sounds != 0: messages.add_message( request, messages.INFO, 'The sounds of this pack have <b>not been moderated</b> yet.') else: if num_sounds_ok < pack.num_sounds: messages.add_message( request, messages.INFO, 'This pack contains more sounds that have <b>not been moderated</b> yet.' ) # If user is owner of pack, display form to add description enable_description_form = False if request.user.username == username: enable_description_form = True form = PackDescriptionForm(instance=pack) # Manage POST info (if adding a description) if request.method == 'POST': form = PackDescriptionForm(request.POST, pack) if form.is_valid(): pack.description = form.cleaned_data['description'] pack.save() else: pass file_exists = os.path.exists(pack.locations("license_path")) return render_to_response('sounds/pack.html', combine_dicts( locals(), paginate(request, qs, settings.SOUNDS_PER_PAGE)), context_instance=RequestContext(request))
def pack(request, username, pack_id): try: pack = Pack.objects.select_related().get(id=pack_id) if pack.user.username.lower() != username.lower(): raise Http404 except Pack.DoesNotExist: raise Http404 qs = Sound.objects.only("id").filter(pack=pack, moderation_state="OK", processing_state="OK") paginate_data = paginate(request, qs, settings.SOUNDS_PER_PAGE) paginator = paginate_data["paginator"] current_page = paginate_data["current_page"] page = paginate_data["page"] sound_ids = [sound_obj.id for sound_obj in page] pack_sounds = Sound.objects.ordered_ids(sound_ids) num_sounds_ok = len(qs) if num_sounds_ok == 0 and pack.num_sounds != 0: messages.add_message(request, messages.INFO, "The sounds of this pack have <b>not been moderated</b> yet.") else: if num_sounds_ok < pack.num_sounds: messages.add_message( request, messages.INFO, "This pack contains more sounds that have <b>not been moderated</b> yet." ) # If user is owner of pack, display form to add description enable_description_form = False if request.user.username == username: enable_description_form = True form = PackDescriptionForm(instance=pack) # Manage POST info (if adding a description) if request.method == "POST": form = PackDescriptionForm(request.POST, pack) if form.is_valid(): pack.description = form.cleaned_data["description"] pack.save() else: pass file_exists = os.path.exists(pack.locations("license_path")) return render_to_response("sounds/pack.html", locals(), context_instance=RequestContext(request))