diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4ca9634 Binary files /dev/null and b/.DS_Store differ diff --git a/blog/.DS_Store b/blog/.DS_Store new file mode 100644 index 0000000..ff91562 Binary files /dev/null and b/blog/.DS_Store differ diff --git a/blog/__init__.py b/blog/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/admin.py b/blog/admin.py new file mode 100644 index 0000000..60b0d82 --- /dev/null +++ b/blog/admin.py @@ -0,0 +1,25 @@ +from django.contrib import admin + +# Register your models here. +from .models import Post + +# Tell Django admin site that model is registered in admin site using +# custom class that inherits from ModelAdmin. +class PostAdmin(admin.ModelAdmin): +# Determine how posts are to be displayed in the admin dashboard + list_display = ('title', 'slug', 'author', 'publish', + 'status') +# Additional field for filtering, searching and ordering +# Right sidebar added to allow filtering by fields in list_filter attribute + list_filter = ('status', 'created', 'publish', 'author') +# Searchable fields using the search_fields attribute. + search_fields = ('title', 'body') +# Prepopulate slug url using title + prepopulated_fields = {'slug': ('title',)} +# Look up widget to replace dropdown. Useful when you have many users + raw_id_fields = ('author',) +# Bar to navigate quickly through a date hierarchy + date_hierarchy = 'publish' + ordering = ['status', 'publish'] +# Register classes +admin.site.register(Post, PostAdmin) \ No newline at end of file diff --git a/blog/apps.py b/blog/apps.py new file mode 100644 index 0000000..7930587 --- /dev/null +++ b/blog/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class BlogConfig(AppConfig): + name = 'blog' diff --git a/blog/migrations/0001_initial.py b/blog/migrations/0001_initial.py new file mode 100644 index 0000000..ee7fd27 --- /dev/null +++ b/blog/migrations/0001_initial.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-12-29 08:59 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Post', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=250)), + ('slug', models.SlugField(max_length=250, unique_for_date='publish')), + ('body', models.TextField()), + ('publish', models.DateTimeField(default=django.utils.timezone.now)), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('status', models.CharField(choices=[('draft', 'Draft'), ('published', 'Published')], default='draft', max_length=10)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_posts', to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/blog/migrations/__init__.py b/blog/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/models.py b/blog/models.py new file mode 100644 index 0000000..ead1122 --- /dev/null +++ b/blog/models.py @@ -0,0 +1,59 @@ +from django.db import models + +# Post model +# Field types as defined in https://docs.djangoproject.com/en/1.8/ref/models/fields/ +from django.utils import timezone +from django.contrib.auth.models import User +# Needed for canonical urls +from django.core.urlresolvers import reverse + +class PublishedManager(models.Manager): + def get_queryset(self): + return super(PublishedManager, + self).get_queryset()\ + .filter(status='published') +class Post(models.Model): + STATUS_CHOICES = ( + ('draft', 'Draft'), + ('published', 'Published'), + ) + title = models.CharField(max_length=250) +# slug is a unique field used for clean urls + slug = models.SlugField(max_length=250, + unique_for_date='publish') +# author field using a foreign key. related_name says author can write many posts + author = models.ForeignKey(User, + related_name='blog_posts') + body = models.TextField() + publish = models.DateTimeField(default=timezone.now) +# auto_now_add - date will be saved automatically when creating an object + created = models.DateTimeField(auto_now_add=True) +# auto_now - date will be updated automatically when saving an object. + updated = models.DateTimeField(auto_now=True) +# choices provides radio list that limits user to pick from select list + status = models.CharField(max_length=10, + choices=STATUS_CHOICES, + default='draft') +# Add managers +# The default manager is objects +# PublishedManager is our custom manager. Will allow us to retrieve posts using Post.published +# e.g. Post.published.filter(title__startswith='Who') + objects = models.Manager() + published = PublishedManager() + +# Canonical URLs. +# We will use the reverse() method that allows you to build URLs by their name and passing optional parameters. +# We are using the strftime() function to build the URL using month and day with leading zeros. +# We will use the get_absolute_url() method in our templates +def get_absolute_url(self): + return reverse('blog:post_detail', + args=[self.publish.year, + self.publish.strftime('%m'), + self.publish.strftime('%d'), + self.slug]) +# Meta - Metadata +class Meta: +# Sort results by the publish. We specify descending order designated by prefix + ordering = ('-publish',) +def __str__(self): + return self.title diff --git a/blog/tests.py b/blog/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/blog/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/blog/urls.py b/blog/urls.py new file mode 100644 index 0000000..9267644 --- /dev/null +++ b/blog/urls.py @@ -0,0 +1,10 @@ +from django.conf.urls import url +from . import views + +urlpatterns = [ +# post views + url(r'^$', views.post_list, name='post_list'), + url(r'^(?P\d{4})/(?P\d{2})/(?P\d{2})/'\ + r'(?P[-\w]+)/$', + views.post_detail, name='post_detail'), +] \ No newline at end of file diff --git a/blog/views.py b/blog/views.py new file mode 100644 index 0000000..146c7e2 --- /dev/null +++ b/blog/views.py @@ -0,0 +1,21 @@ +from django.shortcuts import render +from django.shortcuts import get_object_or_404 + +# Create your views here. +from .models import Post +def post_list(request): + posts = Post.published.all() # uses the manager that was created in models + return render(request, + 'blog/list.html', + {'posts': posts}) + +# Second view to display single post +def post_detail(request, year, month, day, post): + post = get_object_or_404(Post, slug=post, + status='published', + publish__year=year, + publish__month=month, + publish__day=day) + return render(request, + 'blog/detail.html', + {'post': post}) diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..0db2f7b Binary files /dev/null and b/db.sqlite3 differ diff --git a/mainApp/urls.py b/mainApp/urls.py index 531258a..caf0e56 100644 --- a/mainApp/urls.py +++ b/mainApp/urls.py @@ -6,5 +6,10 @@ url(r'^$', views.index, name='index'), - + url(r'^about/', + views.about, + name='about'), + url(r'^contact/', + views.contact, + name='contact') ] \ No newline at end of file diff --git a/mainApp/views.py b/mainApp/views.py index bb2a81a..4666b27 100644 --- a/mainApp/views.py +++ b/mainApp/views.py @@ -1,5 +1,7 @@ from django.shortcuts import render from .apps import MainappConfig +# BA: not sure we need to have these here +from django.http import HttpResponse # Create your views here. @@ -9,5 +11,12 @@ def index(request): :param request: the request that initiated this action :param template: the template that used for the rendering """ - page_data={"page_title":MainappConfig.index_page_name} + page_data={"page_title":MainappConfig.index_page_name,"show_carousel":True} return render(request,MainappConfig.index_page_view_tmpl,page_data) + +def about(request): + return render(request, 'wasisi/about.html') + +def contact(request): + return render(request, 'contact/contact.html') + diff --git a/static/img/favicon.ico b/static/img/favicon.ico new file mode 100644 index 0000000..478c817 Binary files /dev/null and b/static/img/favicon.ico differ diff --git a/static/img/slideshow_analytics_1280_600.jpg b/static/img/slideshow_analytics_1280_600.jpg new file mode 100644 index 0000000..edbb64d Binary files /dev/null and b/static/img/slideshow_analytics_1280_600.jpg differ diff --git a/static/img/slideshow_glossary_1280_600.jpg b/static/img/slideshow_glossary_1280_600.jpg new file mode 100644 index 0000000..9601d1e Binary files /dev/null and b/static/img/slideshow_glossary_1280_600.jpg differ diff --git a/static/img/slideshow_green_coffee_1280_600.jpg b/static/img/slideshow_green_coffee_1280_600.jpg new file mode 100644 index 0000000..04c50fd Binary files /dev/null and b/static/img/slideshow_green_coffee_1280_600.jpg differ diff --git a/static/img/slideshow_networking_1280_600.jpg b/static/img/slideshow_networking_1280_600.jpg new file mode 100644 index 0000000..3e76b8f Binary files /dev/null and b/static/img/slideshow_networking_1280_600.jpg differ diff --git a/templates/.DS_Store b/templates/.DS_Store new file mode 100644 index 0000000..3f16bea Binary files /dev/null and b/templates/.DS_Store differ diff --git a/templates/blog/detail.html b/templates/blog/detail.html new file mode 100644 index 0000000..ac6b582 --- /dev/null +++ b/templates/blog/detail.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} + {% block title %}{{ post.title }}{% endblock %} + {% block content %} +

{{ post.title }}

+

+ Published {{ post.publish }} by {{ post.author }} +

+ {{ post.body|linebreaks }} + {% endblock %} \ No newline at end of file diff --git a/templates/blog/list.html b/templates/blog/list.html new file mode 100644 index 0000000..11a9305 --- /dev/null +++ b/templates/blog/list.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + {% block title %}Blog{% endblock %} + {% block content %} +

My Blog

+ {% for post in posts %} +

+ + {{ post.title }} + +

+

+ Published {{ post.publish }} by {{ post.author }} +

+ {{ post.body|truncatewords:100|linebreaks }} + {% endfor %} + {% endblock %} \ No newline at end of file diff --git a/templates/contact/contact.html b/templates/contact/contact.html index a42181e..e0527fe 100644 --- a/templates/contact/contact.html +++ b/templates/contact/contact.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block title %}Ustudynow Contact{% endblock %} +{% block title %}Contact Wasisi{% endblock %} {% block content %} {% if messages %}
diff --git a/templates/footer.html b/templates/footer.html index d4b237e..7033d36 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -6,21 +6,21 @@
  • -
  • +

COMPANY

diff --git a/templates/nav.html b/templates/nav.html index e5f2e3b..b3bf72e 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -7,11 +7,14 @@ - +