def makeseries(request): if request.method == 'POST': naam = request.POST.get('naam') adlibsearch = request.POST.get('adlibsearch') s = models.Serie.objects.create(naam=naam, adlibsearch=adlibsearch) for v in request.POST.getlist('vraag'): vraag = models.Vraag.objects.get(pk=int(v)) models.SerieVraag.objects.create(serie=s, vraag=vraag) c = adlib.Server('http://amdata.adlibsoft.com/wwwopac.ashx') objs = c.search(database='AMcollect', search=adlibsearch) for obj in objs[:200]: util.update_pic_url(obj) if 'picref' in obj: obj_id = obj.get('priref', [None])[0] if obj_id: models.SerieItem.objects.create(serie=s, objdata=json.dumps(obj), objid=obj_id) return HttpResponse('OK %s' % s.pk, mimetype='text/plain') return direct_to_template(request, 'makeseries.html', { 'vragen': models.Vraag.objects.all(), 'pagename': 'makeseries' })
def doseries(request, serie_pk): aantal_deelnemers = models.User.objects.count() aantal_antwoorden = models.Antwoord.objects.count() gem_antwoorden = aantal_antwoorden / aantal_deelnemers serie = models.Serie.objects.get(pk=serie_pk) vraag = random.choice(serie.vragen.all()) # The items that have already been answered answered_obj = [x['obj'] for x in request.user.antwoorden.filter(serievraag__serie=serie).values('obj')] avail_items = serie.items.exclude(objid__in=answered_obj) if avail_items.count() < 1: return direct_to_template(request, 'seriescomplete.html', {'serie': serie, 'aantal_deelnemers': aantal_deelnemers, 'aantal_antwoorden': aantal_antwoorden, 'gem_antwoorden': gem_antwoorden, }) obj = random.choice(avail_items).obj util.update_pic_url(obj) antwoorden = request.user.antwoorden.filter(serievraag__serie=serie) return direct_to_template(request, 'doseries.html', {'serie': serie, 'serievraag': vraag, 'vraag': vraag.vraag, 'antwoorden': antwoorden, 'pagename': 'home', 'obj': obj, 'aantal_deelnemers': aantal_deelnemers, 'aantal_antwoorden': aantal_antwoorden, 'gem_antwoorden': gem_antwoorden, })
def adlibpreview(request): search = request.GET.get('search', 'all') c = adlib.Server('http://amdata.adlibsoft.com/wwwopac.ashx') result = [] for obj in c.search(database='AMcollect', search=search)[:99]: util.update_pic_url(obj) if 'picref' in obj: result.append(obj) return direct_to_template(request, 'adlibsearch.html', {'result': result[:20], 'pagename': 'makeseries', 'search': search, 'count': len(result) })
def adlibpreview(request): search = request.GET.get('search', 'all') c = adlib.Server('http://amdata.adlibsoft.com/wwwopac.ashx') result = [] for obj in c.search(database='AMcollect', search=search)[:99]: util.update_pic_url(obj) if 'picref' in obj: result.append(obj) return direct_to_template( request, 'adlibsearch.html', { 'result': result[:20], 'pagename': 'makeseries', 'search': search, 'count': len(result) })
def doseries(request, serie_pk): aantal_deelnemers = models.User.objects.count() aantal_antwoorden = models.Antwoord.objects.count() gem_antwoorden = aantal_antwoorden / aantal_deelnemers serie = models.Serie.objects.get(pk=serie_pk) vraag = random.choice(serie.vragen.all()) # The items that have already been answered answered_obj = [ x['obj'] for x in request.user.antwoorden.filter( serievraag__serie=serie).values('obj') ] avail_items = serie.items.exclude(objid__in=answered_obj) if avail_items.count() < 1: return direct_to_template( request, 'seriescomplete.html', { 'serie': serie, 'aantal_deelnemers': aantal_deelnemers, 'aantal_antwoorden': aantal_antwoorden, 'gem_antwoorden': gem_antwoorden, }) obj = random.choice(avail_items).obj util.update_pic_url(obj) antwoorden = request.user.antwoorden.filter(serievraag__serie=serie) return direct_to_template( request, 'doseries.html', { 'serie': serie, 'serievraag': vraag, 'vraag': vraag.vraag, 'antwoorden': antwoorden, 'pagename': 'home', 'obj': obj, 'aantal_deelnemers': aantal_deelnemers, 'aantal_antwoorden': aantal_antwoorden, 'gem_antwoorden': gem_antwoorden, })
def makeseries(request): if request.method == 'POST': naam = request.POST.get('naam') adlibsearch = request.POST.get('adlibsearch') s = models.Serie.objects.create(naam=naam, adlibsearch=adlibsearch) for v in request.POST.getlist('vraag'): vraag = models.Vraag.objects.get(pk=int(v)) models.SerieVraag.objects.create(serie=s, vraag=vraag) c = adlib.Server('http://amdata.adlibsoft.com/wwwopac.ashx') objs = c.search(database='AMcollect', search=adlibsearch) for obj in objs[:200]: util.update_pic_url(obj) if 'picref' in obj: obj_id = obj.get('priref', [None])[0] if obj_id: models.SerieItem.objects.create(serie=s, objdata=json.dumps(obj), objid=obj_id) return HttpResponse('OK %s'%s.pk, mimetype='text/plain') return direct_to_template(request, 'makeseries.html', {'vragen': models.Vraag.objects.all(), 'pagename': 'makeseries' })