Programming in almost language

Thi s is the site where you may share your knowledge and experience to eachother..

Customize admin permission

Posted by Praveen Kumar on May 18, 2009

Here, i am writing all the possible customize admin function.
If a user belong to a specific city then he/she could add the events for that city except others
class

EventAdmin(admin.ModelAdmin):

model = events

# Attributes

list_display = (’title’, ‘event_type’,'city’,'join_name’)

list_display_links = (’title’, ‘event_type’,'city’)

list_filter = ['title','event_type','city','sites']

list_select_related = True

search_fields = ['title']

save_on_top = True

raw_id_fields = (’event_type’,'city’)

list_per_page = 2

prepopulated_fields = {’title’: (’summary’,'description’)}

fieldsets = (
(’Add Event’, {’fields’: (’title’,'event_type’,'city’,'visibility’,'highlighted’,’sites’), ‘classes’: (’wide’,)}),
(’Additional Information’, {’fields’ (’summary’,'description’,’start_date’,'end_date’,’start_Time’,'end_Time’,'admission’), ‘classes’: (’collapse’, ‘wide’)}),
(’Address Information’, {’fields’: (’contact_detail’,'booking_url’,'venue’,'address’,'phone’,'mobile’,'image’,'image_caption’), ‘classes’: (’collapse’, ‘wide’)}),
)

#A cool thing there is the ’site_list’ column. By default, we can’t use a ManyToManyField

def site_list(self):

if self.sites:

sites = [site.name for site in self.sites.all()]
string = “, “.join(sites)
return string

# To give the edit permission city wise

def has_change_permission(self, request, obj=None):

#if obj and request.user.groups.name == ‘Chicago’:

#city=request.user.get_profile().res_city

if obj:

return obj.city == request.user.get_profile().res_city

return super(EventAdmin, self).has_change_permission(request, obj)

# To give the add permission city wise

def has_add_permission(self, request):

#if obj and request.user.groups.name == ‘Chicago’:

#city=request.user.get_profile().res_city

if request.user.get_profile().res_city:

return super(EventAdmin, self).has_add_permission(request)

# To return the records city wise

def queryset(self, request):

#return self.model._default_manager.filter(city=’Chicago’)

return self.model._default_manager.filter(city=request.user.get_profile().res_city)( OR )

def queryset(self, request):

qs = super(EventAdmin, self).queryset(request)

if request.user.is_superuser:

qs = qs.filter(city=request.user.get_profile().res_city)

return qs

#return self.model._default_manager.filter(city=request.user.get_profile().res_city)

admin.site.register(events,EventAdmin)

Posted in Admin | Tagged: | Leave a Comment »

Shell Script for collecting information from domlogs.

Posted by Pratap on May 18, 2009

Write a scripts which can generate a output for all media/source files which has been downloaded in the month.

This is an easy way I found you may try ==============================================================

#!/bin/bash
filename1=/root/mail_body_file.txt # main file to copy media files name

filename2=/usr/local/apache/domlogs/user/domain.com #domlogs

filename3=/root/out_put.txt # raw out put

filename4=/root/output.txt # final out put

filename5=/root/mail_body_file2.txt # replaced ” ” with “%20″

filename6=/root/mail_body_file3.txt # temp dom log file for search

current_date=”echo `date`”

month=`date | awk ‘{print $2}’`

year=`date | awk ‘{print $6}’`

day=$month/$year
grep $day $filename2 > $filename6
echo “”>$filename3
echo “”>$filename1
echo “”>$filename4

#touch /root/mail_body_file.new
find /home/user/public_html/* -type f | grep -E \.mp3$ > $filename1
find /home/user/public_html/* -type f | grep -E \.midi$ >
mail_body_file.txt
find /home/user/public_html/* -type f | grep -E \.mid$ >>
mail_body_file.txt
find /home/user/public_html/* -type f | grep -E \.swf$ >>
mail_body_file.txt

sed ’s/ /%20/g’ $filename1 > $filename5
sed “s%\/home\/user\/public_html%\ %g” $filename5
> /root/mail_body_file.new
for i in `cat /root/mail_body_file.new`; #media file anme
do
count=0
for j in `cat $filename6`; # domlogs
do
if [ `echo $i` = `echo $j` ]; # matching string
then
count=`expr $count + 1`
fi
done
echo “$i”, $count >>$filename3 #storing the match in a file as raw output
sed ’s/%20/ /g’ $filename3 > $filename4 # output to send in mail
done
===========================================================

Posted in Learning Linux | Leave a Comment »