Skip to content

Commit

Permalink
hello world. again
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiD committed Jan 8, 2016
1 parent a024a2b commit 6316708
Show file tree
Hide file tree
Showing 26 changed files with 828 additions and 14 deletions.
19 changes: 19 additions & 0 deletions application/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import Flask
import logging
from flask.ext.cache import Cache
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask('application')

# app.config.from_object('config.ProductionConfig')
app.config.from_object('config.DevelopmentConfig')

db = SQLAlchemy(app)

cache = Cache(app, config={'CACHE_TYPE': 'simple'})
cache.init_app(app)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

import views
24 changes: 24 additions & 0 deletions application/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from threading import Thread
from functools import wraps
from flask import request, redirect, current_app

def threaded_async(f):
def wrapper(*args, **kwargs):
thr = Thread(target=f, args=args, kwargs=kwargs)
thr.start()
return wrapper


def ssl_required(fn):
@wraps(fn)
def decorated_view(*args, **kwargs):
if current_app.config.get("SSL"):
if request.is_secure:
return fn(*args, **kwargs)
else:
return redirect(request.url.replace("http://", "https://"))

return fn(*args, **kwargs)

return decorated_view

8 changes: 8 additions & 0 deletions application/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from wtforms import Form, StringField, TextAreaField, validators


class Form_Record_Add(Form):
title = StringField('title', validators=[validators.DataRequired(),
validators.Length(max=255, message='max 255 characters')])
description = TextAreaField('description',
validators=[validators.Length(max=200, message='max 200 characters')])
57 changes: 57 additions & 0 deletions application/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import datetime

from sqlalchemy import desc
from sqlalchemy import or_

from application import db


class SampleTable(db.Model):
__tablename__ = "SampleTasksTable"
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(255))
description = db.Column(db.Text())
added_time = db.Column(db.DateTime, default=datetime.datetime.now)

def get_id(self, some_id):
record = SampleTable.query.filter(SampleTable.id == some_id).first_or_404()
aux = dict()
aux['id'] = record.id
aux['title'] = record.title
aux['description'] = record.description
aux['added_time'] = record.added_time
return aux


def add_data(self, title, description):
new_record = SampleTable(title=title, description=description)
db.session.add(new_record)
db.session.commit()


def list_all(self, page, LISTINGS_PER_PAGE):
return SampleTable.query.order_by(desc(SampleTable.added_time)).paginate(page, LISTINGS_PER_PAGE, False)


# ------ Delete them if you don't plan to use them ----------

def benchmark_searchspeed(self):
# my very stupid benchmark
records = SampleTable.query.filter(
or_(SampleTable.description.like('%ab%'), SampleTable.description.like('%10%'))).order_by(
desc(SampleTable.added_time)).limit(500)
output = list()
for record in records:
second = SampleTable.query.filter(SampleTable.description.contains(record.title[0:1])).first()
if second:
aux = dict()
aux['id'] = second.id
aux['title'] = second.title
aux['description'] = second.description
aux['added_time'] = second.added_time
output.append(aux)
return output


def __str__(self):
return '<SampleTable %r, %s>' % (self.id, self.title)
7 changes: 7 additions & 0 deletions application/static/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* Main stylesheet */

/* @section forms */
.btn.cancel { margin-left: 0.5rem; }
.nowrap { white-space: nowrap; }

/* Your customizations here */
Binary file added application/static/img/favicon.ico
Binary file not shown.
Binary file added application/static/img/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions application/static/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var Utils = {
renderFieldErrorTooltip: function (selector, msg, placement) {
var elem;
if (typeof placement === 'undefined') {
placement = 'right'; // default to right-aligned tooltip
}
elem = $(selector);
elem.tooltip({'title': msg, 'trigger': 'manual', 'placement': placement});
elem.tooltip('show');
elem.addClass('error');
elem.on('focus click', function(e) {
elem.removeClass('error');
elem.tooltip('hide');
});
}
};

/* Your custom JavaScript here */
2 changes: 2 additions & 0 deletions application/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow:
19 changes: 19 additions & 0 deletions application/templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>not found</title>

<style>
body { text-align: center;}
h1 { font-size: 50px; }
body { font: 20px Constantia, 'Hoefler Text', "Adobe Caslon Pro", Baskerville, Georgia, Times, serif; color: #999; text-shadow: 2px 2px 2px rgba(200, 200, 200, 0.5); }
::-moz-selection{ background:#FF5E99; color:#fff; }
::selection { background:#FF5E99; color:#fff; }
details { display:block; }
a { color: rgb(36, 109, 56); text-decoration:none; }
a:hover { color: rgb(96, 73, 141) ; text-shadow: 2px 2px 2px rgba(36, 109, 56, 0.5); }
span[frown] { transform: rotate(90deg); display:inline-block; color: #bbb; }
</style>

<details>
<summary><h1>Not found</h1></summary>
<p><span frown>:(</span></p>
</details>
8 changes: 8 additions & 0 deletions application/templates/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}

{% block content %}
<h1>Aw, snap</h1>
<p>The server encountered an unexpected error.</p>
<p>Please try again later.</p>
{% endblock %}

61 changes: 61 additions & 0 deletions application/templates/add_record.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends "base.html" %}
{% block content %}




<div class="row">
<div class="col-lg-6">
<div class="well bs-component">
<form class="form-horizontal" method="post" action="">
<fieldset>
<legend>Add new expense</legend>
<div class="form-group">
<label for="user_ip" class="col-lg-4 control-label">Title</label>

<div class="col-lg-6">
{{ form.title (class="form-control") }}

{% for error in form.errors.title %} <br/>

<div class="alert alert-danger" style="display: inline-block">
{{ error }}
</div>
{% endfor %}
</div>
</div>

<div class="form-group">
<label for="user_agent" class="col-lg-4 control-label">Description</label>

<div class="col-lg-6">
{{ form.description (class="form-control") }}

{% for error in form.errors.description %} <br/>

<div class="alert alert-danger" style="display: inline-block">
{{ error }}
</div>
{% endfor %}
</div>
</div>

<div class="form-group">
<div class="col-lg-4 col-lg-offset-4">

<button type="submit" class="btn btn-primary">add new record</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>

</div>



</div>


{% endblock content %}
48 changes: 48 additions & 0 deletions application/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en" class="no-js">


{% set bootstrap_version = '3.3.4' %}
{% set jquery_version = '2.1.3' %}
{% set modernizer_version = '2.8.3' %}
{% set bootswatch_version = '3.3.2' %}
{% set bootswatch_theme = 'slate' %}



<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<title>{% block title%}Flask-Easy Template{% endblock %}</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/{{ bootstrap_version }}/css/bootstrap.min.css" rel="stylesheet" />
<link href="//netdna.bootstrapcdn.com/bootswatch/{{ bootswatch_version }}/{{ bootswatch_theme }}/bootstrap.min.css" rel="stylesheet" >

<link href="/static/css/main.css" rel="stylesheet" />
<link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.ico') }}">
{% block style_block %}{# page-specific CSS #}{% endblock %}
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/{{ modernizer_version }}/modernizr.min.js"></script>{# Modernizr must be here, above body tag. #}
{% block head_script %}{# defer-incapable JS block #}{% endblock %}
</head>
<body>

{% include 'includes/nav.html' %} {# pull in navbar #}

<div class="container" id="maincontent">
{% include 'includes/flash_message.html' %} {# page-level feedback notices #}
<div id="body_content">
{% block content %}{# main content area #}{% endblock %}
</div>
</div><!-- /container -->
<footer>
<div id="footer" class="container">
{% block footer %}{% endblock %}
</div><!-- /footer -->
</footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/{{ jquery_version }}/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/{{ bootstrap_version }}/js/bootstrap.min.js"></script>
<script src="/static/js/main.js"></script>
{% block tail_script %}{# defer-capable JS block #}{% endblock %}
{{ profiler_includes|safe }}
</body>
</html>
55 changes: 55 additions & 0 deletions application/templates/contact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% extends "base.html" %}
{% block content %}

<script src='https://www.google.com/recaptcha/api.js'></script>


{% if email_sent == False %}


<div id="contact_form" class="row">
<div class="col-8 col-sm-8 col-lg-8">



<h2>Got a Question ?</h2>

<p>We appreciate any feedback about your overall experience on our site or how to make it even better. Please fill in the below form with any comments and we will get back to you.</p>
<hr />

<form role="form" method="post" id="feedbackForm">
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Name">
<span class="help-block" style="display: none;">Please enter your name.</span>
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
<span class="help-block" style="display: none;">Please enter a valid e-mail address.</span>
</div>
<div class="form-group">
<textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
<span class="help-block" style="display: none;">Please enter a message.</span>
</div>

<div class="form-group" style="margin-top: 10px;">
<div class="g-recaptcha" data-sitekey="{{RECAPTCHA_SITE_KEY}}"></div>
</div>




<button type="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style="display: block; margin-top: 10px;">Send Feedback</button>
</form>
</div><!--/span-->
</div><!--/row-->



{% else %}

<hr/>
<h5>We have received your mail and will get back to you as soon as possible.</h5>

{% endif %}

{% endblock content %}
46 changes: 46 additions & 0 deletions application/templates/edit_example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% extends "base.html" %}

{% block content %}
<h3>Edit Example</h3>
<form id="edit-example" class="well"
action="{{ url_for('edit_example', example_id=example.key.id()) }}" method="post" accept-charset="utf-8">
<fieldset>
{{ form.hidden_tag() }}
<input type="hidden" name="mode" value="edit" />
<div class="control-group">
<div class="control-label">{{ form.example_name.label }}</div>
<div class="controls">
{{ form.example_name|safe }}
{% if form.example_name.errors %}
<ul class="errors">
{% for error in form.example_name.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
<div>&nbsp;</div>
<div class="control-group">
<div class="control-label">{{ form.example_description.label }}</div>
<div class="controls">
{{ form.example_description|safe }}
{% if form.example_description.errors %}
<ul class="errors">
{% for error in form.example_description.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
<div>&nbsp;</div>
<div class="control-group">
<div class="controls">
<input class="btn btn-primary" type="submit" value="Save Changes"/>
<a class="btn cancel" href="{{ url_for('list_examples') }}">Cancel</a>
</div>
</div>
</fieldset>
</form>
{% endblock content %}
Loading

0 comments on commit 6316708

Please sign in to comment.