]> git.parisson.com Git - mezzo.git/commitdiff
Final Demo and Repository models, add reposity systems fixtures
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 3 Nov 2016 17:41:32 +0000 (18:41 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 3 Nov 2016 17:41:32 +0000 (18:41 +0100)
app/local_settings.py
app/organization/core/models.py
app/organization/projects/admin.py
app/organization/projects/fixtures/organization-projects-repositorysystems.json [new file with mode: 0644]
app/organization/projects/migrations/0025_auto_20161103_1825.py [new file with mode: 0644]
app/organization/projects/models.py
app/scripts/app.sh
docker-compose.yml

index 98e4c370be45a36612bfa45027488a62356ce304..0432308270346fe4f3a97531378a858ed5605b07 100644 (file)
@@ -121,6 +121,9 @@ ADMIN_MENU_ORDER = (
                     'organization-projects.ProjectProgramType',
                     'organization-projects.ProjectTopic',
                     'organization-projects.ProjectProgramType',
+                    'organization-projects.ProjectDemo',
+                    'organization-projects.Repository',
+                    'organization-projects.RepositorySystem',
                     )),
     (_('Shop'), ('shop.Product',
                     'organization-shop.ProductList',
@@ -192,6 +195,9 @@ ARTICLE_PER_PAGE = 4 # just for tests because we haven't got enough content
 # a mode you'd pass directly to os.chmod.
 FILE_UPLOAD_PERMISSIONS = 0o664
 FILE_UPLOAD_TEMP_DIR = '/srv/media/uploads/tmp/'
+if not os.path.exists(FILE_UPLOAD_TEMP_DIR):
+    os.makedirs(FILE_UPLOAD_TEMP_DIR)
+
 MAX_UPLOAD_SIZE = 512000000
 MAX_UPLOAD_SIZE_FRONT = 10485760
 FILEBROWSER_MAX_UPLOAD_SIZE = 512000000
@@ -225,3 +231,5 @@ SHOP_USE_VARIATIONS = False
 SHOP_USE_RATINGS = False
 
 PROJECT_DEMOS_DIR = '/srv/media/projects/demos/'
+if not os.path.exists(PROJECT_DEMOS_DIR):
+    os.makedirs(PROJECT_DEMOS_DIR)
index a145a3076a492739a0b1937d6f65793310756fbe..b077a4b16232e0d6a76692ff269c063627721538 100644 (file)
@@ -26,10 +26,11 @@ class Description(models.Model):
         abstract = True
 
 
-class Named(Description):
+class Named(models.Model):
     """Abstract model providing a name field"""
 
     name = models.CharField(_('name'), max_length=512)
+    description = models.TextField(_('description'), blank=True)
 
     class Meta:
         abstract = True
@@ -43,10 +44,11 @@ class Named(Description):
         return slugify(self.__unicode__())
 
 
-class Titled(Description):
+class Titled(models.Model):
     """Abstract model providing a title field"""
 
     title = models.CharField(_('title'), max_length=1024)
+    description = models.TextField(_('description'), blank=True)
 
     class Meta:
         abstract = True
index 89f65000c12d1376e559dc231f5f51e3e8c99154..9396727a0b60486695db5b3bc0bada5418509aff 100644 (file)
@@ -37,6 +37,17 @@ class ProjectFileInline(TabularDynamicInlineAdmin):
     model = ProjectFile
 
 
+class ProjectDemoInline(TabularDynamicInlineAdmin):
+
+    model = ProjectDemo
+
+
+class ProjectDemoAdmin(BaseTranslationModelAdmin):
+
+    model = ProjectDemo
+    filter_horizontal = ['authors']
+
+
 class ProjectAdmin(admin.ModelAdmin):
 
     model = Project
@@ -49,7 +60,7 @@ class ProjectAdminDisplayable(DisplayableAdmin):
                 ProjectImageInline,
                 ProjectPlaylistInline,
                 ProjectLinkInline,
-                ProjectFileInline]
+                ProjectFileInline,]
     filter_horizontal = ['teams', 'organizations']
     list_filter = ['type', 'program', 'program_type', ]
 
@@ -74,12 +85,11 @@ class ProjectTopicPageAdmin(PageAdmin):
     inlines = [PageImageInline, ]
 
 
-
 admin.site.register(Project, ProjectAdminDisplayable)
 admin.site.register(ProjectProgram, ProjectProgramAdmin)
 admin.site.register(ProjectProgramType, ProjectProgramTypeAdmin)
 admin.site.register(ProjectTopic, ProjectTopicAdmin)
 admin.site.register(ProjectTopicPage, ProjectTopicPageAdmin)
-admin.site.register(ProjectDemo)
+admin.site.register(ProjectDemo, ProjectDemoAdmin)
 admin.site.register(Repository)
 admin.site.register(RepositorySystem)
diff --git a/app/organization/projects/fixtures/organization-projects-repositorysystems.json b/app/organization/projects/fixtures/organization-projects-repositorysystems.json
new file mode 100644 (file)
index 0000000..523958a
--- /dev/null
@@ -0,0 +1 @@
+[{"model": "organization-projects.repositorysystem", "pk": 2, "fields": {"description": "", "name": "Git", "clone_command": "git clone", "pull_command": "git pull", "checkout_command": "git checkout", "branch_command": "git branch"}}, {"model": "organization-projects.repositorysystem", "pk": 3, "fields": {"description": "", "name": "Mercurial", "clone_command": "hg clone", "pull_command": "hg pull", "checkout_command": "hg up", "branch_command": "hg branch"}}, {"model": "organization-projects.repositorysystem", "pk": 4, "fields": {"description": "", "name": "SVN", "clone_command": "svn co", "pull_command": "svn update", "checkout_command": "svn co", "branch_command": "svn copy"}}, {"model": "organization-projects.repositorysystem", "pk": 5, "fields": {"description": "", "name": "Bazaar", "clone_command": "bzr co", "pull_command": "bzr update", "checkout_command": "bzr co", "branch_command": "bzr branch"}}]
\ No newline at end of file
diff --git a/app/organization/projects/migrations/0025_auto_20161103_1825.py b/app/organization/projects/migrations/0025_auto_20161103_1825.py
new file mode 100644 (file)
index 0000000..b312e9b
--- /dev/null
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.10 on 2016-11-03 17:25
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-network', '0046_auto_20161026_1025'),
+        ('organization-projects', '0024_auto_20161103_1521'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='projectdemo',
+            name='author',
+        ),
+        migrations.RemoveField(
+            model_name='projectdemo',
+            name='directory',
+        ),
+        migrations.RemoveField(
+            model_name='repositorysystem',
+            name='type',
+        ),
+        migrations.AddField(
+            model_name='projectdemo',
+            name='authors',
+            field=models.ManyToManyField(blank=True, related_name='demos', to='organization-network.Person', verbose_name='authors'),
+        ),
+        migrations.AddField(
+            model_name='projectdemo',
+            name='description_en',
+            field=models.TextField(blank=True, null=True, verbose_name='Description'),
+        ),
+        migrations.AddField(
+            model_name='projectdemo',
+            name='description_fr',
+            field=models.TextField(blank=True, null=True, verbose_name='Description'),
+        ),
+        migrations.AddField(
+            model_name='projectdemo',
+            name='title_en',
+            field=models.CharField(max_length=500, null=True, verbose_name='Title'),
+        ),
+        migrations.AddField(
+            model_name='projectdemo',
+            name='title_fr',
+            field=models.CharField(max_length=500, null=True, verbose_name='Title'),
+        ),
+    ]
index 39961f0acda2dcfb5ca367cb115f6eb9b95efa0f..f960eac01b0318dacbdbaa6ded13ea7743b0620a 100644 (file)
@@ -10,6 +10,7 @@ from mezzanine.core.models import RichText, Displayable, Slugged, Orderable
 
 from organization.core.models import *
 from organization.pages.models import *
+from organization.network.models import *
 
 
 PROJECT_TYPE_CHOICES = [
@@ -130,9 +131,8 @@ class ProjectTopicPage(Page, SubTitled):
 class ProjectDemo(Displayable, RichText):
 
     project = models.ForeignKey('Project', verbose_name=_('project'), related_name='demos', blank=True, null=True, on_delete=models.SET_NULL)
-    author = models.ForeignKey(User, verbose_name=_('author'), related_name='demos', blank=True, null=True, on_delete=models.SET_NULL)
+    authors = models.ManyToManyField(Person, verbose_name=_('authors'), related_name='demos', blank=True)
     repository = models.ForeignKey('Repository', verbose_name=_('repository'), related_name='demos', blank=True, null=True, on_delete=models.SET_NULL)
-    directory = models.CharField(_('directory'), max_length=256, blank=True, null=True)
     build_commands = models.TextField(_('build commands'), blank=True)
 
     class Meta:
@@ -143,10 +143,14 @@ class ProjectDemo(Displayable, RichText):
         return reverse("organization-project-demo-detail", kwargs={"slug": self.slug})
 
     def build(self):
-        os.chdir(settings.PROJECT_DEMOS_DIR + os.sep + self.directory)
-        for commands in self.build_commands.split('\n'):
+        os.chdir(self.repository.directory)
+        for command in self.build_commands.split('\n'):
             os.system(command)
 
+    def save(self, *args, **kwargs):
+        super(ProjectDemo, self).save(args, kwargs)
+        self.build()
+
 
 class Repository(Named, URL):
 
@@ -158,13 +162,32 @@ class Repository(Named, URL):
         verbose_name = _('repository')
         verbose_name_plural = _("repositories")
 
+    def save(self, *args, **kwargs):
+        super(Repository, self).save(args, kwargs)
+        if not os.path.exists(self.directory):
+            self.clone()
+        self.checkout()
+
+    @property
+    def directory(self):
+        dir_name = self.url.split('/')[-1].split('.')[0]
+        return settings.PROJECT_DEMOS_DIR + os.sep + dir_name
+
     def clone(self):
-        os.system(' '.join((self.system.clone_command, self.url, settings.PROJECT_DEMOS_DIR)))
+        os.chdir(settings.PROJECT_DEMOS_DIR)
+        os.system(' '.join((self.system.clone_command, self.url)))
+
+    def pull(self):
+        os.chdir(self.directory)
+        os.system(' '.join((self.system.pull_command, self.branch)))
+
+    def checkout(self):
+        os.chdir(self.directory)
+        os.system(' '.join((self.system.checkout_command, self.branch)))
 
 
 class RepositorySystem(Named):
 
-    type = models.CharField(_('type'), max_length=32)
     clone_command = models.CharField(_('clone command'), max_length=256)
     pull_command = models.CharField(_('pull command'), max_length=256)
     checkout_command = models.CharField(_('checkout command'), max_length=256)
index e5510f918cf85255f21f2677f7f50393034abbb9..5fc880f2fb0a49e50daf7f0bc986e7e8f34ae916 100644 (file)
@@ -38,6 +38,7 @@ python $manage migrate --noinput
 python $manage create-admin-user
 # @todo searching every fixtures file in each folder
 python $manage loaddata $app/organization/job/fixtures/organization-job.json
+python $manage loaddata $app/organization/projects/fixtures/organization-projects-repositorysystems.json
 
 # app start
 if [ "$1" = "--runserver" ]; then
index 66e895aa2c70fdf56acda0202acf39aa520bcb6a..569f682d92f25c37749a5614b8561dca8bdd50ed 100644 (file)
@@ -55,7 +55,7 @@ app:
   links:
     - db
   environment:
-   - DEBUG=False
+   - DEBUG='False'
 
 nginx:
   image: nginx