def view_question(request, question_id): option = request.GET.get('option', 'highest_rated') page = request_helpers.get_page(request) user = request.user question = get_object_or_404(models.Question, id = question_id) question.accepted_answer = models.Question.objects.get_accepted_answer(question) AnswerForm = forms.build_answer_form() if user and request.POST: answer_form = AnswerForm(request.POST, request.FILES) answer_form.question = question answer_form.user = user if answer_form.is_valid(): answer = models.Answer.objects.answer_question(answer_form.cleaned_data['answer'], question, user) else: answer_form = AnswerForm() answers = models.Question.objects.get_answers(question, option) current_page, page_range = pagination.paginate_queryset(answers, 20, 5, page) View.objects.add(question, request_helpers.get_ip(request)) return shortcuts.render_to_response( 'django_qa/view.html', {'question':question, 'form':answer_form, 'is_owner':question.user.id == user.id, 'current_page':current_page, 'page_range':page_range, 'sort':option}, context_instance = RequestContext(request), )
def view_app(request, app_id): from django_relatedcontent.models import ContentAssociation from django_tracking.models import View user = request.user app = get_object_or_404(models.App, id = app_id) app_content_type = ContentType.objects.get_for_model(models.App) dependencies = ContentAssociation.objects.associations_for_object(app, 'dependency', models.App) app.dependencies = [models.App.objects.get(id = x.child_object_id) for x in dependencies] app.sources = [source.uri for source in Source.objects.filter(content_type = app_content_type, object_id = app_id)] app.pythons = PythonCompatibility.objects.filter(content_type = app_content_type, object_id = app.id) app.djangos = DjangoCompatibility.objects.filter(content_type = app_content_type, object_id = app.id) View.objects.add(app, request_helpers.get_ip(request)) return shortcuts.render_to_response( 'applications/view.html', {'app':app, 'is_owner':app.user.id == user.id, }, context_instance = RequestContext(request), )
def generate_anon_user_name(request): """ Generate an anonymous user name based on and ip address. """ from django_utils.request_helpers import get_ip ip = get_ip(request) return "anon_user_%s" % (str(ip))
def clean_captcha(self): value = None if self.request: challenge = self.data['recaptcha_challenge_field'] response = self.data['recaptcha_response_field'] captcha_response = captcha.submit( challenge, response, settings.RECAPTCHA_PRIVATE_KEY, request_helpers.get_ip(self.request)) if not captcha_response.is_valid: raise forms.ValidationError("Incorrect response entered.") return value
def view(request, tutorial_id): user = request.user tutorial = get_object_or_404(models.Tutorial, id = tutorial_id) View.objects.add(tutorial, request_helpers.get_ip(request)) return shortcuts.render_to_response( 'tutorials/view.html', {'tutorial':tutorial, 'is_owner':tutorial.user.id == tutorial.id, }, context_instance = RequestContext(request), )
def view(request, code_id): user = request.user code = get_object_or_404(models.Code, id = code_id) View.objects.add(code, request_helpers.get_ip(request)) return shortcuts.render_to_response( 'code/view.html', {'code':code, 'is_owner':code.user.id == user.id, }, context_instance = RequestContext(request), )
def view_answer(request, answer_id): answer = get_object_or_404(models.Answer, id = answer_id) question = answer.question answer_url = "%s#answer_%s" % (reverse('qa-view-question', args=[question.id]), str(answer.id)) View.objects.add(question, request_helpers.get_ip(request)) return http.HttpResponseRedirect(answer_url)
def clean_captcha(self): value = None if self.request: challenge = self.data['recaptcha_challenge_field'] response = self.data['recaptcha_response_field'] captcha_response = captcha.submit(challenge, response, settings.RECAPTCHA_PRIVATE_KEY, request_helpers.get_ip(self.request)) if not captcha_response.is_valid: raise forms.ValidationError("Incorrect response entered.") return value