コード例 #1
0
def newpost(request):

    postid = "wellcomes"
    post = "password"
    username = "******"

    postid = random.sample(xrange(1,10000000), 1)

    post = request.POST.get(
        'post'
        , '')
    username = request.POST.get(
        'username'
        , '')
    request.session['postid'] = postid
    request.session['post'] = post
    request.session['username'] = username
    if username == "":
        return render(request, 'login.html')
    elif username == "guestuser":
        return render(request, 'login.html')
    elif post != "":
     dream = Posts(
        postid=postid,
        post=post,
        username=username,
     )
     dream.save()
    objects = Posts.objects.all()
    comments = Comment.objects.all()
    return render(request, 'post.html',{"username": username, "objects": objects, "comments": comments})
コード例 #2
0
ファイル: views.py プロジェクト: mmosteit/django_forum
def new_thread(request):
    page_title       = 'new_thread'
    new_post_text    = request.POST['post_text']
    new_username     = request.POST['username']
    new_thread_title = request.POST['title']
    new_date_posted  = datetime.datetime.now()

    if new_post_text.strip() == "" or new_username.strip() == "" or new_thread_title.strip() == "":
        return HttpResponseRedirect(reverse('new_thread_error'))
    
    # Create the thread 
    new_thread = Threads(thread_title = new_thread_title, username = new_username, date_posted = new_date_posted) 
    new_thread.save()    

    # Create the dummy post. This post is the parent of all the top level
    # posts in this thread.  Being a dummy post, it contains no text
    dummy_post = Posts(parent_id = 0, date_posted = new_date_posted, thread_id = new_thread.thread_id, deleted = False, username = new_username)
    dummy_post.save()
    
    # Set the new thread's first post to the dummy post
    new_thread.first_post_id = dummy_post.post_id
    new_thread.save()
    
    # Insert the actual first post into the table
    first_post = Posts(parent_id = dummy_post.thread_id, username = new_username, post_text = new_post_text, date_posted = new_date_posted, thread_id = new_thread.thread_id, deleted = False )
    first_post.save()
  
    return HttpResponseRedirect(reverse('index'))
コード例 #3
0
def sumar_post(request, slug):
    template = 'temas/nuevo_post.html'
    if request.method == "POST":
        form = FormNuevoPost(request.POST)
        if form.is_valid():
            texto = form.cleaned_data.get('texto')
            perfil_usuario = Perfiles.objects.get(usuario=request.user)
            tema_contenedor = get_object_or_404(Temas, slug=slug)
            post = Posts(texto=texto, creador=perfil_usuario,
                         tema=tema_contenedor)
            post.save()

            perfil_usuario.numero_de_posts = perfil_usuario.numero_de_posts + 1
            perfil_usuario.save()

            # calcular nivel actividad y de popularidad del Tema
            popularidad_actividad_tema(tema_contenedor, "positivo")

            return HttpResponseRedirect(reverse('temas:index_tema',
                                        kwargs={'slug': tema_contenedor.slug, 'queryset': u'recientes'}))

    form_nuevo_post = FormNuevoPost()
    tema_contenedor = get_object_or_404(Temas, slug=slug)

    context = {'form_nuevo_post': form_nuevo_post, 'tema': tema_contenedor}
    return render(request, template, context)
コード例 #4
0
ファイル: twitter.py プロジェクト: enhedslisten/samler
    def saveTweets(self, term):
        tweets = self.getTweetsJSON(term)
        return
        if not tweets:
            logging.info("Saved 0 tweets")
            return 0
            
        for tweet in tweets['statuses']:

            # Discard retweets
            if tweet.has_key('retweeted_status'):
                continue

            post = Posts()

            if not post.hasPost(tweet['id']):

                post.orig_post_id = int(tweet['id'])
                post.orig_user_id = int(tweet['user']['id'])
                post.date = int(time.mktime(time.strptime(tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y')))
                post.username = tweet['user']['screen_name']
                post.text = tweet['text']
                post.image_small = [tweet['entities']['media'][0]['media_url'] if 'media' in tweet['entities'] else ''][0]
                post.image_full = [tweet['entities']['media'][0]['media_url'] if 'media' in tweet['entities'] else ''][0]
                post.service = 'twitter'
                post.likes = None
                post.orig_url = None
                
                post.save()
コード例 #5
0
ファイル: views.py プロジェクト: Alexandrov-Michael/helpdesk
 def form_valid(self, form):
     name               = form.cleaned_data['name']
     description        = form.cleaned_data['description']
     new_obj            = Posts()
     new_obj.name       = name
     new_obj.decription = description
     new_obj.save()
     self.set_message(u'Должность успешно добавлена.')
     return super(AddPostView, self).form_valid(form)
コード例 #6
0
ファイル: views.py プロジェクト: Barolina/helpdesk
 def form_valid(self, form):
     name = form.cleaned_data['name']
     description = form.cleaned_data['description']
     new_obj = Posts()
     new_obj.name = name
     new_obj.decription = description
     new_obj.save()
     self.set_message(u'Должность успешно добавлена.')
     return super(AddPostView, self).form_valid(form)
コード例 #7
0
ファイル: views.py プロジェクト: prakhar673/learning_wall_app
def post(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post_body=form.cleaned_data['post_body']
            p=Posts(body=post_body,time=datetime.now(),user=request.user)
            p.save()
    return redirect('index')

    def like(request):
        p=Posts(body=post_body,time=datetime.now(),user=user)
        p.save()
    return redirect('index')
コード例 #8
0
def respuesta(request, slug, post_id):
    # Maneja la respuesta del usuario a un post. Cualquier post, sea respuesta o en video.
    tema = Temas.objects.get(slug=slug)
    if request.method == "POST":
        form = FormNuevoPost(request.POST)
        if form.is_valid():
            texto = form.cleaned_data.get('texto')
            perfil_usuario = Perfiles.objects.get(usuario=request.user)
            post_padre = Posts.objects.get(id=post_id)
            # Si es una respuesta a un post en un video
            if post_padre.video is not None:
                post_respuesta = Posts(texto=texto, es_respuesta=True,
                                       creador=perfil_usuario, tema=tema, video=post_padre.video)
            else:
                post_respuesta = Posts(texto=texto, es_respuesta=True,
                                       creador=perfil_usuario, tema=tema)

            post_respuesta.save()

            # Respuesta object
            respuesta_db = Respuestas(post_respuesta=post_respuesta,
                                      post_padre=post_padre)
            respuesta_db.save()

            #Notificacion respuesta
            if perfil_usuario != post_padre.creador:
                notificacion_respuesta = Notificacion(actor=perfil_usuario, target=post_padre.creador,
                                                      objeto_id=post_padre.id, tipo_objeto="post",
                                                      tipo_notificacion="comment")
                notificacion_respuesta.save()

            # Redirige a la pagina del post_video si pertenece a un video
            if post_padre.video is not None:
                return HttpResponseRedirect(reverse('videos:post_video',
                                                    kwargs={
                                                        'video_id': post_padre.video.id, 'slug': tema.slug,
                                                        'post_id': post_id,
                                                        'queryset': u'recientes'}))
            # Redirige a la pagina del post.
            else:
                return HttpResponseRedirect(reverse('temas:post',
                                                    kwargs={'slug': tema.slug, 'post_id': post_id,
                                                            'queryset': u'recientes'}))
    else:
        return HttpResponseRedirect(reverse('temas:post',
                                            kwargs={'slug': tema.slug, 'post_id': post_id,
                                                    'queryset': u'recientes'}))
コード例 #9
0
def addpost(request):
    if 'user_id' in request.session:
        types = Types.objects.all()
        if request.POST:
            user = Users.objects.get(pk=request.session['user_id'])
            job_type = Types.objects.get(pk=request.POST.get('job_type', None))
            post = Posts(title=request.POST.get('title', None),
                         description=request.POST.get('description', None),
                         address=request.POST.get('address', None),
                         created_by=user,
                         job_type=job_type,
                         organization=request.POST.get('organization', None),
                         hourly_rate=request.POST.get('hourly_rate', None))
            post.save()
            return HttpResponseRedirect("/post/")
        return render(request, 'advertisements/addpost.html', {"types": types})
    else:
        return render(request, 'advertisements/index.html')
コード例 #10
0
ファイル: views.py プロジェクト: mmosteit/django_forum
def new_post(request):


    new_username    = request.POST['username']
    new_post_text   = request.POST['post_text'] 
    new_date_posted = datetime.datetime.now()
    new_parent_id   = request.POST['parent_id']
    new_thread_id   = request.POST['thread_id']
   
   
    if new_username.strip() == "" or new_post_text.strip() == "":
        template = loader.get_template('forum/new_post_error.html')
        title    = "Error creating thread"
        context  = RequestContext(request,{"title":title,"thread_id":new_thread_id})
        return HttpResponse(template.render(context))  
   
    post = Posts(username = new_username, post_text = new_post_text, date_posted = new_date_posted, parent_id = new_parent_id, deleted = False, thread_id = new_thread_id)
    post.save()
    
    response = redirect('view_thread')
    response['Location'] += '?thread_id='+str(new_thread_id)
    return response
コード例 #11
0
    def saveMedia(self, term):
        media_json = self.getJSON(term)

        if not media_json:
            logging.info("Saved 0 media")
            return 0

        for media in media_json['data']:
            post = Posts()
            if not post.hasPost(int(media['id'].split('_')[0])):
                post.orig_post_id = int(media['id'].split('_')[0])
                post.orig_user_id = int(media['user']['id'])
                post.date = int(media['created_time'])
                post.username = media['user']['username']
                post.text = media['caption']['text']
                post.image_small = media['images']['low_resolution']['url']
                post.image_full = media['images']['standard_resolution']['url']
                post.service = 'instagram'
                post.likes = None
                post.orig_url = media['link']

                post.save()
コード例 #12
0
ファイル: instafetch.py プロジェクト: enhedslisten/samler
    def saveMedia(self, term):
        media_json = self.getJSON(term)

        if not media_json:
            logging.info("Saved 0 media")
            return 0
            
        for media in media_json['data']:
            post = Posts()
            if not post.hasPost(int(media['id'].split('_')[0])):
                post.orig_post_id = int(media['id'].split('_')[0])
                post.orig_user_id = int(media['user']['id'])
                post.date = int(media['created_time'])
                post.username = media['user']['username']
                post.text = media['caption']['text']
                post.image_small = media['images']['low_resolution']['url']
                post.image_full = media['images']['standard_resolution']['url']
                post.service = 'instagram'
                post.likes = None
                post.orig_url = media['link']
                
                post.save()
コード例 #13
0
ファイル: twitter.py プロジェクト: enhedslisten/samler
    def saveTweets(self, term):
        tweets = self.getTweetsJSON(term)
        return
        if not tweets:
            logging.info("Saved 0 tweets")
            return 0

        for tweet in tweets['statuses']:

            # Discard retweets
            if tweet.has_key('retweeted_status'):
                continue

            post = Posts()

            if not post.hasPost(tweet['id']):

                post.orig_post_id = int(tweet['id'])
                post.orig_user_id = int(tweet['user']['id'])
                post.date = int(
                    time.mktime(
                        time.strptime(tweet['created_at'],
                                      '%a %b %d %H:%M:%S +0000 %Y')))
                post.username = tweet['user']['screen_name']
                post.text = tweet['text']
                post.image_small = [
                    tweet['entities']['media'][0]['media_url']
                    if 'media' in tweet['entities'] else ''
                ][0]
                post.image_full = [
                    tweet['entities']['media'][0]['media_url']
                    if 'media' in tweet['entities'] else ''
                ][0]
                post.service = 'twitter'
                post.likes = None
                post.orig_url = None

                post.save()
コード例 #14
0
ファイル: postsDal.py プロジェクト: shebeerki/sharengrow
def createPost(postObj):
    print "in"
    try:
        user = Sngusers.objects.get(user=postObj.user)
    except:
        user=None
    posts = Posts(tag=postObj.tag,
                  title=postObj.title,
                  user = user,
                  content = postObj.content,
                  image = postObj.image,
                  
                               )
    if posts.save():
        return True
    else:
        return False
コード例 #15
0
ファイル: views.py プロジェクト: prakhar673/learning_wall_app
 def like(request):
     p=Posts(body=post_body,time=datetime.now(),user=user)
     p.save()