Skip to content

Commit

Permalink
Merge branch 'adinusa_academy' into 'master'
Browse files Browse the repository at this point in the history
Adinusa academy

See merge request dev/academy!262
  • Loading branch information
Muhammad Irfan committed Sep 28, 2020
2 parents 8f10ad9 + 4157c38 commit 3e9d31b
Show file tree
Hide file tree
Showing 278 changed files with 25,949 additions and 192 deletions.
7 changes: 4 additions & 3 deletions academy/apps/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,12 @@ def generate(self):
options = {
'page-size': 'A4',
'orientation': 'Landscape',
'margin-top': '0in',
'margin-top': '0.15in',
'margin-right': '0in',
'margin-bottom': '0in',
'margin-left': '0in',
'no-outline': None
'no-outline': None,
'dpi': 300
}
pdf = pdfkit.from_string(rendered_html, filepath, options=options)
response = HttpResponse(pdf, content_type='application/pdf')
Expand All @@ -413,7 +414,7 @@ def generate(self):
self.save()

def preview(self):
html_template = get_template('backoffice/graduates/certificate-dev.html')
html_template = get_template('backoffice/graduates/certificate-adinusa.html')
last_name = (
self.user.last_name if self.user.last_name
else self.user.first_name
Expand Down
18 changes: 18 additions & 0 deletions academy/apps/offices/migrations/0019_page_type_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.10 on 2020-09-25 07:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('offices', '0018_auto_20200923_1350'),
]

operations = [
migrations.AddField(
model_name='page',
name='type_content',
field=models.PositiveIntegerField(choices=[(1, 'Halaman'), (2, 'Pos')], default=2),
),
]
10 changes: 10 additions & 0 deletions academy/apps/offices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ class Page(ModelMeta, models.Model):
CategoryPage, on_delete=models.CASCADE, related_name="group",
blank=True, null=True
)
TYPE_CONTENT = Choices(
(1, 'page', _("Page")),
(2, 'post', _("Post")),
)
type_content = models.PositiveIntegerField(
choices=TYPE_CONTENT, default=TYPE_CONTENT.post)
STATUS = Choices(
(1, 'draft', _("Konsep")),
(2, 'publish', _("Terbit")),
Expand All @@ -153,6 +159,10 @@ def get_meta_image(self):
def get_category_list(self):
return self.category.all().values_list('name', flat=True)

@property
def raw_type(self):
return self.get_type_content_display().lower()

def __str__(self):
return self.title

Expand Down
8 changes: 4 additions & 4 deletions academy/backoffice/graduates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from academy.core.utils import pagination
from academy.apps.graduates.models import Graduate
from academy.apps.students.models import Student, TrainingMaterial, TrainingStatus
from academy.apps.accounts.models import User
from academy.apps.accounts.models import User, Certificate
from academy.backoffice.users.forms import ChangeStatusTraining
from .forms import (
ParticipantsRepeatForm, AddTrainingStatus, GraduateTrainingStatusFormSet, BaseFilterForm,
Expand Down Expand Up @@ -237,15 +237,15 @@ def status_training(request, id):

@staff_member_required
def show_certificate(request, id):
graduate = get_object_or_404(Graduate, id=id)
graduate = get_object_or_404(Certificate, id=id)
force = False

if request.GET.get('regenerate') and request.GET['regenerate'] == 'yes':
force = True

graduate.generate_certificate_file(force)
graduate.generate()
context = {
'title': f'Certificate {graduate.certificate_number}',
'title': f'Certificate',
'menu_active': 'graduates',
'graduate': graduate
}
Expand Down
8 changes: 8 additions & 0 deletions academy/core/templatetags/math_extras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django import template

register = template.Library()


@register.filter
def subtract(value, arg):
return value - arg
26 changes: 25 additions & 1 deletion academy/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import datetime
import feedparser
import jwt
import requests

from django.conf import settings
from django.contrib.auth import get_user_model

Expand Down Expand Up @@ -119,4 +122,25 @@ def sync_keycloak_user(id_token_object):
}
)

return user
return user


def call_internal_api(method, url, **kwargs):
method_map = {
'get': requests.get,
'post': requests.post,
'put': requests.put,
'patch': requests.patch,
'delete': requests.delete
}

payload = jwt.encode({
'server_key': settings.SERVER_KEY,
'exp': datetime.datetime.utcnow() + datetime.timedelta(seconds=30)
}, settings.SECRET_KEY).decode('utf-8')

headers = {
"authorization": f'Server {payload}'
}

return method_map[method](url, headers=headers, **kwargs)
4 changes: 3 additions & 1 deletion academy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.forms',

'academy.core',
Expand All @@ -75,7 +76,8 @@
'taggit',
"meta",
"django_keycloak.apps.KeycloakAppConfig",
'django_social_share'
'django_social_share',
'sorl.thumbnail'
]

MIDDLEWARE = [
Expand Down
6 changes: 2 additions & 4 deletions academy/website/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ class ProfileForm(forms.ModelForm):
phone_number = forms.CharField(max_length=16, validators=[validate_mobile_phone],
label='Nomor Ponsel')
curriculum_vitae = fields.FileFieldExtended(
label=mark_safe('Curriculum Vitae<br/>'
'<a href="https://www.dropbox.com/s/nqjoadgifz7zpb0/template_cv_nolsatu.docx?dl=0" target="_blank">'
'Download Template CV</a>'),
help_text="File Type: .doc, .docx, .pdf. Max 2 MB. Mohon gunakan template yang disediakan",
label='Curriculum Vitae',
help_text="File Type: .doc, .docx, .pdf. Max 2 MB.",
max_mb_file_size=2,
allowed_content_type=[
'application/msword',
Expand Down
11 changes: 7 additions & 4 deletions academy/website/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

@login_required
def index(request):
if not hasattr(request.user, 'survey'):
return redirect("website:accounts:survey")
# if not hasattr(request.user, 'survey'):
# return redirect("website:accounts:survey")

user = request.user
training = Training.get_or_create_initial()
Expand All @@ -31,6 +31,7 @@ def index(request):

form = ProfileForm(
data=request.POST or None, files=request.FILES or None,
cv_required=False,
initial={
"first_name": user.first_name,
"last_name": user.last_name
Expand Down Expand Up @@ -191,8 +192,10 @@ def edit_profile(request):
'instagram': user.profile.instagram
}

form = ProfileForm(data=request.POST or None, files=request.FILES or None,
initial=initial, instance=user.profile)
form = ProfileForm(
data=request.POST or None, files=request.FILES or None,
initial=initial, instance=user.profile, cv_required=False
)
if form.is_valid():
form.save(user)
messages.success(request, 'Profil berhasil diubah')
Expand Down
5 changes: 4 additions & 1 deletion academy/website/campuses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def complete_profile(request, campus_id):
return redirect('website:campuses:index')

signup_form = SignupForm(request.session['registration_data'])
form = ProfileForm(data=request.POST or None, files=request.FILES or None)
form = ProfileForm(
data=request.POST or None, files=request.FILES or None,
cv_required=False
)
if signup_form.is_valid() and form.is_valid():
user = signup_form.save()
form.save(user)
Expand Down
8 changes: 4 additions & 4 deletions academy/website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
app_name = 'website'

urlpatterns = [
path('', views.index, name='index'),
path('', views.home_custom, name='index'),
path('profile/', views.profile, name='profile'),
path('home/', views.home, name='home'),
path('error404/', views.error_404, name='error404'),
Expand All @@ -20,9 +20,9 @@
path('statistic/', views.statistic, name='statistic'),
path('blogs/<slug:slug>', views.blog_details, name='blog_details'),
path('blogs/', views.blog_index, name='blog_index'),
path('page/<slug:categoryslug>/',
path('<slug:type_content>/<slug:slug>/',
views.page_category, name='page_category'),
path('page/<slug:categoryslug>/<slug:slug>/',
path('<slug:type_content>/<slug:categoryslug>/<slug:slug>/',
views.page_category_detail, name='page_category_detail'),

path('contact/', views.contact, name='contact'),
]
63 changes: 49 additions & 14 deletions academy/website/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from json.decoder import JSONDecodeError

from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect, get_object_or_404
Expand All @@ -14,6 +15,7 @@
from academy.apps.offices.models import LogoPartner, LogoSponsor, Page, FAQ, CategoryPage
from academy.apps.students.models import Student
from academy.apps.graduates.models import Graduate
from academy.core.utils import call_internal_api

from .forms import CertificateVerifyForm
from meta.views import Meta
Expand Down Expand Up @@ -155,14 +157,12 @@ def profile(request):

def blog_details(request, slug):
blog = get_object_or_404(Page, slug=slug)
print(blog.as_meta().__dict__)

context = {
'title': blog.title,
'blog': blog,
'meta': blog.as_meta()
}

return render(request, 'website/blog-details.html', context)


Expand All @@ -177,25 +177,60 @@ def blog_index(request):
return render(request, 'website/blogs.html', context)


def page_category(request, categoryslug):
cat_page = get_object_or_404(CategoryPage, slug=categoryslug)
blogs = Page.objects.filter(group__slug=categoryslug)

context = {
'title': cat_page.name,
'blogs': blogs
}

return render(request, 'website/page-category.html', context)
def home_custom(request):
try:
courses = call_internal_api(
'get', url=settings.NOLSATU_COURSE_HOST + f'/api/list').json()
courses = courses[:3]
except JSONDecodeError:
courses = []

try:
vendors = call_internal_api(
'get', url=settings.NOLSATU_COURSE_HOST + f'/api/vendorlist').json()
except JSONDecodeError:
vendors = []

def page_category_detail(request, categoryslug, slug):
context = {
'title': 'Home',
'courses': courses,
'vendors': vendors
}
return render(request, 'website/home-adinusa.html', context)


def page_category(request, type_content, slug):
if type_content == 'post':
cat_page = get_object_or_404(CategoryPage, slug=slug)
blogs = cat_page.group.all()
context = {
'title': cat_page.name,
'blogs': blogs
}
return render(request, 'website/page-category.html', context)
else:
blog = get_object_or_404(Page, slug=slug)
context = {
'title': blog.title,
'blog': blog
}
return render(request, 'website/page-detail.html', context)


def page_category_detail(request, type_content, categoryslug, slug):
blog = get_object_or_404(Page, group__slug=categoryslug, slug=slug)

context = {
'title': blog.title,
'blog': blog
}

return render(request, 'website/page-category-detail.html', context)


def contact(request):
context = {
'title': 'Kontak'
}

return render(request, 'website/contact.html', context)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ phonenumbers==8.8.10
django-model-utils==3.0.0
Pillow==6.2.0
pdfkit==0.6.1
sorl-thumbnail==12.6.3

django-post-office==3.0.4
django-extensions==2.0.7
Expand Down
Loading

0 comments on commit 3e9d31b

Please sign in to comment.