From 7f588070ca2221457adc0c7fe6a076aac191002e Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 3 Nov 2016 18:41:32 +0100 Subject: [PATCH] Final Demo and Repository models, add reposity systems fixtures --- app/local_settings.py | 8 +++ app/organization/core/models.py | 6 ++- app/organization/projects/admin.py | 16 ++++-- ...ganization-projects-repositorysystems.json | 1 + .../migrations/0025_auto_20161103_1825.py | 53 +++++++++++++++++++ app/organization/projects/models.py | 35 +++++++++--- app/scripts/app.sh | 1 + docker-compose.yml | 2 +- 8 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 app/organization/projects/fixtures/organization-projects-repositorysystems.json create mode 100644 app/organization/projects/migrations/0025_auto_20161103_1825.py diff --git a/app/local_settings.py b/app/local_settings.py index 98e4c370..04323082 100644 --- a/app/local_settings.py +++ b/app/local_settings.py @@ -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) diff --git a/app/organization/core/models.py b/app/organization/core/models.py index a145a307..b077a4b1 100644 --- a/app/organization/core/models.py +++ b/app/organization/core/models.py @@ -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 diff --git a/app/organization/projects/admin.py b/app/organization/projects/admin.py index 89f65000..9396727a 100644 --- a/app/organization/projects/admin.py +++ b/app/organization/projects/admin.py @@ -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 index 00000000..523958ad --- /dev/null +++ b/app/organization/projects/fixtures/organization-projects-repositorysystems.json @@ -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 index 00000000..b312e9b4 --- /dev/null +++ b/app/organization/projects/migrations/0025_auto_20161103_1825.py @@ -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'), + ), + ] diff --git a/app/organization/projects/models.py b/app/organization/projects/models.py index 39961f0a..f960eac0 100644 --- a/app/organization/projects/models.py +++ b/app/organization/projects/models.py @@ -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) diff --git a/app/scripts/app.sh b/app/scripts/app.sh index e5510f91..5fc880f2 100644 --- a/app/scripts/app.sh +++ b/app/scripts/app.sh @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 66e895aa..569f682d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -55,7 +55,7 @@ app: links: - db environment: - - DEBUG=False + - DEBUG='False' nginx: image: nginx -- 2.39.5