def form_valid(self, form): data = form.cleaned_data adds = [('add{}'.format(i - 1), data.get('add{}'.format(i), '')) for i in range(1, 6)] # print(adds) for index, add in adds: AdvertiseBox.load().set_add(index, add) # print('cheeeel') # print(str(AdvertiseBox.load())) return HttpResponseRedirect(SITE_URL)
def home(request): new_services = Service.objects.all().order_by('-id')[0:5] new_solds = [] for srv in new_services: new_solds.append(sold_count(srv.sold_number)) if request.user.is_authenticated(): try: if request.user.site_user is not None: if request.user.site_user.get_fields()['super_type'] == 'tourist': recomended_services = send_recommended_mail(request.user.id) recomended_solds = [] for srv in recomended_services: recomended_solds.append(sold_count(srv.sold_number)) return render(request, 'base/home.html',{ 'new_services': zip(new_services, new_solds), 'recomended_services': zip(recomended_services, recomended_solds) }) except: pass return render(request, 'base/home.html',{ 'new_services': zip(new_services, new_solds), 'pics': AdvertiseBox.load() })
def get_initial(self): adv = AdvertiseBox.load() adds = [('add{}'.format(i + 1), getattr(adv, 'add{}'.format(i)).name if getattr(adv, 'add{}'.format(i)) else '') for i in range(0, 5)] return dict(adds)