Planet LUG-Jaipur

May 09, 2012

Rag Sagar (ragsagar)

ragsagar

While i was working on the project onspot_v2, i came across with a specific need. onspot_v2 makes use of the django admin interface for data entry. When employees are entering data, ‘branch’ field in the form will get populated automatically as per the branch of the employee. When a manager is entering data using the form, an extra field should appear to select the ‘branch’ instead of automatically populating. Googling didn’t help much. Finally i thought of overriding the ModelAdmin.add_view() method which is invoked when you try to add an entry using the admin. I changed the editable property of the field ‘branch’ inside after checking the request.user and it worked out. Part of my code in admin.py

from django.contrib import admin
from books.models import Agent, PolicyIssue

class PolicyIssueAdmin(admin.ModelAdmin):
 
    def add_view(self, request, form_url='', extra_context=None):
        if request.user.get_profile().is_employee:
            self.model.branch.field.editable = False
        else:
            self.model.branch.field.editable = True
        return super(PolicyIssueAdmin, self).add_view(request, form_url)

admin.site.register(PolicyIssue, PolicyIssueAdmin)


by Rag Sagar.V രാഗ് സാഗര്‍.വി at May 09, 2012 05:22 PM

April 28, 2012

Shakthi Kannan (mbuf)

Disassembly of HP Pavilion dv6000

Some pictures of a used HP Pavilion dv6000 which had a fried motherboard:

Keyboard removed
Keyboard
Metal casing
TFT
Without the TFT
Motherboard

April 28, 2012 02:45 PM

April 27, 2012

Lalith Suresh (nightstrike_)

April 25, 2012

Shakthi Kannan (mbuf)

ghc-data-reify

data-reify provides a way to turn recursive data structures into graphs. It is now available in Fedora. Install it using:
 $ sudo yum install ghc-data-reify-devel
A list [1,2,3] can be written using Cons, Nil, and In for recursion using:
In (Cons 1 (In (Cons 2 (In (Cons 3 (In Nil))))))
An example when using data-reify for the above is given below:
{-# LANGUAGE TypeFamilies #-}
module Main where

import Control.Applicative hiding (Const)

import Data.Reify
import Control.Monad

data List a b = Nil | Cons a b
  deriving Show

instance MuRef [a] where
  type DeRef [a] = List a 

  mapDeRef f (x:xs) = Cons x $> f xs
  mapDeRef f []     = pure Nil

main = do
        let g1 = [1, 2, 3]
        reifyGraph g1 >>= print
Compile it using:
$ ghc --make Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test ...
Run it using:
$ ./Test
let [(1,Cons 1 2),(2,Cons 2 3),(3,Cons 3 4),(4,Nil)] in 1

April 25, 2012 10:10 AM

April 24, 2012

Shakthi Kannan (mbuf)

ghc-dotgen

dotgen provides a a simple interface for generating .dot graph files. It is now available in Fedora. Install it along with graphviz using:
 $ sudo yum install ghc-dotgen-devel graphviz
A binary search tree example is shown below:
module Main where

import Text.Dot

box label = node $ [ ("shape","record"),("height",".1"),("label",label) ]

main = putStrLn $ showDot $ do
     c0 - box " | G| "
     c1 - box " | E| "
     c2 - box " | B| "
     c3 - box " | F| "
     c4 - box " | R| "
     c5 - box " | H| "
     c6 - box " | Y| "
     c7 - box " | A| "
     c8 - box " | C| "

     c0 .->. c4
     c0 .->. c1
     c1 .->. c2
     c1 .->. c3
     c2 .->. c8
     c2 .->. c7
     c4 .->. c6
     c4 .->. c5

     return ()
Compile, and run it using:
$ ghc --make Test.hs
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test ...

$ ./Test > test.dot
You can convert the generated .dot graph file into .png using:
$ dot -Tpng test.dot -o test.png
A screenshot of the generated png:
binary search tree screenshot

April 24, 2012 07:40 AM