Commit e704d6ae authored by Stefano Alberto Russo's avatar Stefano Alberto Russo
Browse files

Added support for custom texts. Refactored the home (main) page to support a custom text.

parent f91aa409
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
from django.contrib import admin

from .models import Profile, LoginToken, Task, Container, Computing, ComputingSysConf, ComputingUserConf, KeyPair
from .models import Profile, LoginToken, Task, Container, Computing, ComputingSysConf, ComputingUserConf, KeyPair, Text

admin.site.register(Profile)
admin.site.register(LoginToken)
@@ -10,3 +10,4 @@ admin.site.register(Computing)
admin.site.register(ComputingSysConf)
admin.site.register(ComputingUserConf)
admin.site.register(KeyPair)
admin.site.register(Text)
+25 −2
Original line number Diff line number Diff line
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from ...models import Profile, Container, Computing, ComputingSysConf, ComputingUserConf, KeyPair
from ...models import Profile, Container, Computing, ComputingSysConf, ComputingUserConf, KeyPair, Text

class Command(BaseCommand):
    help = 'Adds the admin superuser with \'a\' password.'
@@ -39,6 +39,29 @@ class Command(BaseCommand):
                                private_key_file = '/rosetta/.ssh/id_rsa',
                                public_key_file = '/rosetta/.ssh/id_rsa.pub')

        # Default homepage text
        default_home_text_content = '''
<div class="span8 offset2" style="margin: 30px auto; max-width:800px">
  Welcome to Rosetta!
  <br/><br/>
  This is the default home text loaded after populating the platform with the default/demo data.
  To change it, head to the <a href="/admin">admin</a> page and edit the <code>Text</code> model.
  <br/><br/>
  The default installation provides a test user register with email <code>testuser@rosetta.platform</code>
  and password <code>testpass</code>, which you can use to login on the menu on the right or using the link
  below and give Rosetta a try immediately. If you run with the default docker-compose file (i.e. you just
  run <code>rosetta/setup</code>), then you will also have a few demo computing resources you can play with
  out-of-the-box, including a small Slurm cluster. Otherwise, you will need to setup your own computing
  resources either platform-wide or as user.
</div>
'''
        home_text = Text.objects.filter(id='home')
        if home_text:
            print('Not creating default home text as already present')
        else:
            print('Creating default home text...')
            Text.objects.create(id='home', content=default_home_text_content)


        # Public containers
        public_containers = Container.objects.filter(user=None)
+20 −0
Original line number Diff line number Diff line
# Generated by Django 2.2.1 on 2021-03-30 22:02

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('core_app', '0002_container_protocol'),
    ]

    operations = [
        migrations.CreateModel(
            name='Text',
            fields=[
                ('id', models.CharField(max_length=16, primary_key=True, serialize=False, verbose_name='Text id')),
                ('content', models.TextField(blank=True, null=True, verbose_name='Text content')),
            ],
        ),
    ]
+11 −0
Original line number Diff line number Diff line
@@ -378,7 +378,18 @@ class KeyPair(models.Model):



#=========================
#  Texts 
#=========================

class Text(models.Model):
    '''A model to store some text contents for the platform, like the home page text'''

    id = models.CharField('Text id', max_length=16, primary_key=True)
    content = models.TextField('Text content', blank=True, null=True)

    def __str__(self):
        return str('Text with id "{}"'.format(self.id))



+22 −1
Original line number Diff line number Diff line
@@ -10,9 +10,30 @@
                <h2 style="margin-top:10px; margin-left:25px; margin-right:25px; font-weight:100; line-height: 30px;"><i>A container-centric Science Platform<br></i></h2>
            </div>
        </div>
        
        <div class="container">
            <div class="dashboard">
                {% if data.home_text %}
                {{ data.home_text | safe }}
                {% else %}
                <div class="span8 offset2" style="margin: 30px auto; max-width:800px">
                <br/>
                Welcome to Rosetta!
                <br/><br/>
                This is an empty installation. To load some demo data, run <code>rosetta/populate</code>.
                </div>
                {% endif %}
            </div>
        </div>

        <div style="display:table-row">
            <div class="text-vertical-bottom">
                <a href="https://github.com/sarusso/Rosetta" class="btn btn-dark btn-lg">Find Out More</a>
                {% if user.is_authenticated %}
                <a href="/tasks" class="btn btn-dark btn-lg">Tasks</a>
                <a href="/containers" class="btn btn-dark btn-lg">Containers</a>
                {% else %}
                <a href="/login" class="btn btn-dark btn-lg">Log In</a>
                {% endif %}
            </div>
        </div>
    </header>
Loading