[extensions-web] extensions: Reorganize Extensions class



commit 4539296150d7c13273079dd86a272555b223363e
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sat Mar 3 06:09:21 2012 -0500

    extensions: Reorganize Extensions class
    
    Just a shuffle around of the order of the methods

 sweettooth/extensions/models.py |   70 +++++++++++++++++++--------------------
 1 files changed, 34 insertions(+), 36 deletions(-)
---
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index 1574e1b..ad57ba9 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -101,29 +101,11 @@ class Extension(models.Model):
     def __unicode__(self):
         return self.uuid
 
-    @property
-    def visible_versions(self):
-        return self.versions.filter(status__in=VISIBLE_STATUSES)
-
-    @property
-    def latest_version(self):
-        try:
-            return self.visible_versions.latest()
-        except ExtensionVersion.DoesNotExist:
-            return None
-
-    def user_can_edit(self, user):
-        if user == self.creator:
-            return True
-        if user.has_perm('extensions.can-modify-data'):
-            return True
-        return False
-
-    @property
-    def first_line_of_description(self):
-        if not self.description:
-            return ""
-        return self.description.splitlines()[0]
+    def parse_metadata_json(self, metadata):
+        self.name = metadata.pop('name', "")
+        self.description = metadata.pop('description', "")
+        self.url = metadata.pop('url', "")
+        self.uuid = metadata['uuid']
 
     def clean(self):
         from django.core.exceptions import ValidationError
@@ -131,12 +113,6 @@ class Extension(models.Model):
         if not validate_uuid(self.uuid):
             raise ValidationError("Invalid UUID")
 
-    def parse_metadata_json(self, metadata):
-        self.name = metadata.pop('name', "")
-        self.description = metadata.pop('description', "")
-        self.url = metadata.pop('url', "")
-        self.uuid = metadata['uuid']
-
     def save(self, replace_metadata_json=True, *args, **kwargs):
         super(Extension, self).save(*args, **kwargs)
         if replace_metadata_json:
@@ -147,7 +123,35 @@ class Extension(models.Model):
                     except BadZipfile, e:
                         # Ignore bad zipfiles, we don't care
                         pass
- 
+
+    def get_absolute_url(self):
+        return reverse('extensions-detail', kwargs=dict(pk=self.pk,
+                                                        slug=self.slug))
+
+    def user_can_edit(self, user):
+        if user == self.creator:
+            return True
+        if user.has_perm('extensions.can-modify-data'):
+            return True
+        return False
+
+    @property
+    def first_line_of_description(self):
+        if not self.description:
+            return ""
+        return self.description.splitlines()[0]
+
+    @property
+    def visible_versions(self):
+        return self.versions.filter(status__in=VISIBLE_STATUSES)
+
+    @property
+    def latest_version(self):
+        try:
+            return self.visible_versions.latest()
+        except ExtensionVersion.DoesNotExist:
+            return None
+
     @property
     def visible_shell_version_map(self):
         return build_shell_version_map(self.visible_versions)
@@ -156,12 +160,6 @@ class Extension(models.Model):
     def visible_shell_version_map_json(self):
         return json.dumps(self.visible_shell_version_map)
 
-    def get_absolute_url(self):
-        return reverse('extensions-detail', kwargs=dict(pk=self.pk,
-                                                        slug=self.slug))
-
-
-
 class ExtensionPopularityItem(models.Model):
     extension = models.ForeignKey(Extension, db_index=True,
                                   related_name='popularity_items')



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]