Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/flexible-server_papermasters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions

name: Build and deploy Python app to Azure Web App - papermasters

on:
push:
branches:
- flexible-server
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.8'

- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate

- name: Install dependencies
run: pip install -r requirements.txt

# Optional: Add step to run tests here (PyTest, Django test suites, etc.)

- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v2
with:
name: python-app
path: |
.
!venv/

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: python-app
path: .

- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'papermasters'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_4BA33C844B7D4802B268CA0825F427DB }}
15 changes: 6 additions & 9 deletions azuresite/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# DBHOST is only the server name, not the full URL
hostname = os.environ['DBHOST']

# Configure Postgres database; the full username is username@servername,
# which we construct using the DBHOST value.
# Configure Postgres database.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ['DBNAME'],
'HOST': hostname + ".postgres.database.azure.com",
'USER': os.environ['DBUSER'] + "@" + hostname,
'PASSWORD': os.environ['DBPASS']
'NAME': os.environ['pmdb'],
'HOST': os.environ['pmserver'],
'USER': os.environ['karen'],
'PASSWORD': os.environ['Efromm1967'],
'OPTIONS': { 'sslmode': 'require'}
}
}
25 changes: 21 additions & 4 deletions azuresite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@
# Application definition

INSTALLED_APPS = [
'polls.apps.PollsConfig',
#'polls.apps.PollsConfig',
'topics.apps.TopicsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'dynamic_breadcrumbs',
'resources',
'toplevel',
]

MIDDLEWARE = [
Expand All @@ -49,6 +54,8 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',

]

ROOT_URLCONF = 'azuresite.urls'
Expand All @@ -64,6 +71,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'dynamic_breadcrumbs.context_processors.breadcrumbs',
],
},
},
Expand All @@ -77,8 +85,11 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': 'django.db.backends.postgresql',
'NAME':'pmdb',
'USER': 'karen',
'PASSWORD':'Efromm1967',
'HOST':'pmserver.postgres.database.azure.com',
}
}

Expand Down Expand Up @@ -120,4 +131,10 @@
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
2 changes: 1 addition & 1 deletion azuresite/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
from django.urls import include, path

urlpatterns = [
path('', include('polls.urls')),
path('', include('topics.urls')),
path('admin/', admin.site.urls),
]
6 changes: 3 additions & 3 deletions env.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set DBHOST=localhost
set DBUSER=manager
set DBNAME=pollsdb
set DBPASS=supersecretpass
set DBUSER=postgres
set DBNAME=pm_local
set DBPASS=Efromm1967
6 changes: 3 additions & 3 deletions env.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$Env:DBHOST = "localhost"
$Env:DBUSER = "manager"
$Env:DBNAME = "pollsdb"
$Env:DBPASS = "supersecretpass"
$Env:DBUSER = "postgres"
$Env:DBNAME = "pm_local"
$Env:DBPASS = "Efromm1967"
6 changes: 3 additions & 3 deletions env.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export DBHOST="localhost"
export DBUSER="manager"
export DBNAME="pollsdb"
export DBPASS="supersecretpass"
export DBUSER="postgres"
export DBNAME="pm_local"
export DBPASS="Efromm1967"

Empty file added resources/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions resources/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from .models import Resource

class ResourceAdmin(admin.ModelAdmin):
list_display = ('title', 'type_of_resource')
prepopulated_fields = {'slug': ('title',)}

admin.site.register(Resource, ResourceAdmin)
6 changes: 6 additions & 0 deletions resources/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ResourcesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'resources'
34 changes: 34 additions & 0 deletions resources/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.0.3 on 2022-04-04 20:41

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Resource',
fields=[
('id', models.IntegerField(primary_key=True, serialize=False)),
('title', models.CharField(max_length=200)),
('slug', models.SlugField(blank=True, max_length=200, null=True, unique=True)),
('meta_title', models.CharField(blank=True, max_length=200)),
('meta_description', models.CharField(max_length=400)),
('content', models.TextField(blank=True)),
('old_url', models.CharField(blank=True, max_length=200)),
('lower_content', models.TextField(blank=True)),
('type_of_resource', models.CharField(choices=[('E', 'Elements of a Paper'), ('R', 'Type of Research'), ('P', 'Type of Paper')], max_length=1)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
],
options={
'verbose_name': 'resource',
'verbose_name_plural': 'resources',
},
),
]
Empty file.
37 changes: 37 additions & 0 deletions resources/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.db import models
from django.utils.text import slugify
from django.urls import reverse

class Resource(models.Model):
id = models.IntegerField(primary_key=True)
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, null = True, unique = True, blank = True)
meta_title = models.CharField(max_length=200, blank=True)
meta_description = models.CharField(max_length=400)
content = models.TextField(blank=True)
old_url = models.CharField(max_length=200,blank=True)
lower_content = models.TextField(blank=True)
TYPE_OF_RESOURCE = (
('E', 'Elements of a Paper'),
('R', 'Type of Research'),
('P', 'Type of Paper'),
)
type_of_resource = models.CharField(max_length=1, choices=TYPE_OF_RESOURCE)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)


class Meta:
verbose_name = 'resource'
verbose_name_plural = 'resources'

def __str__(self):
return self.title

def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
return super().save(*args, **kwargs)

def get_absolute_url(self):
return reverse('resource_detail', kwargs={'slug': self.slug})
20 changes: 20 additions & 0 deletions resources/templates/resources/resource.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "topics/base.html" %}
{% load static %}

{% block back-style %}
<section class="section is-medium mt-6" style="background-image: linear-gradient(to right,rgba(7,20,37,.98) 0,rgba(7,20,37,.1) 100%), url('https://images.pexels.com/photos/5553045/pexels-photo-5553045.jpeg?auto=compress&amp;cs=tinysrgb&amp;dpr=2&amp;h=750&amp;w=1260'); background-repeat: no-repeat; background-size: cover;">
{% endblock back-style %}

{% block content %}
<section class="section">
<div class="container">
<div class="columns is-multiline">
<div class="column is-8">
<div class="boxbox has-background-white-ter p-6">
<div class="conStyle has-text-grey mb-5">
{{ content|safe }}
</div>

</div>
</div>
{% endblock content %}
3 changes: 3 additions & 0 deletions resources/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions resources/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from . import views

app_name = 'resources'

urlpatterns = [
path('<slug:slug>', views.resource_view, name='resource_view'),
]
13 changes: 13 additions & 0 deletions resources/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.shortcuts import render
from resources.models import Resource

def resource_view(request, slug):
slug = slug
rg = Resource.objects.get(slug=slug)
context = {
'title':rg.title,
'content':rg.content,
'meta_description':rg.meta_description,
'meta_title':rg.meta_title,
}
return render(request, 'resources/resource.html', context)
1 change: 1 addition & 0 deletions static/css/bulma.min.css

Large diffs are not rendered by default.

Loading