NicholasStudt

Changeset 349


Ignore:
Timestamp:
07/08/10 22:47:45 (2 months ago)
Author:
nicholas
Message:

Adding loging routines.
Adding File model to track files, this will allow for permissions.

Location:
Python/file_manager/trunk/file_manager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Python/file_manager/trunk/file_manager/models.py

    r334 r349  
     1from django.contrib.auth.models import User 
    12from django.db import models 
     3from django.utils.translation import ugettext as _ 
    24#from django.contrib import admin 
    35 
    46class File(models.Model): 
     7    TYPES = ( 
     8        ('S_IFSOCK', _('Socket')), 
     9        ('S_IFLNK', _('Symbolic link')), 
     10        ('S_IFREG', _('Regular file')), 
     11        ('S_IFBLK', _('Block device')), 
     12        ('S_IFDIR', _('Directory')), 
     13        ('S_IFCHR', _('Character device')), 
     14        ('S_IFIFO', _('FIFO')), 
     15    ) 
     16 
     17    # Path is relative to settings.DOCUMENT_ROOT 
     18    path = models.TextField() 
     19    name = models.CharField(max_length=250)   
     20    type = models.CharField(max_length=10, choices=TYPES) 
     21    
     22    # By default the person that created the file. 
     23    owner = models.ForeignKey(User)  
     24 
     25    # How should permissions be handled? 
     26    # What can a non-owner do? What can they not do? 
     27    # How is that represented? 
     28 
     29    #permissions = models.ManyToManyField(Permission, verbose_name=_('file permissions'), blank=True) 
     30 
    531    class Meta: 
    632        permissions = ( 
    7             ("can_create_file", "Can create file"), 
    8             ("can_update_file", "Can update file"), 
    9             ("can_copy_file", "Can copy file"), 
    10             ("can_upload_file", "Can upload file"), 
    11             ("can_delete_file", "Can delete file"), 
    12             ("can_rename_file", "Can rename file"), 
    13             ("can_move_file", "Can move file"), 
     33            ('can_create_file', _('Can create file')), 
     34            ('can_update_file', _('Can update file')), 
     35            ('can_copy_file', _('Can copy file')), 
     36            ('can_upload_file', _('Can upload file')), 
     37            ('can_delete_file', _('Can delete file')), 
     38            ('can_rename_file', _('Can rename file')), 
     39            ('can_move_file', _('Can move file')), 
    1440 
    15             ('can_create_symlink', 'Can create symlink'), 
    16             ('can_copy_symlink', 'Can copy symlink'), 
    17             ('can_move_symlink', 'Can move symlink'), 
    18             ('can_rename_symlink', 'Can rename symlink'), 
    19             ('can_delete_symlink', 'Can delete symlink'), 
     41            ('can_create_symlink', _('Can create symlink')), 
     42            ('can_copy_symlink', _('Can copy symlink')), 
     43            ('can_move_symlink', _('Can move symlink')), 
     44            ('can_rename_symlink', _('Can rename symlink')), 
     45            ('can_delete_symlink', _('Can delete symlink')), 
    2046 
    21             ("can_copy_dir", "Can copy directory"), 
    22             ("can_delete_dir", "Can delete directory"), 
    23             ("can_rename_dir", "Can rename directory"), 
    24             ("can_create_dir", "Can make directory"), 
    25             ("can_move_dir", "Can move directory"), 
     47            ('can_copy_dir', _('Can copy directory')), 
     48            ('can_delete_dir', _('Can delete directory')), 
     49            ('can_rename_dir', _('Can rename directory')), 
     50            ('can_create_dir', _('Can make directory')), 
     51            ('can_move_dir', _('Can move directory')), 
     52 
     53 
    2654        ) 
  • Python/file_manager/trunk/file_manager/utils.py

    r334 r349  
    118118    return os.path.join(*rel_list) 
    119119 
     120# From: django.contrib.admin.options 
     121def log_addition(request, object): 
     122    """ 
     123    Log that an object has been successfully added. 
     124 
     125    The default implementation creates an admin LogEntry object. 
     126    """ 
     127    from django.contrib.admin.models import LogEntry, ADDITION 
     128    LogEntry.objects.log_action( 
     129        user_id         = request.user.pk, 
     130        content_type_id = ContentType.objects.get_for_model(object).pk, 
     131        object_id       = object.pk, 
     132        object_repr     = force_unicode(object), 
     133        action_flag     = ADDITION 
     134    ) 
     135 
     136# From: django.contrib.admin.options 
     137def log_change(request, object, message): 
     138    """ 
     139    Log that an object has been successfully changed. 
     140 
     141    The default implementation creates an admin LogEntry object. 
     142    """ 
     143    from django.contrib.admin.models import LogEntry, CHANGE 
     144    LogEntry.objects.log_action( 
     145        user_id         = request.user.pk, 
     146        content_type_id = ContentType.objects.get_for_model(object).pk, 
     147        object_id       = object.pk, 
     148        object_repr     = force_unicode(object), 
     149        action_flag     = CHANGE, 
     150        change_message  = message 
     151    ) 
     152 
     153# From: django.contrib.admin.options 
     154def log_deletion(request, object, object_repr): 
     155    """ 
     156    Log that an object has been successfully deleted. Note that since the 
     157    object is deleted, it might no longer be safe to call *any* methods 
     158    on the object, hence this method getting object_repr. 
     159 
     160    The default implementation creates an admin LogEntry object. 
     161    """ 
     162    from django.contrib.admin.models import LogEntry, DELETION 
     163    from file_manager import models 
     164    LogEntry.objects.log_action( 
     165        user_id         = request.user.id, 
     166        content_type_id = ContentType.objects.get_for_model(models.File).pk, 
     167        object_id       = object.pk, 
     168        object_repr     = object_repr, 
     169        action_flag     = DELETION 
     170    ) 
Note: See TracChangeset for help on using the changeset viewer.