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
Binary file added .DS_Store
Binary file not shown.
Binary file added blog/.DS_Store
Binary file not shown.
Empty file added blog/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions blog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BlogConfig(AppConfig):
name = 'blog'
34 changes: 34 additions & 0 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
Empty file added blog/migrations/__init__.py
Empty file.
59 changes: 59 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions blog/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.
10 changes: 10 additions & 0 deletions blog/urls.py
Original file line number Diff line number Diff line change
@@ -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<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/'\
r'(?P<post>[-\w]+)/$',
views.post_detail, name='post_detail'),
]
21 changes: 21 additions & 0 deletions blog/views.py
Original file line number Diff line number Diff line change
@@ -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})
Binary file added db.sqlite3
Binary file not shown.
7 changes: 6 additions & 1 deletion mainApp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
url(r'^$',
views.index,
name='index'),

url(r'^about/',
views.about,
name='about'),
url(r'^contact/',
views.contact,
name='contact')
]
11 changes: 10 additions & 1 deletion mainApp/views.py
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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')

Binary file added static/img/favicon.ico
Binary file not shown.
Binary file added static/img/slideshow_analytics_1280_600.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/slideshow_glossary_1280_600.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/slideshow_green_coffee_1280_600.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/slideshow_networking_1280_600.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/.DS_Store
Binary file not shown.
9 changes: 9 additions & 0 deletions templates/blog/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block title %}{{ post.title }}{% endblock %}
{% block content %}
<h1>{{ post.title }}</h1>
<p class="date">
Published {{ post.publish }} by {{ post.author }}
</p>
{{ post.body|linebreaks }}
{% endblock %}
16 changes: 16 additions & 0 deletions templates/blog/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}Blog{% endblock %}
{% block content %}
<h1>My Blog</h1>
{% for post in posts %}
<h2>
<a href="{{ post.get_absolute_url }}">
{{ post.title }}
</a>
</h2>
<p class="date">
Published {{ post.publish }} by {{ post.author }}
</p>
{{ post.body|truncatewords:100|linebreaks }}
{% endfor %}
{% endblock %}
2 changes: 1 addition & 1 deletion templates/contact/contact.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.html" %}
{% block title %}Ustudynow Contact{% endblock %}
{% block title %}Contact Wasisi{% endblock %}
{% block content %}
{% if messages %}
<div class="container-fluid">
Expand Down
8 changes: 4 additions & 4 deletions templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
<ul class="list-unstyled list-inline list-social-icons">
<li><a href="#"><i class="fa fa-facebook-square fa-2x"></i></a></li>
<li><a href="#"><i class="fa fa-linkedin-square fa-2x"></i></a></li>
<li><a href="#"><i class="fa fa-twitter-square fa-2x"></i></a></li>
<li><a href="https://twitter.com/wasisivillage"><i class="fa fa-twitter-square fa-2x"></i></a></li>
</ul>
</div>
<div class="col-md-4">
<h4 class="ustdy-header-three"><strong>COMPANY</strong></h4>
<ul class="list-unstyled list-social-icons">
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</div>
<div class="col-md-4">
<h4 class="ustdy-header-three"><strong>PLATFORM</strong></h4>
<ul class="list-unstyled list-social-icons">
<li><a href="#">Coffee Analytics</a></li>
<li><a href="#" >Log in</a></li>
<li><a href="{% url 'accountApp:log_in' %}" >Log in</a></li>
</ul>
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions templates/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><strong id="ustdy-logo" class="ustdy-header-three">Wasisi</strong></a>
<a class="navbar-brand" href="/about"><strong id="ustdy-logo" class="ustdy-header-three">Wasisi</strong></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse pull-right" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li {% if selectcourses %}class="active" {%endif%}>
<a href="/about" >About</a>
</li>
<li {% if selectcourses %}class="active" {%endif%}>
<a href="#" >Coffee</a>
</li>
<li {% if selectlibrary %}class="active" {%endif%}>
<a href="#">Coffee Analytics</a>
</li>
<li {% if selecttutoring %}class="active" {%endif%}>
<a href="#">Contact</a>
<a href="/blog">Blog</a>
</li>
<li {%if selectcontact == True %} class="active" {% endif %}>
<a href="#" >Developer</a>
<a href="/contact" >Contact</a>
</li>

<li>
Expand Down
Loading