Programming in almost language

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

Creating an alias as a non root user .

Posted by Pratap on August 3, 2009

Hi folks!!!

Many of you have faced the same problem for creating an alias of the frequently used command .

But here is another way to do it . It is not just to add alias using alias command which will enable the particular alias for particular session and console . I am not going to use alias command to create aliases .

I would suggest you (if you do not have root access ) to write a script which will help you to use it like an alias .

For example suppose you want to create the alias for telnet command , for root user it is easy to create , by adding a single line to .bashrc file but for a non-root user this is very handy .
-===========

vi t ### create a filename with t name

####add the following line to this file

telnet $1 $2

###save and quit :wq

chmod 777 t

now use the following command

./t yourdomain.com 25

#### voila it is working

Now it depends on you to choose it or reject it .
In the same way you can create many script for your aliases.

kdarious@gmail.com

Posted in Learning Linux | Tagged: | Leave a Comment »

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 »