Skip to content

Instantly share code, notes, and snippets.

View arecker's full-sized avatar
🍕
my life is dope, and I have dope emacs configs

Alex Recker arecker

🍕
my life is dope, and I have dope emacs configs
View GitHub Profile
@arecker
arecker / weekly_report.html
Created November 13, 2015 01:00
Report Template
<moolah-card card-title="reportCtrl.cardTitle">
<canvas class="chart chart-line" chart-data="reportCtrl.data"
chart-labels="reportCtrl.labels" chart-legend="true" chart-series="reportCtrl.series">
</canvas>
</moolah-card>
@arecker
arecker / weekly_report.js
Created November 13, 2015 00:59
Report Directive
angular.module('moolah')
.controller('dailyTransactionreportController', ['ReportService', function(ReportService) {
var self = this;
self.cardTitle = 'This Week';
ReportService.dailyTransactionReport().success(function(d) {
self.data = d.data;
self.labels = d.labels;
@arecker
arecker / views.py
Created November 13, 2015 00:57
Weekly Report
class DailyTransactionReportView(views.APIView):
def _get_week_dates(self, weeks=-1):
today = get_timestamp()
monday = today + relativedelta(weekday=MO(weeks))
return [monday + timedelta(days=n)
for n in range(7)]
def get(self, request):
t = Transaction.objects
labels = ['Monday',
@arecker
arecker / views.py
Created November 13, 2015 00:56
report
from rest_framwork import views, response
from models import Tranaction
class SummaryView(views.APIView):
def get(self, request):
t = Transaction.objects
data = {'day': t.today().total(),
'week': t.last_week().total(),
'month': t.last_month().total(),
@arecker
arecker / resource.js
Created November 13, 2015 00:52
resource
angular.module('moolah').factory('TransactionService', ['$resource', 'API_URL', function($resource, API_URL) {
return $resource('{}transactions/:id'.format(API_URL));
}]);
@arecker
arecker / static.js
Created November 13, 2015 00:50
toStatic
angular.module('moolah')
.factory('toStatic', ['STATIC_URL', function(STATIC_URL) {
return function(i) {
return '{}{}'.format(STATIC_URL, i);
};
}]);
@arecker
arecker / index.html
Created November 13, 2015 00:47
Index constants
<script>
angular.module('moolah')
.constant('STATIC_URL', '/static/')
.constant('API_URL', '/api/')
.constant('LOGOUT_URL', '{% url 'django.contrib.auth.views.logout' %}')
.constant('USER_NAME', '{{ user.get_full_name }}');
</script>
from django.conf.urls import url
from django.views.generic import TemplateView
from django.contrib.auth.decorators import login_required
import routes
urlpatterns = [
'''... other rules...'''
@arecker
arecker / models.py
Last active November 13, 2015 01:34
Sanitize Dates
from dateutil import parser
def sanitize_dates(func):
'''
attempt to convert stringy dates
to real dates
'''
def wrapper(self, *args):
clean_args = []
@arecker
arecker / models.py
Created November 13, 2015 00:35
Transaction Manager
class TransactionQuerySet(models.QuerySet):
def total(self):
return self.aggregate(
models.Sum('amount'))['amount__sum'] or 0
def date(self, date):
return self.filter(timestamp__month=date.month,
timestamp__day=date.day,
timestamp__year=date.year)