예제 #1
0
def likeComentario(request,id_comentario):    
    usuario = request.user
    outfile = open('archivoLogs.txt', 'a') # Indicamos el valor 'w'.
    comentario = get_object_or_404(Comentario, id=id_comentario)
    album = Album.objects.get(id=comentario.fkalbum.id)
    albumes = Album.objects.filter(id=album.id)
    usu = User.objects.get(id= comentario.fkalbum.fkusuario.id )
    contenido = Contenido.objects.filter(fkalbum=comentario.fkalbum.id)
    comentarioAlbum = Comentario.objects.filter(fkalbum=comentario.fkalbum.id)      
    cantidadComentario = Comentario.objects.filter(fkalbum=comentario.fkalbum.id).count()          
    cantidadLike = Like.objects.all()   
    count = Like.objects.filter(fkcomentario = comentario, userLike=usuario)
    if count:
    	for aux in count: 
            aux.delete()    	
    		
    Liked = Like(fkcomentario=comentario, userLike=usuario,like=True)        
    Liked.save()           
    l = Like.objects.get(fkcomentario = comentario, userLike=usuario)
    k = User.objects.get(id=album.fkusuario.id)
    b = Historial(usuario=k, accion='like',fklike=l)
    b.save()
    contexto = {'usuario' : usuario, 'albumes' : albumes, 'contenido' : contenido, 'comentarioAlbum' : comentarioAlbum,'formulario': RegistroComentario(), 'cantidadComentario':cantidadComentario ,'cantidadLike':cantidadLike }
    outfile.write('LikeComentario - OBTENIENDO USUARIO QUE HIZO LIKE\n')
    outfile.write('LikeComentario - ENVIANDO POR CONTEXTO AL: USUARIO, ALBUMES, CONTENIDO, COMENTARIO, FOMULARIO Y LIKE\n')
    outfile.close()
    return render_to_response('detalleAlbum.html',context_instance=RequestContext(request, contexto)) 
예제 #2
0
def like_comment(request, category_id, poll_id, comment_id):
    c = Comment.objects.get(pk=comment_id)
    c.likes = c.likes + 1
    c.save()
    l = Like(user=request.user, comment=c, pub_date=datetime.datetime.now())
    l.save()
    # Redirect back to poll page.
    return HttpResponseRedirect("/" + category_id + '/' + poll_id + '/')
예제 #3
0
  def handle(self, *args, **options):
    start_time = datetime.now()
    # Заполнение юзеров
    for user_id in range(1, users_count + 1):
      user = CustomUser(
          avatar='http://lorempixel.com/10%s/10%s/cats' % (
              user_id % 10, user_id % 10),
          password=make_password("password"),
          last_login=self.random_date(),
          is_superuser=False,
          username="******" % (user_id),
          first_name="",
          last_name="",
          email="",
          is_staff=False,
          is_active=True,
          date_joined=datetime(2015, 1, 1, 1, 0, 0, 0, pytz.UTC)
      )
      self.stdout.write("User#%d" % user_id)
      user.save()
    # Заполнение вопросов
    for question_id in range(1, questions_count + 1):
      text = ''
      for i in get_paragraphs(randint(1, 4)):
        text += i

      question = Question(
          title=get_sentence(),
          content=text,
          author_id=randint(1, users_count),
          created=self.random_date(),
          rating=0
      )
      self.stdout.write("Question#%d" % question_id)
      question.save()

    # Заполнение ответов
    for answer_id in range(1, answers_count + 1):
      text = ''
      for i in get_paragraphs(randint(1, 2)):
        text += i

      answer = Answer(
          id=answer_id,
          content=text,
          author_id=randint(1, users_count),
          created=self.random_date(),
          question_id=randint(1, questions_count),
          rating=0
      )

      self.stdout.write("Answer#%d" % answer_id)
      answer.save()

    # Заполнение тэгов
    words = open('polls/words', 'r')
    for tag_id in range(1, tags_count + 1):
      tag = Tag(title=words.readline()[:-1])
      tag.save()
    words.close()

    # Заполнение лайков
    for like_id in range(1, votes_count):
      l_value = randint(0, 1)
      if l_value == 0:
        l_value = -1
      like = Like(author_id=randint(1, users_count), value=l_value)
      like.save()
      self.stdout.write("Like#%d" % like_id)

    # Добавление тегов к вопросам
    for question_id in range(1, questions_count + 1):
      question = Question.objects.get(pk=question_id)
      self.stdout.write("Linking tags#%d" % question_id)
      for i in range(1, 4):
        question.tags.add(Tag.objects.get(pk=randint(1, tags_count)))

    for q_like in range(1, votes_count / 2):
      question = Question.objects.get(pk=randint(1, questions_count))
      like = Like.objects.get(pk=q_like)
      question.likes.add(like)
      question.rating += like.value
      question.save()
      self.stdout.write("Linking question likes#%d" % q_like)

    for a_like in range(votes_count / 2 + 1, votes_count):
      answer = Answer.objects.get(pk=randint(1, answers_count))
      like = Like.objects.get(pk=a_like)
      answer.likes.add(like)
      answer.rating += like.value
      answer.save()
      self.stdout.write(
          "Linking answer likes#%d, like value=%d" % (a_like, like.value))

    end_time = datetime.now()
    self.stdout.write(
        'Database filled successfully' + str(end_time - start_time))
예제 #4
0
    def handle(self, *args, **options):
        start_time = datetime.now()
        #
        for user_id in range(1, users_count + 1):
            user = CustomUser(avatar='http://lorempixel.com/10%s/10%s/people' %
                              (user_id % 10, user_id % 10),
                              password=make_password("password"),
                              last_login=self.random_date(),
                              is_superuser=False,
                              username="******" % (user_id),
                              first_name="",
                              last_name="",
                              email="",
                              is_staff=False,
                              is_active=True,
                              date_joined=datetime(2014, 1, 1, 1, 0, 0, 0,
                                                   pytz.UTC))
            self.stdout.write("User#%d" % user_id)
            user.save()
        #
        for question_id in range(1, questions_count + 1):
            text = ''
            for i in get_paragraphs(randint(1, 4)):
                text += i

            question = Question(title=get_sentence(),
                                content=text,
                                author_id=randint(1, users_count),
                                created=self.random_date(),
                                rating=0,
                                counts=0)
            self.stdout.write("Question#%d" % question_id)
            question.save()

        #
        for answer_id in range(1, answers_count + 1):
            text = ''
            for i in get_paragraphs(randint(1, 2)):
                text += i
            """
      answer = Answer(
          id=answer_id,
          content=text,
          author_id=randint(1, users_count),
          created=self.random_date(),
          question_id=randint(1, questions_count),
          rating=0
      )

      self.stdout.write("Answer#%d" % answer_id)
      answer.save()"""
            answer = Answer(id=answer_id,
                            content=text,
                            author_id=randint(1, users_count),
                            created=self.random_date(),
                            question_id=randint(1, questions_count),
                            rating=0)

            self.stdout.write("Answer#%d" % answer_id)
            answer.save()

        for question_id in range(1, questions_count + 1):
            question = Question.objects.get(pk=question_id)
            answer_ = Answer.objects.filter(question_id=question_id)
            i = 0
            for elem in answer_:
                i = i + 1
            question.counts = i
            question.save()
            answer.save()

        #
        words = open('polls/words', 'r')
        for tag_id in range(1, tags_count + 1):
            tag = Tag(title=words.readline()[:-1])
            tag.save()
        words.close()

        #
        for like_id in range(1, votes_count + 1):
            l_value = randint(0, 1)
            if l_value == 0:
                l_value = -1
            like = Like(author_id=randint(1, users_count), value=l_value)
            like.save()
            self.stdout.write("Like#%d" % like_id)

        #
        for question_id in range(1, questions_count + 1):
            question = Question.objects.get(pk=question_id)
            self.stdout.write("Linking tags#%d" % question_id)
            #for i in range(1, ):
            question.tags.add(Tag.objects.get(pk=randint(1, tags_count)))

        for q_like in range(1, votes_count / 2):
            question = Question.objects.get(pk=randint(1, questions_count))
            for i in range(1, q_like):
                like = Like.objects.get(pk=i)
                question.likes.add(like)
                question.rating += like.value
                question.save()
            self.stdout.write("Linking question likes#%d" % q_like)

        for a_like in range(votes_count / 2 + 1, votes_count):
            answer = Answer.objects.get(pk=randint(1, answers_count))
            for i in range(1, q_like):
                like = Like.objects.get(pk=i)
                answer.likes.add(like)
                answer.rating += like.value
                answer.save()
            self.stdout.write("Linking answer likes#%d" % a_like)

        end_time = datetime.now()
        self.stdout.write('Database filled successfully' +
                          str(end_time - start_time))