Commit b780da61 authored by Mirko Vucicevich's avatar Mirko Vucicevich
Browse files

Updated admin to have better organization for projects

added helptext for several project fields

added more gitlab integration options (to override defaults)
parent bda6fc8f
......@@ -45,15 +45,16 @@ class NoticeInline(admin.StackedInline):
class ProjectAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['title']}),
('Project Icon', {'fields': ['icon']}),
('Tagline', {'fields': ['tagline']}),
('Gitlab ID', {'fields': ['gitlab_id']}),
('Hostnames', {'fields': ['hostnames']}),
('Description', {'fields': ['description']}),
('Date information', {'fields': ['project_created']}),
('Groups & Technologies', {'fields': ['technologies', 'groups']}),
('Scope', {'fields': ['scope']}),
('Project Information', {
'fields': ['title', 'icon', 'tagline', 'description', 'project_created']
}),
('Project Details', {'fields': ['scope', 'technologies', 'groups']}),
('Overlay Information', {'fields': ['hostnames']}),
('Gitlab Integration', {
'fields': ['gitlab_id', 'gitlab_access_token', 'gitlab_url'],
'classes': ['collapse']
}),
]
filter_horizontal = ['technologies', 'groups']
......
# Generated by Django 2.2.6 on 2019-11-18 18:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('projector', '0029_auto_20191008_1826'),
]
operations = [
migrations.AddField(
model_name='project',
name='gitlab_access_token',
field=models.CharField(blank=True, help_text="If the default gitlab API token won't work for you, provide an alternative", max_length=256),
),
migrations.AddField(
model_name='project',
name='gitlab_url',
field=models.CharField(blank=True, help_text="If your project isn't in the UW git repo, you can provide an alternative gitlab url here.", max_length=256),
),
migrations.AlterField(
model_name='project',
name='description',
field=models.TextField(help_text='Markdown-formatted project description'),
),
migrations.AlterField(
model_name='project',
name='gitlab_id',
field=models.CharField(blank=True, help_text='This can be found under general project settings (its an integer). If you have a CHANGELOG.md file in the root of your repo it will be read.', max_length=100),
),
migrations.AlterField(
model_name='project',
name='groups',
field=models.ManyToManyField(help_text='Include or add all groups which work with this project from a development perspective', to='projector.Group'),
),
migrations.AlterField(
model_name='project',
name='hostnames',
field=models.TextField(blank=True, help_text='List of allowed domains. Separate by commas. Overlay will only work on these hosts'),
),
migrations.AlterField(
model_name='project',
name='project_created',
field=models.DateField(help_text='The approximate date this project started development or was launched. Only year / term will be used by site.'),
),
migrations.AlterField(
model_name='project',
name='scope',
field=models.CharField(blank=True, choices=[('Local', 'Local (Used by Faculty/Dept Internally)'), ('Cross-Department', 'Cross-Department (Invite only)'), ('Campus-Wide', 'Campus-Wide (Available to All)')], max_length=100),
),
migrations.AlterField(
model_name='project',
name='tagline',
field=models.CharField(help_text='Short, catchy sentence about the project', max_length=100),
),
]
from django.utils import timezone
from django.utils.functional import cached_property
from django.db import models
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill
......@@ -14,20 +15,27 @@ class Project(models.Model):
blank=True,
null=True,
)
gitlab_id = models.CharField(max_length=100, blank=True)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, blank=True)
tagline = models.CharField(max_length=100)
description = models.TextField()
tagline = models.CharField(
max_length=100,
help_text="Short, catchy sentence about the project"
)
description = models.TextField(
help_text="Markdown-formatted project description"
)
technologies = models.ManyToManyField('projector.Technology', blank=True)
project_created = models.DateField(
help_text="The approximate date this project started development or was launched."
help_text="The approximate date this project started development or was launched. Only year / term will be used by site."
)
groups = models.ManyToManyField(
'projector.Group',
help_text='Include or add all groups which work with this project from a development perspective'
)
groups = models.ManyToManyField('projector.Group')
SCOPES = (
('Local', 'Local'),
('Cross-Department', 'Cross-Department'),
('Campus-Wide', 'Campus-Wide'),
('Local', 'Local (Used by Faculty/Dept Internally)'),
('Cross-Department', 'Cross-Department (Invite only)'),
('Campus-Wide', 'Campus-Wide (Available to All)'),
)
scope = models.CharField(
max_length=100,
......@@ -35,9 +43,23 @@ class Project(models.Model):
blank=True,
)
hostnames = models.TextField(
help_text="List of allowed domains. Separate by commas.",
help_text="List of allowed domains. Separate by commas. Overlay will only work on these hosts",
blank=True
)
gitlab_id = models.CharField(
max_length=100, blank=True,
help_text="This can be found under general project settings (its an integer). If you have a CHANGELOG.md file in the root of your repo it will be read."
)
gitlab_access_token = models.CharField(
max_length=256,
blank=True,
help_text="If the default gitlab API token won't work for you, provide an alternative"
)
gitlab_url = models.CharField(
max_length=256,
blank=True,
help_text="If your project isn't in the UW git repo, you can provide an alternative gitlab url here."
)
@property
def active_notices(self):
......@@ -49,23 +71,32 @@ class Project(models.Model):
@property
def html(self):
return markdown.markdown(self.description)
@property
def changelog(self):
#if self.changelog_stuff
if not self.gitlab_id:
return ''
changelog = get(
'{}/api/v4/projects/{}/repository/files/changelog.md/raw?ref=master'.format(
settings.GITLAB_DEFAULT_URL, self.gitlab_id
'{}/api/v4/projects/{}/repository/files/CHANGELOG.md/raw?ref=master'.format(
self.gitlab_url if self.gitlab_url else
settings.GITLAB_DEFAULT_URL,
self.gitlab_id
),
headers={
'PRIVATE-TOKEN': settings.GITLAB_DEFAULT_ACCESS_TOKEN,
'PRIVATE-TOKEN': self.gitlab_access_token
if self.gitlab_access_token
else settings.GITLAB_DEFAULT_ACCESS_TOKEN,
}
)
return changelog.text
@property
@cached_property
def changelogmd(self):
return markdown.markdown(self.changelog)
try:
return markdown.markdown(self.changelog)
except:
return ''
class Notice(models.Model):
project = models.ForeignKey(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment