Esempio n. 1
0
 def _create_project(self, user, projectname):
     project = Project(
         name=projectname,
         description="project",
         directory=projectname,
         owner=user,
     )
     project.save()
     return project
Esempio n. 2
0
    def post(self, request):
        ## return post from one of the starters list
        form = NewProjectForm(request.POST, user=request.user)
        template_id = request.POST.get('template_id')
        if form.is_valid():
            template = Template.objects.get(pk=template_id)
            project_directory = "%05d_%s" % (
                request.user.pk,
                get_valid_filename(form.cleaned_data['projectname']))

            logger.debug('--------------- create svn repository')
            # create svn project
            #            pm = SVNProjectCreator()
            #            pm.create_from_template(template.svn, project_directory, request.user.username)
            logger.debug('--------------- create project object')

            project = Project(name=form.cleaned_data['projectname'],
                              description="Saas demo project",
                              directory=project_directory,
                              owner=request.user,
                              template=template)

            project.save()

            logger.debug('--------------- create user project')
            # adds user to project
            up = UserProject(user=request.user,
                             project=project,
                             is_saas=True,
                             is_admin=True)

            up.save()
            logger.debug('--------------- set kolekti project')
            projectpath = os.path.join(settings.KOLEKTI_BASE,
                                       request.user.username,
                                       project.directory)
            self.set_project(projectpath)
            logger.debug('--------------- activate')
            self.project_activate(up)
            logger.debug('--------------- end ')
            return HttpResponseRedirect('/')
        else:
            context = self.get_context_data({
                "project_starters":
                self._project_starters(request.user, form, template_id),
                "projecturl":
                "",
            })

        return self.render_to_response(context)
Esempio n. 3
0
def bootstrap():

    # registers kolekti projects in windows libraries
    os.environ['DJANGO_SETTINGS_MODULE'] = 'kolekti_server.settings'

    import shutil
    from lxml import etree as ET
    import django
    from django.conf import settings

    if not os.path.exists(os.path.join(settings.KOLEKTI_BASE, '.logs')):
        os.makedirs(os.path.join(settings.KOLEKTI_BASE, '.logs'))

    django.setup()
    from django.contrib.auth.models import User
    from kserver_saas.models import Project, UserProfile, UserProject
    from django.core import management
    from django.core.exceptions import ObjectDoesNotExist

    if os.path.exists(settings.DB_NAME):
        shutil.move(settings.DB_NAME, settings.DB_NAME + "_backup")
    management.call_command('migrate', verbosity=0, interactive=False)
    management.call_command('loaddata',
                            'singleuser',
                            verbosity=0,
                            interactive=False)
    user = User.objects.get()

    for project_dir in os.listdir(os.path.join(settings.KOLEKTI_BASE)):
        print project_dir
        try:
            project_path = os.path.join(settings.KOLEKTI_BASE, project_dir)
            project_settings = ET.parse(
                os.path.join(project_path, 'kolekti',
                             'settings.xml')).getroot()
            if project_settings.xpath('string(/settings/@version)') != '0.7':
                continue
            lang = project_settings.xpath('string(/settings/@sourcelang)')
            try:
                project = Project.objects.get(directory=project_dir)
            except ObjectDoesNotExist:
                project = Project(
                    name=project_dir,
                    directory=project_dir,
                    description=project_dir,
                    owner=user,
                )
                project.save()
            try:
                userproject = UserProject.objects.get(project=project,
                                                      user=user)
            except ObjectDoesNotExist:
                userproject = UserProject(project=project,
                                          user=user,
                                          is_saas=False,
                                          is_admin=True,
                                          srclang=lang,
                                          publang=lang)
                userproject.save()

            userprofile = UserProfile.objects.get()
            userprofile.activeprojects = userproject
            userprofile.save()

        except:
            import traceback
            print traceback.format_exc()
            continue