From 11a18b6abae6ef99d1761f107e8078e1d199bfd4 Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Sun, 18 Mar 2012 02:29:49 +0100 Subject: [PATCH] Adds FB picture sync script and UI fixes --- scripts/facebook_sync.py | 45 +++++++++++++++++++++++++++++ static/gaute/sass/screen.scss | 26 ++++++++++++++--- static/gaute/stylesheets/screen.css | 26 ++++++++++++++--- static/js/register.js | 24 ++++++++++++++- templates/deposit.html | 7 +++-- templates/register.html | 10 ++++--- 6 files changed, 122 insertions(+), 16 deletions(-) create mode 100755 scripts/facebook_sync.py diff --git a/scripts/facebook_sync.py b/scripts/facebook_sync.py new file mode 100755 index 0000000..bf9365a --- /dev/null +++ b/scripts/facebook_sync.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# coding: utf-8 + +""" +This script fetches the members of the KAK facebook group, matches names against the local db, and then saves the users facebook-picture in his/her user profile. + +REQ: +https://github.com/iplatform/pyFaceGraph +INSTALL: +$ pip install pyfacegraph +""" + +import os,sys,difflib +from facegraph import Graph + +ACCESS_TOKEN = '' +PATH = '.' +KAK_GROUP_ID = '108265352570560' +if PATH not in sys.path: + sys.path.append(PATH) + +from django.core.management import setup_environ +import settings + +setup_environ(settings) + +from main.models import * + +g = Graph(ACCESS_TOKEN) +members = g[KAK_GROUP_ID]['members']() +group_members = [(member.name,member.id) for member in members.data] +names = [] # to fuzzy search for a name +name_lookup = {} # to update the matching UserProfile object +for u in User.objects.all().order_by('id'): + fullname = u.first_name + " " + u.last_name + names.append(fullname) + name_lookup[fullname] = u.id + +for member in group_members: + match = difflib.get_close_matches(member[0], names, 1) # max 1 match + if match: + u = UserProfile.objects.get(pk=name_lookup[match[0]]) + u.image = 'https://graph.facebook.com/{0}/picture'.format(member[1]) + u.save() + diff --git a/static/gaute/sass/screen.scss b/static/gaute/sass/screen.scss index 0bb3720..bdac027 100644 --- a/static/gaute/sass/screen.scss +++ b/static/gaute/sass/screen.scss @@ -10,15 +10,20 @@ body { @include inline-block-list; li { - padding: 1.5em; + padding-right: 10px; + padding-top: 10px; text-align: center; - width: 100px; + width: 79px; &:hover { background-color: #dddddd; } &.marked { - background-color: #dddddd; + color: #468847; + background-color: #DFF0D8; + } + .name { + font-weight: bold; } } } @@ -30,12 +35,25 @@ body { @include inline-block-list; li { - padding: 1.5em; + padding-top: 10px; + padding-left: 20px; + padding-right: 20px; text-align: center; &:hover { background-color: #dddddd; } + &.marked { + color: #468847; + background-color: #DFF0D8; + } + .qty { + font-size: 1.7em; + font-weight: bold; + } + .name { + font-weight: bold; + } } } } diff --git a/static/gaute/stylesheets/screen.css b/static/gaute/stylesheets/screen.css index 4c20b4b..893daa7 100644 --- a/static/gaute/stylesheets/screen.css +++ b/static/gaute/stylesheets/screen.css @@ -4118,15 +4118,20 @@ body #customer ul li { *display: inline; } body #customer ul li { - padding: 1.5em; + padding-right: 10px; + padding-top: 10px; text-align: center; - width: 100px; + width: 79px; } body #customer ul li:hover { background-color: #dddddd; } body #customer ul li.marked { - background-color: #dddddd; + color: #468847; + background-color: #DFF0D8; +} +body #customer ul li .name { + font-weight: bold; } body #register #products ul { margin: 0; @@ -4156,12 +4161,25 @@ body #register #products ul li { *display: inline; } body #register #products ul li { - padding: 1.5em; + padding-top: 10px; + padding-left: 20px; + padding-right: 20px; text-align: center; } body #register #products ul li:hover { background-color: #dddddd; } +body #register #products ul li.marked { + color: #468847; + background-color: #DFF0D8; +} +body #register #products ul li .qty { + font-size: 1.7em; + font-weight: bold; +} +body #register #products ul li .name { + font-weight: bold; +} body #register #total div { color: #ffffff; background-color: #222; diff --git a/static/js/register.js b/static/js/register.js index ba1fbe0..f293fcd 100644 --- a/static/js/register.js +++ b/static/js/register.js @@ -5,6 +5,21 @@ $(document).ready(function() { $(this).show(); }); } + function enable_all_products() { + $("li.product").each(function(i) { + $(this).removeClass("marked"); + $(this).show(); + }); + } + function reset_qtys() { + $(".qty").each(function(i) { + $(this).html('0'); + }); + + $("input[name$=amount]").each(function(i) { + $(this).val("0"); + }); + } function filter_customers(typed) { /* FIXME: Does not work well. */ setTimeout(function() { @@ -42,9 +57,14 @@ $(document).ready(function() { }); /* Product amount controls */ $("li.product").click( function() { - var form_field = $(this).children("input[type=text]"); + /* Mark the product as selected */ + $(this).addClass("marked"); + /* Update amounts */ + var form_field = $(this).children("input[name$=amount]"); + var display = $(this).children(".qty"); var qty = Number(form_field.val()) + 1; form_field.val(qty); + display.html(qty); /* Update total*/ var sale_price_int = Number($(this).children("span.sale_price_int").text()); var cur_total = Number($("span.total_text").text()) @@ -56,6 +76,8 @@ $(document).ready(function() { $("#id_customer_typeahead").val(""); $("span.total_text").html(""); enable_all_customers(); + enable_all_products(); + reset_qtys(); }); /* Hide alert messages */ $("a[data-dismiss=alert]").click(function(){ diff --git a/templates/deposit.html b/templates/deposit.html index c95fd7c..74c3e6f 100644 --- a/templates/deposit.html +++ b/templates/deposit.html @@ -28,11 +28,12 @@ {% for user in users %}
  • {% if user.get_profile.image %} -  
    +  
    {% else %} -  
    +  
    {% endif %} - {{ user.first_name }} {{ user.last_name|slice:":1"}} ({{ user.get_profile.balance }}) + {{ user.first_name }} {{ user.last_name|slice:":1"}}
    + {{ user.get_profile.balance }}
  • diff --git a/templates/register.html b/templates/register.html index 32b45b1..0087b3e 100644 --- a/templates/register.html +++ b/templates/register.html @@ -35,11 +35,12 @@ {% for user in users %}
  • {% if user.get_profile.image %} -  
    +  
    {% else %} -  
    +  
    {% endif %} - {{ user.first_name }} {{ user.last_name|slice:":1"}} ({{ user.get_profile.balance }}) + {{ user.first_name }} {{ user.last_name|slice:":1"}}
    + {{ user.get_profile.balance }}
  • @@ -60,8 +61,9 @@