Skip to content

Commit

Permalink
Merge 7a68ae1 into 2fba2cc
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolestCatMona committed Jun 10, 2020
2 parents 2fba2cc + 7a68ae1 commit 1f1e0e1
Show file tree
Hide file tree
Showing 57 changed files with 510 additions and 587 deletions.
66 changes: 65 additions & 1 deletion docs/styleguide.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Template Style Guide
======
### Teamwork Project
#### Revision 1 | April 15, 2017
#### Revision 2 | June 10, 2020

#### Goal: define a standard style for HTML templates in order to unify the Teamwork user interface.

Expand Down Expand Up @@ -43,6 +43,70 @@ See project views for examples of properly formated page info, specifically view

**Please note that you may have to remove a hard coded title in the html.**

## Styling Python Code

You should follow the [Google Style Guide](https://google.github.io/styleguide/pyguide.html) for python code.

```python
def module_level_function(param1, param2=None, *args, **kwargs):
"""This is an example of a module level function.
Function parameters should be documented in the ``Args`` section. The name
of each parameter is required. The type and description of each parameter
is optional, but should be included if not obvious.
If \*args or \*\*kwargs are accepted,
they should be listed as ``*args`` and ``**kwargs``.
The format for a parameter is::
name (type): description
The description may span multiple lines. Following
lines should be indented. The "(type)" is optional.
Multiple paragraphs are supported in parameter
descriptions.
Args:
param1 (int): The first parameter.
param2 (:obj:`str`, optional): The second parameter. Defaults to None.
Second line of description should be indented.
*args: Variable length argument list.
**kwargs: Arbitrary keyword arguments.
Returns:
bool: True if successful, False otherwise.
The return type is optional and may be specified at the beginning of
the ``Returns`` section followed by a colon.
The ``Returns`` section may span multiple lines and paragraphs.
Following lines should be indented to match the first line.
The ``Returns`` section supports any reStructuredText formatting,
including literal blocks::
{
'param1': param1,
'param2': param2
}
Raises:
AttributeError: The ``Raises`` section is a list of all exceptions
that are relevant to the interface.
ValueError: If `param2` is equal to `param1`.
"""
if param1 == param2:
raise ValueError('param1 may not be equal to param2')
return True
```
*Taken from* [example_google.py](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)

**Variables** should be in ```snake_case```

**Global Variables** should be in ```UPPERCASE_SNAKE_CASE```

## Adding breadcrumbs to an HTML template.

Take a look at base.hmtl to see where the breadcrumb block is defined:
Expand Down
1 change: 1 addition & 0 deletions teamwork/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module Initialization."""
1 change: 1 addition & 0 deletions teamwork/apps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module Initialization."""
1 change: 1 addition & 0 deletions teamwork/apps/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module Initialization."""
1 change: 1 addition & 0 deletions teamwork/apps/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .models import *


"""
Upload a csv file form
Expand Down
26 changes: 11 additions & 15 deletions teamwork/apps/core/helpers.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
# Required headers for sendgrid: (sendgrid, os)
from sendgrid import SendGridAPIClient
import codecs
# csv
import csv
import os
from sendgrid.helpers.mail import Mail, Email, Personalization, Content

from django.http import JsonResponse
from django.db.models import Q
from django.conf import settings

from django.contrib.auth.decorators import login_required
# Django
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404, redirect, render
from django.db.models import Q
from django.http import (HttpResponse, HttpResponseBadRequest,
HttpResponseRedirect)

# csv
import csv
import codecs

from teamwork.apps.projects.models import Project
HttpResponseRedirect, JsonResponse)
from django.shortcuts import get_object_or_404, redirect, render
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Content, Email, Mail, Personalization
from teamwork.apps.courses.models import Course
from teamwork.apps.projects.models import Project


def send_email(recipients, gt_email, subject, content):
Expand Down Expand Up @@ -86,7 +82,7 @@ def send_email(recipients, gt_email, subject, content):

def parse_csv(csv_file):
"""
parse csv file
parse csv file.
Expects csv file to contain headers containing: first name, last name, email
Expand Down
18 changes: 8 additions & 10 deletions teamwork/apps/core/models.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
from __future__ import unicode_literals

from django.contrib.auth import get_user_model
# Used for Email Address authentication method
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.template.defaultfilters import slugify
from django.utils import timezone

# Used for Email Address authentication method
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth import get_user_model

from teamwork.apps.courses.models import *
from teamwork.apps.projects.models import *
from teamwork.apps.projects.models import to_bits, from_bits


class EmailAddressAuthBackend(ModelBackend):
"""
Authentication backend used to determine if a users email & password are valid.
Returns:
- None if Email doesn't exist or password doesn't match Email
- UserModel object if email and password match
Authentication backend used to determine if a users email & password are valid. Returns:
- None if Email doesn't exist or password doesn't match Email
- UserModel object if email and password match
"""
def authenticate(self, username=None, password=None, **kwargs):
UserModel = get_user_model()
Expand Down
92 changes: 33 additions & 59 deletions teamwork/apps/core/tests.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from django.core.urlresolvers import resolve
from django.test import TestCase, Client

from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import resolve
from django.test import Client, TestCase
from django.urls import reverse
from teamwork.apps.core.views import *
from teamwork.apps.core.models import EmailAddressAuthBackend, po_match, sort, auto_ros, by_schedule
from teamwork.apps.core.helpers import *

from teamwork.apps.core.models import (EmailAddressAuthBackend, auto_ros,
by_schedule, po_match, sort)
from teamwork.apps.core.views import *
from teamwork.apps.courses.models import *
from teamwork.apps.profiles.models import *
from teamwork.apps.projects.models import *
from teamwork.apps.courses.models import *


def create_project(creator, scrum_master, ta, course, slug):
project = Project.objects.create(creator=creator,
Expand All @@ -36,43 +36,30 @@ def create_project_membership(user, project, invite_reason):
return Membership.objects.create(user=user, project=project, invite_reason=invite_reason)

class AuthenticateWithEmailTest(TestCase):
"""
Creates a user and asserts return values are correct from authenticate method
"""
"""Creates a user and asserts return values are correct from authenticate method."""
def setUp(self):
"""
Init any variables that are needed for testing
"""
"""Init any variables that are needed for testing."""
self.user1 = User.objects.create_user('user_test1', 'test1@test.com', 'groupthink')

def tearDown(self):
"""
Delete any variables that were created for testing
"""
"""Delete any variables that were created for testing."""
del self.user1

def testAuthenticateSuccess(self):
"""
Attempt to authenticate user w/ correct email address and pw and assert user object is returned
"""
"""Attempt to authenticate user w/ correct email address and pw and assert user object is
returned."""
user = EmailAddressAuthBackend.authenticate(self, username='test1@test.com', password='groupthink')
self.assertTrue(type(user) is User)

def testAuthenticateFail(self):
"""
Attempt to authenticate user w/ incorrect password and assert user object is None
"""
"""Attempt to authenticate user w/ incorrect password and assert user object is None."""
user = EmailAddressAuthBackend.authenticate(self, username='test1@test.com', password='incorrect')
self.assertIsNone(user)

class FindProjectMatchesTest(TestCase):
"""
Tests for the po_match method
"""
"""Tests for the po_match method."""
def setUp(self):
"""
Init any variables that are needed for testing
"""
"""Init any variables that are needed for testing."""
# create users
self.user1 = User.objects.create_user('user1', 'user1@test.com', 'testing')
self.user2 = User.objects.create_user('user2', 'user2@test.com', 'testing')
Expand Down Expand Up @@ -114,9 +101,7 @@ def setUp(self):
self.project.interest.add(self.interest2)

def tearDown(self):
"""
Delete any variables that were created for testing
"""
"""Delete any variables that were created for testing."""
# delete users
del self.user1
del self.user2
Expand All @@ -138,7 +123,9 @@ def tearDown(self):

def testMatchWithoutScheduleBonus(self):
"""
Runs po_match, with User2 showing interest 5, and User3 showing interest 4. Users schedules are NOT set.
Runs po_match, with User2 showing interest 5, and User3 showing interest 4.
Users schedules are NOT set.
"""
matchesList = po_match(self.project)

Expand All @@ -153,7 +140,9 @@ def testMatchWithoutScheduleBonus(self):

def testMatchWithProjectDesiringSkills(self):
"""
Runs po_match, with the project desiring the skill User3 knows. Users schedules are NOT set.
Runs po_match, with the project desiring the skill User3 knows.
Users schedules are NOT set.
"""
# Add user3's skill as a desired skill
self.project.desired_skills.add(self.skill2)
Expand All @@ -169,18 +158,14 @@ def testMatchWithProjectDesiringSkills(self):

# TODO:
def testMatchWithScheduleBonus(self):
"""
Runs po_match, with user2's scheduling fitting into the existing member's schedule, and user3's not ligning up
"""
"""Runs po_match, with user2's scheduling fitting into the existing member's schedule, and
user3's not ligning up."""

# TODO: sort
class SortMatchListTest(TestCase):
"""
"""
""""""
def setUp(self):
"""
Init any variables that are needed for testing
"""
"""Init any variables that are needed for testing."""
# create users
self.user1 = User.objects.create_user('user1', 'user1@test.com', 'testing')
self.user2 = User.objects.create_user('user2', 'user2@test.com', 'testing')
Expand All @@ -190,9 +175,7 @@ def setUp(self):
self.course = Course.objects.create(name='TestCourse',slug='Test1', creator=self.user1)

def tearDown(self):
"""
Delete any variables that were created for testing
"""
"""Delete any variables that were created for testing."""
del self.user1
del self.user2
del self.user3
Expand All @@ -201,12 +184,9 @@ def tearDown(self):

# TODO: auto_ros tests
class AutoSetRosterTest(TestCase):
"""
"""
""""""
def setUp(self):
"""
Init any variables that are needed for testing
"""
"""Init any variables that are needed for testing."""
# create users
self.user1 = User.objects.create_user('user1', 'user1@test.com', 'testing')
self.user2 = User.objects.create_user('user2', 'user2@test.com', 'testing')
Expand All @@ -216,9 +196,7 @@ def setUp(self):
self.course = Course.objects.create(name='TestCourse',slug='Test1', creator=self.user1)

def tearDown(self):
"""
Delete any variables that were created for testing
"""
"""Delete any variables that were created for testing."""
del self.user1
del self.user2
del self.user3
Expand All @@ -238,14 +216,10 @@ class GetAvailabilityScoreTest(TestCase):
Returns: An integer that is floor(# meeting hours/ # pos meetings)
"""
def setUp(self):
"""
Init any variables that are needed for testing
"""
"""Init any variables that are needed for testing."""

def tearDown(self):
"""
Delete any variables that were created for testing
"""
"""Delete any variables that were created for testing."""

# TODO: adjust send_email to be more testable
class EmailTests(TestCase):
Expand Down
1 change: 1 addition & 0 deletions teamwork/apps/core/views/AboutView.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.shortcuts import render


def about(request):
page_name = "Frequently Asked Questions"
page_description = "GrepThink"
Expand Down
5 changes: 2 additions & 3 deletions teamwork/apps/core/views/ContactView.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.shortcuts import get_object_or_404, redirect, render


def contact(request):
"""
Renders the ContactUs page
"""
"""Renders the ContactUs page."""
return render(request, 'core/contact.html')

0 comments on commit 1f1e0e1

Please sign in to comment.