def user_login(request): data = {} revurl = urlresolvers.reverse('izba_homepage') loc = request.COOKIES.get('ads_location', None) if not request.user.is_authenticated(): if request.method == 'POST': data['form'] = AuthenticationForm(data=request.POST) if data['form'].is_valid(): username = request.POST.get('username', '') password = request.POST.get('password', '') user = authenticate(username=username, password=password) if user and user.is_active: login(request, user) return HttpResponseRedirect(revurl) else: data['form'] = AuthenticationForm() else: return HttpResponseRedirect(revurl) cache_key = 'feat_items_%s' % loc data['featured_items'] = cache.get(cache_key) if not data['featured_items']: data['featured_items'] = Item.get_featured(loc) cache.set(cache_key, data['featured_items'], 900) return render(request, 'accounts/login.html', data)
def render_contact_form(request): data = {} loc = request.COOKIES.get('ads_location', None) if request.method == 'POST': form = ContactForm(request.POST) subject = request.POST.get('subject', '') user_email = request.POST.get('email', '') message = request.POST.get('message', '') honeypot = request.POST.get('phone', '') receivers = [settings.ADMINS[0][1]] if form.is_valid(): try: send_mail(u'[Izba] {0}'.format(subject), message, user_email, receivers) except BadHeaderError: return http.HttpResponse(_(u'Неправильный заголовок.')) return http.HttpResponseRedirect('/feedback/thankyou/') else: data['err_msg'] = _(u'Пожалуйста, заполните все поля, чтобы отправить сообщение.') else: data['form'] = ContactForm() cache_key = 'feat_items_%s' % loc data['featured_items'] = cache.get(cache_key) if not data['featured_items']: data['featured_items'] = Item.get_featured(loc) cache.set(cache_key, data['featured_items'], 900) return render(request, 'forms/feedback.html', data)
def my_settings(request): data = {} loc = request.COOKIES.get('ads_location', None) if request.method == 'POST': data['form'] = forms.AccountForm(request.POST, request.FILES, instance=request.user.profile) if data['form'].is_valid(): account_instance = data['form'].save(commit=False) avatar = data['form'].cleaned_data['avatar'] data['err_msg'] = forms.clean_avatar(avatar) if not data['err_msg']: account_instance.save() data['suc_msg'] = _(u'Настройки сохранены.') else: data['err_msg'] = _(u'Один или несколько полей заполнены неверно. Пожалуйста, проверьте их и попробуйте снова.') else: data['form'] = forms.AccountForm(instance=request.user.profile) cache_key = 'feat_items_%s' % loc data['featured_items'] = cache.get(cache_key) if not data['featured_items']: data['featured_items'] = Item.get_featured(loc) cache.set(cache_key, data['featured_items'], 900) return render(request, 'accounts/settings.html', data, context_instance=RequestContext(request))
def thank_you(request): data = {} loc = request.COOKIES.get('ads_location', None) cache_key = 'feat_items_%s' % loc data['featured_items'] = cache.get(cache_key) if not data['featured_items']: data['featured_items'] = Item.get_featured(loc) cache.set(cache_key, data['featured_items'], 900) return render(request, 'forms/message_sent.html', data)
def my_items(request): data = {} data['user_items'] = Item.objects.filter(seller=request.user) loc = request.COOKIES.get('ads_location', None) cache_key = 'feat_items_%s' % loc data['featured_items'] = cache.get(cache_key) if not data['featured_items']: data['featured_items'] = Item.get_featured(loc) cache.set(cache_key, data['featured_items'], 900) return render(request, 'accounts/items.html', data)
def render_cephei(request): if "query" in request.GET: data = {} data["query"] = request.GET.get("query", None) data["section"] = request.GET.get("section", None) data["order_by"] = request.GET.get("order_by", None) data["new"] = request.GET.get("new", None) data["used"] = request.GET.get("used", None) data["location"] = request.GET.get("location", None) location = request.COOKIES.get("ads_location", None) if data["query"] is None or data["query"] == u"Я ищу...": if data["section"] == "all": revurl = urlresolvers.reverse("izba_homepage") elif data["section"] == "clothing": revurl = urlresolvers.reverse("izba_apparel_views") elif data["section"] == "electronics": revurl = urlresolvers.reverse("izba_computer_views") elif data["section"] == "motors": revurl = urlresolvers.reverse("izba_automobile_views") elif data["section"] == "for_home": revurl = urlresolvers.reverse("izba_interior_views") elif data["section"] == "beauty_health": revurl = urlresolvers.reverse("izba_makeup_views") elif data["section"] == "flora_fauna": revurl = urlresolvers.reverse("izba_plant_views") elif data["section"] == "other": revurl = urlresolvers.reverse("izba_otheritem_views") if revurl: return HttpResponseRedirect(revurl) data["result_items"] = Cephei.get_results(request) data["result_count"] = len(data["result_items"]) if request.GET.get("images", None): data["with_images"] = True cache_key = "feat_items_%s" % location data["featured_items"] = cache.get(cache_key) if not data["featured_items"]: data["featured_items"] = Item.get_featured(location) cache.set(cache_key, data["featured_items"], 900) return render(request, "cephei/results.html", data) raise Http404
def user_registration(request): data = {} revurl = urlresolvers.reverse('izba_my_account') loc = request.COOKIES.get('ads_location', None) if not request.user.is_authenticated(): if request.method == 'POST': postdata = request.POST.copy() data['form'] = UserCreationForm(postdata) if data['form'].is_valid(): data['form'].save() username = postdata.get('username', '') password = postdata.get('password1', '') new_user = authenticate(username=username, password=password) if new_user is not None: if new_user.is_active: login(request, new_user) return HttpResponseRedirect(revurl) else: data['err_msg'] = _(u'Данный аккаунт заблокирован.') data['form'] = UserCreationForm() else: data['err_msg'] = _(u'Вы ввели неверные данные.') data['form'] = UserCreationForm() else: data['form'] = UserCreationForm() else: return HttpResponseRedirect(revurl) cache_key = 'feat_items_%s' % loc data['featured_items'] = cache.get(cache_key) if not data['featured_items']: data['featured_items'] = Item.get_featured(loc) cache.set(cache_key, data['featured_items'], 900) return render(request, 'accounts/registration.html', data, context_instance=RequestContext(request))
def view_account(request, id, slug): """ User profile page. """ data = {} loc = request.COOKIES.get('ads_location', None) data['cache_time'] = settings.CACHE_TIME data['viewed_user'] = User.objects.get(pk=id) data['user_items'] = Item.objects.filter(seller=data['viewed_user'], published=True) if request.user.is_authenticated(): if request.user.pk == data['viewed_user'].pk: data['user_items'] = Item.objects.filter(seller=data['viewed_user']) cache_key = 'feat_items_%s' % loc data['featured_items'] = cache.get(cache_key) if not data['featured_items']: data['featured_items'] = Item.get_featured(loc) cache.set(cache_key, data['featured_items'], 900) return render(request, 'accounts/profile.html', data)
def my_security(request): data = {} loc = request.COOKIES.get('ads_location', None) if request.method == 'POST': data['form'] = PasswordChangeForm(data=request.POST, user=request.user) if data['form'].is_valid(): data['form'].save() data['suc_msg'] = _(u'Пароль изменён.') else: data['err_msg'] = _(u'Пароль неверен. Попробуйте снова.') else: data['form'] = PasswordChangeForm(user=request.user) cache_key = 'feat_items_%s' % loc data['featured_items'] = cache.get(cache_key) if not data['featured_items']: data['featured_items'] = Item.get_featured(loc) cache.set(cache_key, data['featured_items'], 900) return render(request, 'accounts/security.html', data, context_instance=RequestContext(request))
def bt_update(self, winner: Item, loser: Item) -> None: self.update_confidence(winner, loser) new_winner_score, new_loser_score = update_scores( winner.score, loser.score, self.confidence) winner.update_score(new_winner_score) loser.update_score(new_loser_score)
def start(count): author_id = 1 local = ['en_US', 'uk_UA', 'ru_RU', 'pl_PL'] for loc in local: fake = Factory.create(loc) # items for i in range(count): local_lat = fake.local_latlng() item = Item(title=fake.catch_phrase(), description=fake.text(), author_id=author_id, point=Point((float(local_lat[0]), float(local_lat[1]))), expires=fake.date_this_year(), city=local_lat[2], address=fake.street_address(), local=loc[:2], # uniq condition=rand.randint(0, 4), price=rand.randint(1, 2000), ) create_img(fake, item) item.save() print("created Item") # jobs for i in range(count): local_lat = fake.local_latlng() job = Job(title=fake.job(), description=fake.text(), author_id=author_id, point=Point((float(local_lat[0]), float(local_lat[1]))), local=loc[:2], address=fake.street_address(), city=local_lat[2], expires=fake.date_this_year(), # uniq jobtype=JobType.objects.get(pk=rand.randint(1, 7)), duration=rand.randint(0, 3), salary=rand.randint(1, 2000), countries=rand.choice(['US', 'UA', 'RU', 'PL']) ) create_img(fake, job) job.save() print("created Job") # rents for i in range(count): local_lat = fake.local_latlng() rent = Rent(title=fake.catch_phrase(), description=fake.text(), author_id=author_id, point=Point((float(local_lat[0]), float(local_lat[1]))), local=loc[:2], address=fake.street_address(), city=local_lat[2], expires=fake.date_this_year(), # uniq property_type=PropertyType.objects.get(pk=rand.randint(1, 4)), bathrooms=rand.randint(1, 3), bedrooms=rand.randint(1, 3), pet_policy=rand.randint(0, 5), furnished=bool(rand.getrandbits(1)), prefer_sex=rand.choice(['a', 'w', 'm']), price=rand.randint(1, 2000), ) create_img(fake, rent) rent.save() print("created Rent") # gifts for i in range(count): local_lat = fake.local_latlng() gift = Gift(title=fake.catch_phrase(), description=fake.text(), gift_type=GiftType.objects.get(pk=rand.randint(1, 4)), author_id=author_id, point=Point((float(local_lat[0]), float(local_lat[1]))), expires=fake.date_this_year(), city=local_lat[2], address=fake.street_address(), local=loc[:2]) create_img(fake, gift) gift.save() print("created Gift")