Exemple #1
0
def view_rankings():
    # get the top movies by our users favourites
    # TODO: add different sorting methods
    movies = data.get_top_favourited_movies(auth.current_user_id())
    return flask.render_template('rankings.html',
                                 c={
                                     'user':
                                     auth.get_user_context(
                                         auth.current_user_id()),
                                     'movies':
                                     movies[:50]
                                 })
Exemple #2
0
def view_all_polls():
    polls = data.get_polls(auth.current_user_id())
    for poll in polls:
        poll['choices'] = list(poll['choices'].values())
        poll['choices'].sort(key=lambda x: x['vote_count'], reverse=True)
    return flask.render_template('polls.html',
                                 c={
                                     'user':
                                     auth.get_user_context(
                                         auth.current_user_id()),
                                     'polls':
                                     polls
                                 })
Exemple #3
0
def feedback():
  if not config.CONFIG_DB.feedback_email:
    return flask.abort(418)

  form = FeedbackForm(obj=auth.current_user_db())
  if form.validate_on_submit():
    mail.send_mail(
        sender=config.CONFIG_DB.feedback_email,
        to=config.CONFIG_DB.feedback_email,
        subject='[%s] %s' % (
            config.CONFIG_DB.brand_name,
            form.subject.data,
          ),
        reply_to=form.email.data or config.CONFIG_DB.feedback_email,
        body='%s\n\n%s' % (form.message.data, form.email.data)
      )
    flask.flash('Thank you for your feedback!', category='success')
    return flask.redirect(flask.url_for('countdown'))
  if not form.errors and auth.current_user_id() > 0:
    form.email.data = auth.current_user_db().email

  return flask.render_template(
      'feedback.html',
      title='Feedback',
      html_class='feedback',
      form=form,
    )
Exemple #4
0
def feedback():
  if not config.CONFIG_DB.feedback_email:
    return flask.abort(418)

  form = FeedbackForm()
  if form.validate_on_submit():
    mail.send_mail(
        sender=config.CONFIG_DB.feedback_email,
        to=config.CONFIG_DB.feedback_email,
        subject='[%s] %s' % (
            config.CONFIG_DB.brand_name,
            form.subject.data,
          ),
        reply_to=form.email.data or config.CONFIG_DB.feedback_email,
        body='%s\n\n%s' % (form.message.data, form.email.data)
      )
    flask.flash('Thank you for your feedback!', category='success')
    return flask.redirect(flask.url_for('welcome'))
  if not form.errors and auth.current_user_id() > 0:
    form.email.data = auth.current_user_db().email

  return flask.render_template(
      'feedback.html',
      title='Feedback',
      html_class='feedback',
      form=form,
    )
Exemple #5
0
def index():
    from main import FeedbackForm
    form = FeedbackForm()
    if form.validate_on_submit():
        feedback_email = model.Config.get_master_db().feedback_email
        try:
            if feedback_email:
                mail.send_mail(
                    sender=feedback_email,
                    to=feedback_email,
                    subject=u'[%s] - cообщение от %s' % (
                        model.Config.get_master_db().brand_name,
                        form.name.data,
                      ),
                    reply_to=form.email.data or feedback_email,
                    body=u'%s\n\n%s\n%s' % (form.feedback.data, form.email.data, form.contact.data)
                )
        except:
            pass
        flash(u'Спасибо за сообщение! Мы свяжемся с Вами в ближайшее время.', category='success')
        return redirect(url_for('contacts.index'))
    if not form.errors and auth.current_user_id() > 0:
        form.email.data = auth.current_user_db().email
    contacts = Contact.query(Contact.is_public == True).order(Contact.order_id)
    return render_template(
        'contacts/index.html',
        html_class='contacts_page',
        contacts=contacts,
        form=form
    )
Exemple #6
0
def view_all_polls():
    return flask.render_template('admin.html',
                                 c={
                                     'user':
                                     auth.get_user_context(
                                         auth.current_user_id()),
                                 })
def tournament_register(tournament_id, register_flag):
  tournament_db = model.Tournament.get_by_id(tournament_id)
  if not tournament_db:
    flask.abort(404)

  # TODO: Check if it's open for registrations first - george -> should we add an [open_for_registration] field ???

  user_tournament_db = model.UserTournament.get_or_insert(
      str(auth.current_user_id()),
      parent=tournament_db.key,
      tournament_key=tournament_db.key,
      user_key=auth.current_user_key(),
  )

  body = 'name: %s\nusername: %s\nemail: %s' % (
      auth.current_user_db().name,
      auth.current_user_db().username,
      auth.current_user_db().email,
  )
  creator_user_db = model.User.get_by_id(tournament_db.user_key.id())

  if register_flag == 'register':
    user_tournament_db.put()
    flask.flash('Awesome! You are in..', category='success')
    # how to send an email to -> creator_user_db.email
    # task.send_mail_notification('%s entered tournament %s' % (auth.current_user_db().name, tournament_db.name), body)
  elif register_flag == 'unregister':
    user_tournament_db.key.delete()
    flask.flash('Bummer! You are out..', category='info')
    # how to send an email to -> creator_user_db.email
    # task.send_mail_notification('%s left tournament %s' % (auth.current_user_db().name, tournament_db.name), body)

  return flask.redirect(flask.url_for('tournament_view', tournament_id=tournament_id))
Exemple #8
0
def user_update(user_id):
    user_db = model.User.get_by_id(user_id)
    if not user_db:
        flask.abort(404)

    form = UserUpdateForm(obj=user_db)
    if form.validate_on_submit():
        if not util.is_valid_username(form.username.data):
            form.username.errors.append('This username is invalid.')
        elif not is_username_available(form.username.data, user_db):
            form.username.errors.append('This username is taken.')
        else:
            form.populate_obj(user_db)
            if auth.current_user_id() == user_db.key.id():
                user_db.admin = True
                user_db.active = True
            user_db.put()
            return flask.redirect(flask.url_for('user_list',
                                                order='-modified'))

    if flask.request.path.startswith('/_s/'):
        return util.jsonify_model_db(user_db)

    return flask.render_template(
        'user/user_update.html',
        title=user_db.name,
        html_class='user-update',
        form=form,
        user_db=user_db,
    )
Exemple #9
0
def user_update(user_id):
  user_db = model.User.get_by_id(user_id)
  if not user_db:
    flask.abort(404)

  form = UserUpdateForm(obj=user_db)
  for permission in user_db.permissions:
    form.permissions.choices.append((permission, permission))
  form.permissions.choices = sorted(set(form.permissions.choices))
  if form.validate_on_submit():
    if not util.is_valid_username(form.username.data):
      form.username.errors.append('This username is invalid.')
    elif not model.User.is_username_available(form.username.data, user_db.key):
      form.username.errors.append('This username is already taken.')
    else:
      form.populate_obj(user_db)
      if auth.current_user_id() == user_db.key.id():
        user_db.admin = True
        user_db.active = True
      user_db.put()
      return flask.redirect(flask.url_for(
          'user_list', order='-modified', active=user_db.active,
        ))

  if flask.request.path.startswith('/_s/'):
    return util.jsonify_model_db(user_db)

  return flask.render_template(
      'user/user_update.html',
      title=user_db.name,
      html_class='user-update',
      form=form,
      user_db=user_db,
    )
Exemple #10
0
def view_search():
    # split the search terms up
    term_str = flask.request.args.get('q')
    terms = term_str.split(' ')
    # search the database for movies
    movies = data.search_movies(terms, auth.current_user_id())
    # render the results page
    return flask.render_template('search.html',
                                 c={
                                     'user':
                                     auth.get_user_context(
                                         auth.current_user_id()),
                                     'movies':
                                     movies[:50],
                                     'search_query':
                                     term_str
                                 })
Exemple #11
0
def view_index():
    # prompt the user to log in with facebook oauth2
    auth.try_login_user()
    # get movie db popular movies
    movies = data.get_popular_movies(auth.current_user_id())
    all_movies = data.get_all_movies()
    # render the index template with user and movies contexts
    return flask.render_template('index.html',
                                 c={
                                     'user':
                                     auth.get_user_context(
                                         auth.current_user_id()),
                                     'all_movies':
                                     all_movies,
                                     'movies':
                                     movies[:50],
                                 })
Exemple #12
0
def view_poll(poll_id):
    poll = data.get_poll(poll_id, current_user_id=auth.current_user_id())
    if not poll:
        return flask.redirect('/polls')
    # sort poll choices by vote count
    poll['choices'] = list(poll['choices'].values())
    poll['choices'].sort(key=lambda x: x['vote_count'], reverse=True)
    # get comments for the poll
    comments = data.get_poll_comments(poll_id)
    comments.sort(key=lambda x: x['timestamp'], reverse=True)
    return flask.render_template('poll.html',
                                 c={
                                     'user':
                                     auth.get_user_context(
                                         auth.current_user_id()),
                                     'poll':
                                     poll,
                                     'comments':
                                     comments
                                 })
Exemple #13
0
def vote_poll(poll_id, choice_id):
    # check if the user is logged in
    if not auth.is_authenticated():
        return json.dumps({
            'success': False,
            'message': 'You are not logged in'
        })
    data.change_poll_vote(auth.current_user_id(), poll_id, choice_id)
    return json.dumps({
        'success': True,
    })
Exemple #14
0
def view_user_favs(target_user_id):
    target_user = auth.get_user_context(target_user_id)
    # 404 if the use doesnt exist
    if target_user is None:
        return flask.abort(404)
    # get the target users favourite movies
    movies = data.get_fav_movies(target_user_id)
    movies = data.add_fav_count(movies)
    # flag our own favourite status for each of them
    movies = data.flag_fav_movies(movies, auth.current_user_id())
    # render the profile page
    return flask.render_template('profile_favourites.html',
                                 c={
                                     'user':
                                     auth.get_user_context(
                                         auth.current_user_id()),
                                     'target_user':
                                     target_user,
                                     'movies':
                                     movies[:50]
                                 })
Exemple #15
0
def grant_admin():
    # check if the user is logged in
    if not auth.is_authenticated():
        return json.dumps({
            'success': False,
            'message': 'You are not logged in'
        })
    data.grant_admin(auth.current_user_id())
    return json.dumps({
        'success': True,
        'message': ''
    })
Exemple #16
0
def new_comment():
    # check if the user is logged in
    if not auth.is_authenticated():
        return json.dumps({
            'success': False,
            'message': 'You are not logged in'
        })
    comment_body = flask.request.form.get('body')
    print('comment_body =', comment_body)
    poll_id = flask.request.form.get('poll')
    print('poll_id =', poll_id)
    data.create_comment(auth.current_user_id(), poll_id, comment_body)
    return flask.redirect('/poll/{}'.format(poll_id))
Exemple #17
0
def index():
    master_db = Config.get_master_db()
    if master_db.recaptcha_public_key and master_db.recaptcha_private_key:
        if not flask.request.headers.getlist("X-Forwarded-For"):
            ip = flask.request.remote_addr
        else:
            ip = flask.request.headers.getlist("X-Forwarded-For")[0]
        form = FeedbackCaptchaForm(captcha={
            'ip_address': ip,
            'public_key': master_db.recaptcha_public_key,
            'private_key': master_db.recaptcha_private_key
        })
        use_captcha = True
    else:
        form = FeedbackForm()
        use_captcha = False
    if form.validate_on_submit():
        feedback = Feedback()
        form.populate_obj(feedback)
        feedback.put()
        feedback_email = master_db.feedback_email
        managers = Manager.query()
        if feedback_email and managers:
            subject = u'[%s] Сообщение - %s' % (
                master_db.brand_name,
                form.subject.data
            )
            body = u'%s\n\n%s' % (form.feedback.data, form.email.data)
            for manager in managers:
                if manager.email and manager.is_mailable:
                    emails = collect_emails(manager.email)
                    for email in emails:
                        mail.send_mail(
                            sender=master_db.feedback_email,
                            to=email,
                            subject=subject,
                            reply_to=form.email.data or master_db.feedback_email,
                            body=body
                        )
        flask.flash(u'Спасибо за Ваш отзыв!', category='success')
        return flask.redirect(flask.url_for('pages.index'))
    if not form.errors and current_user_id() > 0:
        form.email.data = current_user_db().email
    return flask.render_template(
        'feedback/index.html',
        title=u'Обратная связь',
        html_class='feedback',
        form=form,
        use_captcha=use_captcha
    )
Exemple #18
0
def index():
    master_db = Config.get_master_db()
    if master_db.recaptcha_public_key and master_db.recaptcha_private_key:
        if not flask.request.headers.getlist("X-Forwarded-For"):
            ip = flask.request.remote_addr
        else:
            ip = flask.request.headers.getlist("X-Forwarded-For")[0]
        form = FeedbackCaptchaForm(
            captcha={
                'ip_address': ip,
                'public_key': master_db.recaptcha_public_key,
                'private_key': master_db.recaptcha_private_key
            })
        use_captcha = True
    else:
        form = FeedbackForm()
        use_captcha = False
    if form.validate_on_submit():
        feedback = Feedback()
        form.populate_obj(feedback)
        feedback.put()
        feedback_email = master_db.feedback_email
        managers = Manager.query()
        if feedback_email and managers:
            subject = u'[%s] Сообщение - %s' % (master_db.brand_name,
                                                form.subject.data)
            body = u'%s\n\n%s' % (form.feedback.data, form.email.data)
            for manager in managers:
                if manager.email and manager.is_mailable:
                    emails = collect_emails(manager.email)
                    for email in emails:
                        mail.send_mail(sender=master_db.feedback_email,
                                       to=email,
                                       subject=subject,
                                       reply_to=form.email.data
                                       or master_db.feedback_email,
                                       body=body)
        flask.flash(u'Спасибо за Ваш отзыв!', category='success')
        return flask.redirect(flask.url_for('pages.index'))
    if not form.errors and current_user_id() > 0:
        form.email.data = current_user_db().email
    return flask.render_template('feedback/index.html',
                                 title=u'Обратная связь',
                                 html_class='feedback',
                                 form=form,
                                 use_captcha=use_captcha)
Exemple #19
0
def feedback():
    if not config.CONFIG_DB.feedback_email:
        return flask.abort(418)

    form = FeedbackForm()
    if form.validate_on_submit():
        mail.send_mail(
            sender=config.CONFIG_DB.feedback_email,
            to=config.CONFIG_DB.feedback_email,
            subject="[%s] %s" % (config.CONFIG_DB.brand_name, form.subject.data.strip()),
            reply_to=form.email.data.strip() or config.CONFIG_DB.feedback_email,
            body="%s\n\n%s" % (form.message.data.strip(), form.email.data.strip()),
        )
        flask.flash("Thank you for your feedback!", category="success")
        return flask.redirect(flask.url_for("welcome"))
    if not form.errors and auth.current_user_id() > 0:
        form.email.data = auth.current_user_db().email

    return flask.render_template("feedback.html", title="Feedback", html_class="feedback", form=form)
Exemple #20
0
def create_poll():
    # check if the user is logged in
    if not auth.is_authenticated():
        return json.dumps({
            'success': False,
            'message': 'You are not logged in'
        })
    poll_title = flask.request.args.get('title')
    poll_desc = flask.request.args.get('description')
    poll_choices = []
    for i in range(1, 25):
        pc = flask.request.args.get('choice' + str(i))
        if not pc:
            break
        poll_choices.append(pc)
    # remove duplicates
    poll_choices = list(dict.fromkeys(poll_choices))
    poll_id = data.create_poll(auth.current_user_id(), poll_title, poll_desc, poll_choices)
    return flask.redirect('/poll/{}'.format(poll_id))
Exemple #21
0
                subject=u'[%s] - Заказ экскурсии [%s]' % (
                    model.Config.get_master_db().brand_name,
                    order.excursion_name
                ),
                reply_to=form.email.data or feedback_email,
                body=u'Имя: %s\nEmail: %s\nТелефон: %s\nДата: %s\nКол-во человек: %s\nДоп. информация: %s\n' % (
                    order.name,
                    order.email,
                    order.telephone,
                    order.date,
                    order.people_count,
                    order.additional_info
                )
            )
        except Exception, e:
            flash(u'Не удалось обработать заказ, попробуйте повторить чуть позже.', category='error')
            logging.error(str(e))
        else:
            flash(u'Спасибо за заказ! Мы свяжемся с Вами в ближайшее время.', category='success')
        return redirect(url_for('services.excursion', key_id=key_id, uid=uid))
    if not form.errors and auth.current_user_id() > 0:
        form.email.data = auth.current_user_db().email
    return render_template(
        'services/excursion.html',
        html_class='services_page',
        active_element='excursions',
        excursion_type=excursion_type,
        excursion = excursion,
        form = form
    )