Commits

b7w committed 83fd3a4 Merge

Merge dev

Comments (0)

Files changed (11)

 # The short X.Y version.
 version = '1.3'
 # The full version, including alpha/beta/rc tags.
-release = '1.3.0'
+release = '1.3.1'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.

docs/ref/settings.rst

 
 
 
+.. _SETTINGS_FILES_MESSAGE:
+
+LIMITED_FILES_MESSAGE
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Default: ``u"This name of file '{0}' is not allowed for upload!"``
+
+| Message to show if file is not allowed for upload. Look :ref:`SETTINGS_FILES_ALLOWED`.
+  Put '{0}' for place of file name. Be careful, string must be unicode.
+
+
+
+
 .. _SETTINGS_SERVE:
 
 LIMITED_SERVE

docs/releases/notes.rst

 ====================================
 
 
+1.3.1
+------------------------------------
+
+| Fix some strong bugs. Move error message on uploading not allowed file names
+  to settings :ref:`SETTINGS_FILES_MESSAGE`. Now it can be easy to tell user where error is.
+
+* Fix wrong message on uploading not allowed file names.
+* Fix encoding problems in mail notify.
+* Fix profile creation only on LUser add.
+
+
 1.3.0
 ------------------------------------
 

limited/core/feeds.py

     Base feed for History objects
     Need to override get_object method.
     """
-    title = "User feed"
-    link = "/"
-    description = "Some history events"
+    title = u"User feed"
+    link = u"/"
+    description = u"Some history events"
 
     def get_object(self, request, *args, **kwargs):
         raise NotImplemented()
         return obj
 
     def item_title(self, item):
-        return ", ".join(item.files)
+        return u", ".join(item.files)
 
     def item_description(self, item):
-        return "{0} by {1}".format(item.get_type_display(), item.user).capitalize()
+        return u"{0} by {1}, in '{2}'".format(item.get_type_display(), item.user, item.path or u'/').capitalize()
 
     def item_link(self, item):
-        return urlbilder("browser", item.lib_id, p=item.path, hl=item.hash())
+        return urlbilder(u"browser", item.lib_id, p=item.path, hl=item.hash())
 
     def item_pubdate(self, item):
         return item.time
     def get_object(self, request, hash, lib_id):
         user = Profile.objects.get(rss_token=hash).user
 
-        # If none, it raise Home.DoesNotExist
-        if settings.LIMITED_ANONYMOUS:
-            Home.objects.select_related('lib').get(Q(user=user) | Q(user=settings.LIMITED_ANONYMOUS_ID), lib__id=lib_id)
-        else:
-            Home.objects.select_related('lib').get(user=user, lib__id=lib_id)
+        count = Home.objects.select_related('lib').filter(Q(user=user) | Q(user=settings.LIMITED_ANONYMOUS_ID), lib__id=lib_id).count()
+        if not count:
+            raise Home.DoesNotExist()
 
         history = History.objects.\
                   select_related('user').\

limited/core/models.py

         ordering = ["username"]
         proxy = True
         verbose_name = 'User'
-        verbose_name_plural = 'Users'
+        verbose_name_plural = 'Users'
+
+post_save.connect( create_profile, sender=LUser )

limited/core/settings.py

 # Allow and block some regex patterns.
 # It is highly needed to set pattern in unicode!
 LIMITED_FILES_ALLOWED = getattr( settings, 'LIMITED_FILES_ALLOWED', {
-    'ONLY': [u'^[А-Яа-я\w\.\(\)\+\- ]+$', ],
+    'ONLY': [u'^[А-Яа-я\w\.\(\)\+\- ]+$', ],
     'EXCEPT': [u'.+\.rar', ],
     } )
 
+# Message to show if file is not allowed
+# '{0}' - place for file name
+LIMITED_FILES_MESSAGE = getattr( settings, 'LIMITED_FILES_MESSAGE',
+    u"This name of file '{0}' is not allowed for upload!" )
+
 # Set backend for serving files
 # Now only default and nginx
 LIMITED_SERVE = getattr( settings, 'LIMITED_SERVE', {

limited/core/static/limited/js/actions.js

     } );
 }
 
-function handleFileSelect(event, allowed, except) {
+function handleFileSelect(event, allowed, except, message) {
     var files = event.target.files;
     var allowed = allowed.split( '|' );
     var except = except.split( '|' );
             }
         }
         if (flag == true) {
-            NotifyError( "This type of file '" + f.name + "' is not allowed for upload!" )
+            NotifyError( message.replace('{0}', f.name) )
         }
     }
     if (flag == true) {

limited/core/templates/limited/files.html

     var fl = document.getElementById( 'files' )
     if (fl != null) {
         fl.addEventListener( 'change', function(ev) {
-            handleFileSelect( ev, "{{ allowed.only }}", "{{ allowed.except }}" )
+            handleFileSelect( ev, "{{ allowed.only }}", "{{ allowed.except }}", "{{ allowed.message }}" )
         }, false );
     }
 </script>

limited/core/tests/views.py

             """
             resp = self.client.get( link )
             assert resp.status_code == 200
-            assert unicode( resp.content ).count( u"<item>" ) == count, unicode( resp.content ).count( u"<item>" )
+            assert unicode( resp.content, errors='ignore' ).count( u"<item>" ) == count
 
         link_anon = urlbilder( 'rss.user.anon' )
         link_all = urlbilder( 'rss.user.all', rss_token )

limited/core/utils.py

     def run(self):
         assert self.title and self.body and self.user_from
         if self.files:
-            self.body += '\n'
-            self.body += 'Files:\n'
-            self.body += '\n'.join(map(lambda x: ' * ' + x, self.files))
+            self.body += u'\n'
+            self.body += u'Files:\n'
+            self.body += u'\n'.join(map(lambda x: u' * ' + x, self.files))
         try:
             emails = self.emails or self.get_emails()
             data = [(self.title, self.body, self.user_from, (email,),) for email in emails]

limited/core/views.py

         allowed = {}
         allowed['only'] = '|'.join( settings.LIMITED_FILES_ALLOWED["ONLY"] ).replace( '\\', '\\\\' )
         allowed['except'] = '|'.join( settings.LIMITED_FILES_ALLOWED["EXCEPT"] ).replace( '\\', '\\\\' )
+        allowed['message'] = settings.LIMITED_FILES_MESSAGE
 
         rss_token = None if user.is_anonymous() else Profile.objects.get(user=user).rss_token
 
             files = request.FILES.getlist( u'files' )
 
             if not len( files ):
-                messages.warning( request, "No any files selected" )
+                messages.warning( request, u"No any files selected" )
                 return HttpResponseReload( request )
 
             for file in files:
                 if not check_file_name( file.name ):
-                    raise PermissionError( u"This name of file '{0}' is not allowed for upload!".format( file.name ) )
+                    raise PermissionError( settings.LIMITED_FILES_MESSAGE.format( file.name ) )
 
             history = History( user=user, lib=home.lib, type=History.UPLOAD, path=path )
 
 
             if settings.LIMITED_EMAIL_NOTIFY['ENABLE']:
                 domain = Site.objects.get_current( ).domain
-                link = urlbilder( "browser", lib_id, p=history.path )
+                link = urlbilder( u"browser", lib_id, p=history.path )
                 libs = Home.objects.filter( lib_id=lib_id )
                 users = [i.user_id for i in libs]
 
                 notify = MailFileNotify( )
-                notify.body = "New files upload to '{0}' by user {1}\n".format(path or '/', history.user)
-                notify.body += "Link http://{0}{1}&hl={2}\n".format(domain, link, history.hash())
+                notify.body = u"New files upload to '{0}' by user {1}\n".format(path or '/', history.user)
+                notify.body += u"Link http://{0}{1}&hl={2}\n".format(domain, link, history.hash())
                 notify.files = [i.name for i in files]
                 notify.users = users
                 # Hack to stay in one thread and test mail.outbox