def home(request):
  from solutioner.solutions.views import most_recent_sols, most_pop_sols
  from solutioner.users.forms import RegisterForm, LoginForm
  form_login = LoginForm()
  form_reg = RegisterForm(prefix='0')
  from solutioner.solutions.views import add_solution
  from solutioner.comments.views import add_comment
  form_add_solution = add_solution(request, JSON=False)
  form_add_comment = add_comment(request, object_inst=request.user, operation='post_desk', JSON=False)
  if request.user.is_authenticated():
    last_event, firstever_event = get_home_events(request, JSON=False)
  else:
    last_event, firstever_event = 1, 1

  return render_to_response('home.html', {'last_event': last_event, 'firstever_event': firstever_event, 'form_reg': form_reg, 'form_login': form_login, 'form_add_solution': form_add_solution, 'form_add_comment': form_add_comment, 'latestsols': most_recent_sols(), 'mostpops': most_pop_sols()}, context_instance=RequestContext(request))
def view_solution(request, solution_id):
  try:
    redirectTo = re.search(r'http://[-.\w\d]+/(.+)', request.META['HTTP_REFERER']).group(1)
    redirectTo = '/'+redirectTo
  except:
    redirectTo = '/'
  real_solution_id = int(solution_id)
  needed_solution = get_object_or_404(Solution, id=real_solution_id, is_deleted=False)
  owner_score = User_score.objects.get(user=needed_solution.owner)
  if request.user != needed_solution.owner:
    owner_score.viewed_count = int(owner_score.viewed_count) + 1
    owner_score.save()
    try:
      needed_solution.viewed = int(needed_solution.viewed) + 1
    except:
      needed_solution.viewed = 0
    needed_solution.save()
  graphs_user_info = graphs_user(request, user_username=needed_solution.owner.username, external=False, JSON=False, score=True)

  add_comment_av = False
  if RBACGenericPermission.objects.get_user_permission(needed_solution.owner, Solution, 'add_comment', request.user) and request.user.is_authenticated():
    add_comment_av = True
  if add_comment_av: #if permissions passed, POST vars come to account
    form = add_comment(request, object_inst=needed_solution , JSON=False)
    if not form: #DONE!
      return HttpResponseRedirect(redirectTo)
  else:
    form = None
    
  if request.user.is_authenticated() and request.user != needed_solution.owner:
    user_score = User_score.objects.get(user=request.user)
    user_score.views_count = int(user_score.views_count) + 1
    user_score.save()
      
  graphs_solution_info = graphs_solution(request, real_solution_id, JSON=False)
  tags = Solution.objects.get(id=real_solution_id).tags.values_list('id', flat=True)
  soltags = Solution.objects.filter(tags__id__in=tags).exclude(id=real_solution_id)[0:20]
  latestsols = most_recent_sols()
  mostpops = most_pop_sols()
  comments = get_comment(request=request, operation='view_comment', owner=needed_solution.owner, model=Solution, order_by='-datetime', limit=10, object_inst=needed_solution)
  return render_to_response('view_solution.html',{ 'graphs_solution_info': graphs_solution_info, 'graphs_user_info': graphs_user_info,'soltags':soltags, 'mostpops':mostpops, 'latestsols':latestsols, 'form': form, 'add_comment_av': add_comment_av, 'comments': comments }, context_instance=RequestContext(request))
def profile_desk(request, user_username):
  try:
    redirectTo = re.search(r'http://[-.\w\d]+/(.+)', request.META['HTTP_REFERER']).group(1)
    redirectTo = '/'+redirectTo
  except:
    redirectTo = '/'
  user = User.objects.get(username=user_username)
  post_desk = False
  if RBACGenericPermission.objects.get_user_permission(user, User, 'post_desk', request.user):
    post_desk = True
  if post_desk: #if permissions passed then POST vars come to account
    form = add_comment(request, object_inst=user, operation='post_desk', JSON=False)
    if not form: #DONE!
      return HttpResponseRedirect(redirectTo)
  else:
    form = None
  from solutioner.solutions.views import add_solution
  form_add_solution = add_solution(request, JSON=False)
  last_event, firstever_event = get_profile_events(request, user_username=user_username, JSON=False)
  graphs_user_info = graphs_user(request, user_username=user_username, JSON=False)
  return render_to_response("profile_desk.html", {'title': 'Desk', 'graphs_user_info': graphs_user_info, 'form': form, 'form_add_solution': form_add_solution, 'post_desk': post_desk, 'last_event': last_event, 'firstever_event': firstever_event, 'user_following_limited_graph': user_following_graph(request, user_username, limit=5), 'user_followers_limited_graph': user_followers_graph(request, user_username, limit=5) }, context_instance=RequestContext(request))
Exemple #4
0
def view_solution(request, solution_id):
    try:
        redirectTo = re.search(r'http://[-.\w\d]+/(.+)',
                               request.META['HTTP_REFERER']).group(1)
        redirectTo = '/' + redirectTo
    except:
        redirectTo = '/'
    real_solution_id = int(solution_id)
    needed_solution = get_object_or_404(Solution,
                                        id=real_solution_id,
                                        is_deleted=False)
    owner_score = User_score.objects.get(user=needed_solution.owner)
    if request.user != needed_solution.owner:
        owner_score.viewed_count = int(owner_score.viewed_count) + 1
        owner_score.save()
        try:
            needed_solution.viewed = int(needed_solution.viewed) + 1
        except:
            needed_solution.viewed = 0
        needed_solution.save()
    graphs_user_info = graphs_user(
        request,
        user_username=needed_solution.owner.username,
        external=False,
        JSON=False,
        score=True)

    add_comment_av = False
    if RBACGenericPermission.objects.get_user_permission(
            needed_solution.owner, Solution, 'add_comment',
            request.user) and request.user.is_authenticated():
        add_comment_av = True
    if add_comment_av:  #if permissions passed, POST vars come to account
        form = add_comment(request, object_inst=needed_solution, JSON=False)
        if not form:  #DONE!
            return HttpResponseRedirect(redirectTo)
    else:
        form = None

    if request.user.is_authenticated(
    ) and request.user != needed_solution.owner:
        user_score = User_score.objects.get(user=request.user)
        user_score.views_count = int(user_score.views_count) + 1
        user_score.save()

    graphs_solution_info = graphs_solution(request,
                                           real_solution_id,
                                           JSON=False)
    tags = Solution.objects.get(id=real_solution_id).tags.values_list(
        'id', flat=True)
    soltags = Solution.objects.filter(tags__id__in=tags).exclude(
        id=real_solution_id)[0:20]
    latestsols = most_recent_sols()
    mostpops = most_pop_sols()
    comments = get_comment(request=request,
                           operation='view_comment',
                           owner=needed_solution.owner,
                           model=Solution,
                           order_by='-datetime',
                           limit=10,
                           object_inst=needed_solution)
    return render_to_response('view_solution.html', {
        'graphs_solution_info': graphs_solution_info,
        'graphs_user_info': graphs_user_info,
        'soltags': soltags,
        'mostpops': mostpops,
        'latestsols': latestsols,
        'form': form,
        'add_comment_av': add_comment_av,
        'comments': comments
    },
                              context_instance=RequestContext(request))