예제 #1
0
파일: routes.py 프로젝트: SLDem/MySNSite
def private_messages(recipient):
    recipient = User.query.filter_by(username=recipient).first_or_404()
    page = request.args.get('page', 1, type=int)

    received_messages = current_user.messages_received.filter_by(
        author=recipient)
    sent_messages = current_user.messages_sent.filter_by(recipient=recipient)
    messages = received_messages.union(sent_messages).order_by(
        Message.timestamp).paginate(page, 15, False)

    next_url = url_for('private_messages',
                       recipient=recipient.username,
                       page=messages.next_num) if messages.has_next else None
    prev_url = url_for('private_messages',
                       recipient=recipient.username,
                       page=messages.prev_num) if messages.has_prev else None

    form = MessageForm()
    if form.validate_on_submit():
        message = Message(body=form.message.data,
                          author=current_user,
                          recipient=recipient)
        db.session.add(message)
        db.session.commit()
        flash('Message sent!')
        return redirect(
            url_for('private_messages', recipient=recipient.username))

    return render_template('private_messages.html',
                           title='Private Messages',
                           recipient=recipient,
                           form=form,
                           messages=messages.items,
                           next_url=next_url,
                           prev_url=prev_url)
예제 #2
0
def message(id):
    _user = User.query.filter_by(id=id).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        form_subject = form.subject.data
        form_message = form.body.data
        recipient = _user.email
        _message = "<p>You've received a new message from <a href='" + app.config[
            'HOST'] + url_for(
                'user', id=current_user.id
            ) + "'>" + current_user.name + "</a> on Marketplace.</p>"
        _message += '<p>Subject: ' + form_subject + '</p>'
        _message += '<p>Message: ' + form_message + '</p>'
        _message += '<p><a href="' + app.config['HOST'] + url_for(
            'message', id=current_user.id
        ) + '">Reply to ' + current_user.name + ' on Marketplace</a></p>'
        subject = "Message from " + current_user.name + " on Marketplace"
        send_email(subject, '*****@*****.**', [recipient],
                   _message, _message)
        flash('Message sent')
        return redirect(url_for('user', id=id))
    return render_template('message.html',
                           title='Send Message',
                           form=form,
                           user=_user,
                           current_user=current_user)
예제 #3
0
def newmessage():
    if not current_user.is_authenticated:
        return redirect(url_for('index'))

    form = MessageForm()
    if form.validate_on_submit():
        s_name = current_user.display_name
        s_id = current_user.id
        receiver = User.query.filter_by(
            username=form.receiver_name.data).first()
        r_id = receiver.id
        content = form.content.data
        msg = Message(body=content,
                      sender_id=s_id,
                      sender_name=s_name,
                      receiver_id=r_id)
        db.session.add(msg)
        db.session.commit()
        flash('Message Sent!')
        return redirect(url_for('inbox'))
    #else:
    #flash('Error creating message. Please try again')

    return render_template('newmessage.html',
                           title='Create Message',
                           form=form)
예제 #4
0
파일: routes.py 프로젝트: benzhang13/MyMLM
def user(username):
    user = User.query.filter_by(username=username).first_or_404()
    message_form = MessageForm()
    if message_form.validate_on_submit():
        message = Message(author=current_user,
                          recipient=user,
                          body=message_form.message.data)
        db.session.add(message)
        db.session.commit()
        user.add_notification('unread_message_count', user.new_messages())
        db.session.commit()
        flash('Your message has been sent!')
        return redirect(url_for('user', username=username))

    page = request.args.get('page', 1, type=int)
    schemes = user.schemes.order_by(Scheme.timestamp.desc()).paginate(
        page, app.config['SCHEMES_PER_PAGE'], False)
    next_url = url_for('index',
                       page=schemes.next_num) if schemes.has_next else None
    prev_url = url_for('index',
                       page=schemes.prev_num) if schemes.has_prev else None

    return render_template('user.html',
                           user=user,
                           schemes=schemes.items,
                           next_url=next_url,
                           prev_url=prev_url,
                           form=message_form)
예제 #5
0
def message_user(id_param):
    form = MessageForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    user = User.query.filter(User.id == current_user.id).first()
    user_to_message = User.query.filter(User.id == id_param).first()

    def message_info(self):
        return {
            "id": self.id,
            "read": self.read,
            "content": self.content,
            "recipient_id": self.recipient_id,
            "message_sender_id": self.message_sender_id,
            "created_at": self.created_at
        }

    if form.validate_on_submit():
        message_data = request.form.get('content')
        message = Message(
            read=False,
            content=message_data,
            recipient_id=user_to_message.id,
            message_sender_id=user.id,
        )
        db.session.add(message)
        db.session.commit()
        return message_info(message)
    return "Bad Data"
예제 #6
0
def messages(username):
    msg_to = User.query.filter_by(username=username).first_or_404()
    if msg_to.id == 1 or msg_to == current_user:  #Prevent chatting with admin or self
        return render_template('admin_restricted.html')
    form0 = SearchProfileForm()
    form = MessageForm()
    if form.validate_on_submit():
        message = Message(body=form.message.data,
                          author=current_user,
                          profile=msg_to)
        db.session.add(message)
        flash('Message sent!')

        ##add change to table
        prev_convo = None
        new_convo = None
        try:
            print('curstart')
            current_start = Conversation.query.filter_by(author=current_user,
                                                         profile=msg_to)
            print('msgstart')
            msg_to_start = Conversation.query.filter_by(author=msg_to,
                                                        profile=current_user)
            print('union')
            prev_convo = current_start.union(msg_to_start).first()
            print('set_tm')
            prev_convo.timestamp = message.timestamp
            print('finish try')
        except:
            print('new convo')
            new_convo = Conversation(author=current_user, profile=msg_to)
            db.session.add(new_convo)

        db.session.commit()
        return redirect(url_for('messages', username=username))
    page = request.args.get('page', 1, type=int)

    messages = current_user.msgs_btw(username).paginate(
        page, app.config['MESSAGES_PER_PAGE'], False)

    for message in messages.items:
        if message.author != current_user:
            message.seen = 1
    db.session.commit()

    next_url = url_for('messages', username = username, page = messages.next_num) \
        if messages.has_next else None
    prev_url = url_for('messages', username = username, page = messages.prev_num) \
        if messages.has_prev else None

    return render_template('messages.html',
                           title='Messages',
                           messages=messages.items,
                           form0=form0,
                           form=form,
                           user=msg_to,
                           badge_colour=badge_colour,
                           prev_url=prev_url,
                           next_url=next_url)
예제 #7
0
def rooms():
    form = MessageForm()
    if form.validate_on_submit():
        print(form.message.data)
        emit('message',
             {'msg': current_user.username + ':' + form.message.data})
        print(form.message.data)
    return render_template("rooms.html", title='Rooms', form=form)
예제 #8
0
 def post(self, request, *args, **kwargs):
     form = MessageForm(request.POST)
     if form.is_valid():
         message = form.save()
         message.save()
         messages = Message.objects.all()
         cache.set('messages', pickle.dumps(messages))
         return HttpResponseRedirect(reverse_lazy('app:message_list'))
     return HttpResponseRedirect(reverse_lazy('app:message_list'))
예제 #9
0
def mail():
    if current_user.is_authenticated:
        return redirect(url_for('mail'))
    form = MessageForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            MessageForm()
            flash('Mail send!')
예제 #10
0
def contact_seller(request):
    response = reply_object()
    form = MessageForm(request.POST, request=request)
    if form.is_valid():
        response = form.new_message()
    else:
        response["code"] = settings.APP_CODE["FORM ERROR"]
        response["errors"] = form.errors
    return HttpResponse(simplejson.dumps(response))
예제 #11
0
def home():
    """
    home page for managing sms messages
    """
    message_form = MessageForm()
    if message_form.validate_on_submit():
        send_message(message_form.message)
        flash('Message Sent!')

    return render_template('index.html', MessageForm=message_form)
예제 #12
0
def message(teacher_id):
    teacher = db.session.query(Teacher).get_or_404(teacher_id)
    form = MessageForm()

    if form.validate_on_submit():
        flash('Сообщение отправлено!', category='sent')
        return redirect(url_for('message', teacher_id=teacher.id))
        
    context = {'teacher': teacher}
    return render_template('message.html', form=form, **context)
예제 #13
0
def leave_message():
    form = MessageForm()
    if form.validate_on_submit():
        message = Message(body=form.message.data, user_id=current_user.id)
        db.session.add(message)
        db.session.commit()
        flash('You successfully leave a message to us!')
        return redirect(url_for('leave_message'))
    return render_template('leave_message.html',
                           title='Leave a Message',
                           form=form)
예제 #14
0
파일: views.py 프로젝트: jjzgood/sayhello
def index():
    messages = Message.query.order_by(Message.timestamp.desc()).all()
    form = MessageForm()
    if form.validate_on_submit():
        name = form.name.data
        body = form.body.data
        message = Message(name=name, body=body)
        db.session.add(message)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('index.html', form=form, messages=messages)
def send_message(recipient):
    user = User.query.filter_by(username=recipient).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(author=current_user, recipient=user,
                      body=form.message.data)
        db.session.add(msg)
        db.session.commit()
        flash('Your message has been sent.')
        return redirect(url_for('user', username=recipient))
    return render_template('/communication/send_message.html', title='Send Message', form=form, recipient=recipient)
예제 #16
0
def message_thread_add(request):
    if not request.POST:
        return HttpResponse("waiting")
    response = reply_object()
    form = MessageForm(request.POST, request=request)
    if form.is_valid():
        response = form.add_to_thread()
    else:
        response["code"] = settings.APP_CODE["FORM ERROR"]
        response["errors"] = form.errors
    return render_to_response("message_submit.html",
                              {"response_data": simplejson.dumps(response)})
예제 #17
0
def send_message(recipient):
    user = User.query.filter_by(username=recipient).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(author=current_user, recipient=user,\
                      body=form.message.data)
        db.session.add(msg)
        user.add_notification('unread_message_count', user.new_messages())
        db.session.commit()
        flash(('Your message has been sent.'))
        return redirect(url_for('user', username=recipient))
    return render_template('send_message.html', title=('Send Message'),\
                           form=form, recipient=recipient)
예제 #18
0
def send_message(recipient):
    user = User.query.filter_by(username=recipient).first()
    messageForm = MessageForm()

    if messageForm.validate_on_submit():
        message = Message(sender=current_user,
                          recipient=user,
                          body=messageForm.message.data)
        db.session.add(message)
        db.session.commit()
        user.add_notification('unread_message_count', user.new_messages())
        flash('Your message has been sent.')

    return render_template('send_message.html', messageForm=messageForm)
예제 #19
0
def send_message():
  try:
    if MessageForm().validate_on_submit():
      client.messages.create(
        body = MessageForm().message.data,
        from_ = str(app.config['TWILIO_NUMBER']),
        to = f"+1{MessageForm().send_to.data}"
      )
      flash("Message sent")
      return redirect(url_for('index'))
  except twilio.base.exceptions.TwilioRestException:
    flash("There seems to be an error. Try again later!")
    return redirect(url_for('index'))
  return redirect(url_for('index'))
예제 #20
0
def home():
    form=MessageForm()
    if form.validate_on_submit():
        # check if user exits in database
        # if not create user and add to database
        # create row in Message table with user (created/found) add to ta database

    posts = []
    # output all messages
    # create a list of dictionaries with the following structure
    # [{'author':'carlos', 'message':'Yo! Where you at?!'},
    #  {'author':'Jerry', 'message':'Home. You?'}]

    return render_template('home.html', posts=posts, form=form)
예제 #21
0
def upload():
    form = MessageForm()
    if form.validate_on_submit():
        if request.method == 'POST' and 'photo' in request.files:
            # filename = photos.save(request.files['photo'])
            url = Upload(request.files['photo'])
            punish = Punish(message=form.message.data,
                            to_user=form.to_user.data,
                            url=url)
            db.session.add(punish)
            db.session.commit()
            flash('You have submitted it!')
            return redirect(url_for('index'))
    return render_template('upload.html', title='Upload', form=form)
예제 #22
0
파일: auth.py 프로젝트: cuijianhui1998/blog
def say_me():
    '''
    留言
    '''
    leave_messages = Message.query.all()
    form = MessageForm(request.form)
    if request.method == 'POST' and form.validate():
        with db.submit_data():
            message = Message()
            message.leave_message = request.form.get('leave_message')
            db.session.add(message)
        return redirect(url_for('web.say_me'))
    return render_template('sayme.html',
                           form=form,
                           leave_messages=leave_messages)
예제 #23
0
def index():
    form = MessageForm()
    if form.validate_on_submit():
        uploaded_image = request.files['image']
        image_name = secure_filename(uploaded_image.filename)
        uploaded_file = request.files['file']
        file_name = secure_filename(uploaded_file.filename)
        if image_name != '' and file_name != '':
            file_ext = os.path.splitext(image_name)[1]
            if file_ext not in app.config['UPLOAD_EXTENSIONS']:
                return "Invalid image", 400
            uploaded_image.save(
                os.path.join(app.config['UPLOAD_PATH'], image_name))
            data_xls = pd.read_excel(uploaded_file)

            template = form_template(form)
            user_id = current_user.id
            attachment = os.path.join(app.config['UPLOAD_PATH'], image_name)
            body = form.message.data
            receiver_list = data_xls.dropna(subset=['numbers']).to_json()

            task = Task(user_id, template, attachment, body, receiver_list)

            flash('Hayırlı olsun!!')
            #return data_xls.to_html()
            #return redirect(url_for('index'))
            frozen = jsonpickle.encode(task)
            return frozen
        return '', 204

    files = os.listdir(app.config['UPLOAD_PATH'])
    user = {'username': '******'}
    messages = [{
        'author': {
            'username': '******'
        },
        'body': 'Beautiful day in Portland!'
    }, {
        'author': {
            'username': '******'
        },
        'body': 'The Avengers movie was so cool!'
    }]
    return render_template('index.html',
                           title='Home',
                           messages=messages,
                           form=form,
                           files=files)
예제 #24
0
def showStorage(storage_id, page=1):
    storage = Storage.query.filter_by(id=storage_id).first()
    found_count = Item.query.filter_by(store_location_id=storage.id,
                                       status='found').count()
    success_count = Item.query.filter_by(store_location_id=storage.id,
                                         status='success').count()
    page = request.args.get('page', 1, type=int)
    pagination = Item.query.filter_by(store_location_id=storage.id).order_by(
        Item.timestamp.desc()).paginate(page, per_page=10, error_out=False)
    items = pagination.items
    form = MessageForm()
    if current_user.group_id == 1:
        messages = Message.query.filter_by(store_location_id=storage_id,
                                           is_recieve=0).order_by(
                                               Message.timestamp.desc()).all()
        return render_template('storage_location.html',
                               current_user=current_user,
                               storage=storage,
                               found_count=found_count,
                               success_count=success_count,
                               items=items,
                               form=form,
                               messages=messages,
                               pagination=pagination)
    if form.validate_on_submit():
        message = Message(sender_id=current_user.id,
                          title=form.title.data,
                          content=form.content.data,
                          store_location_id=storage_id)
        db.session.add(message)
        success_send = 'You are succeed sending the message to this storage!'
        return render_template('storage_location.html',
                               current_user=current_user,
                               storage=storage,
                               found_count=found_count,
                               success_count=success_count,
                               items=items,
                               success_send=success_send,
                               form=form,
                               pagination=pagination)
    return render_template('storage_location.html',
                           current_user=current_user,
                           storage=storage,
                           pagination=pagination,
                           found_count=found_count,
                           success_count=success_count,
                           items=items,
                           form=form)
예제 #25
0
def home():
    """
    Create a home page for the message board.

    Display a form for users to post messages under their name. Post all messages
    for all visitors to see.

    Parameters
    ----------
    GET
        Method to request data.
    POST
        Method to send data.

    Returns
    -------
    Render the home.html template.
    """
    form = MessageForm()
    if form.validate_on_submit():
        # check if user exists in database
        # Determine who to link the message to
        user = User.query.filter_by(author=form.author.data).first()
        if user is None:
            # if not create user and add to database
            # Allow new users to post messages as well
            user = User(author=form.author.data)
            db.session.add(user)
            db.session.commit()
        # create row in Message table with user (created/found) add to the database
        message = Messages(message=form.message.data, user_id=user.id)
        db.session.add(message)
        db.session.commit()

    posts = []
    # output all messages
    # create a list of dictionaries with the following structure
    # [{'author':'carlos', 'message':'Yo! Where you at?!'},
    #  {'author':'Jerry', 'message':'Home. You?'}]
    # Follow format for collecting author name and message specified in the home.html template
    list = Messages.query.all()
    for m in list:
        posts.append({
            'author': User.query.get(m.user_id).author,
            'message': m.message
        })

    return render_template('home.html', posts=posts, form=form)
예제 #26
0
파일: views.py 프로젝트: zmadi1/env-matcha
def message():
    id = session.get('USER')

   
    id=session.get("USER")

    form = MessageForm()
    existing_user = find_id(id)
    existing_blog_post = find_blog_post(id)
    user = existing_user['username']

    rooms = []

    for i in existing_user['liked']:
        if i['id'] == 'like':
            other_user = find_user(i['owner'])
            for k in other_user['liked']:
                if k['id'] == 'like':
                    if k['owner'] == i['user']:
                        # print(k['owner'])
                        # print('--------------------------------')
                        # print(i['user'])
                        rooms.append(i['owner'])

    rooms = list(dict.fromkeys(rooms))
    
    msg = collection()


    return render_template('public/chat.html',rooms=rooms,msg=msg,form=form,existing_blog_post=existing_blog_post,existing_user=existing_user,id=id,user=user)
예제 #27
0
def send_message(recipient):
    """Funkcja wyświetlająca formularz wysyłania wiadomości prywatnej."""
    user = User.query.filter_by(username=recipient).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(author=current_user,
                      recipient=user,
                      body=form.message.data)
        db.session.add(msg)
        db.session.commit()
        flash(_('Your message has been sent.'))
        return redirect(url_for('user', username=recipient))
    return render_template('send_message.html',
                           title=_('Send Message'),
                           form=form,
                           recipient=recipient)
예제 #28
0
def chat():
    form = MessageForm()
    messageCnt = storage.getMessagesCount()
    postedMessage = sendMessage(form, info())
    pageStr = request.args.get('page')
    try:
        page = int(pageStr)
    except Exception:
        page = 0
    pageCnt = (messageCnt + MessagesOnPage - 1) // MessagesOnPage
    if (messageCnt):
        if (page < 0):
            page = pageCnt - 1
        if (page >= pageCnt):
            page = 0
    else:
        page = 0

    beginMessageId = max(0, messageCnt - (page + 1) * MessagesOnPage)
    endMessageId = messageCnt - page * MessagesOnPage
    messages = [useCasesAPI.getMessageDict(i) for i in range(beginMessageId, endMessageId)]
    if (postedMessage):
        return redirect("/chat")
    else:
        return render_template("chat.html.j2", title = "Chat", info = info(), **locals())
예제 #29
0
def meuform():
    form = MessageForm()
    messages = Message.query.all()

    if form.validate_on_submit():
        mensagem = Message()
        mensagem.name = form.name.data
        mensagem.text = form.text.data
        mensagem.user_id = 1

        db.session.add(mensagem)
        db.session.commit()

        return redirect('/meuform')

    return render_template("meuform.html", form=form, messages=messages)
예제 #30
0
def private_chat(recipient):
    user = User.query.filter_by(username=recipient).first_or_404()
    check_match(current_user.id, user.id)
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(author=current_user,
                      recipient=user,
                      body=form.message.data)
        db.session.add(msg)
        db.session.commit()
        flash('Your message has been sent')
        return redirect(url_for('private_chat', recipient=recipient))
    return render_template('private_chat.html',
                           title='Private Chat',
                           form=form,
                           recipient=recipient)
예제 #31
0
def home():
    form = MessageForm()
    if request.method == 'POST':
        if form.validate() == False:
            flash('Remplir tous les champs')
            return render_template('index.html', form=form)
        else:
            msg = Message(form.sujet.data,
                          sender='*****@*****.**',
                          recipients=['*****@*****.**'])
            msg.body = "Nom = {}, mail = {}, msg = {}".format(
                form.nom.data, form.email.data, form.message.data)
            mail.send(msg)
            return 'form_posted'

    elif request.method == 'GET':
        return render_template('index.html', form=form)
예제 #32
0
def send_message(recipient):
    user = User.query.filter_by(username=recipient).first_or_404()
    form = MessageForm()
    if form.validate_on_submit():
        msg = Message(author=current_user,
                      recipient=user,
                      body=form.message.data)
        db.session.add(msg)
        user.add_notification('unread_message_count', user.new_messages())
        db.session.commit()
        flash('Your message has been sent.', category='success')
        return redirect(url_for('user', username=recipient))
    return render_template('send_message.html',
                           title='Send Message',
                           form=form,
                           recipient=recipient,
                           refresh=app.config['PAGE_REFRESH'])
예제 #33
0
파일: user.py 프로젝트: crook/snippets
def send_mail(user_id):
    user = User.query.get_or_404(user_id)
    #user.permissions.send_message.test(403)
    form = MessageForm()
    if form.validate_on_submit():
        if setting.MAIL_ENABLE:
            body = render_template("emails/send_message.html",
                                   user=user,
                                   subject=form.subject.data,
                                   message=form.message.data)
            subject ="邮件来自 %s" % current_user.username
            message = Message(subject=subject,
                              body=body,
                              recipients=[user.email])
            mail.send(message)
            flash(u"给%s的邮件已发出" % user.username, "successfully")
        else:
            flash(u"邮件服务器未开启,请联系管理员", "error")
        return redirect(url_for("user.cases", username=user.username))
    return render_template("user/send_mail.html", user=user, form=form)