Merge branch 'squash-test'
diff --git a/app/soc/logic/document.py b/app/soc/logic/document.py
index be1deb8..42932ae 100644
--- a/app/soc/logic/document.py
+++ b/app/soc/logic/document.py
@@ -29,24 +29,27 @@
A query object that fetches all the documents that should be visible for
the profile's roles in the current program.
"""
- q = document_model.Document.all()
- q.filter('scope', data.program)
+ query = document_model.Document.all()
+ query.filter('scope', data.program)
- roles = []
+ visibilities = []
if data.is_student:
- roles.append('student')
+ visibilities.append(document_model.STUDENT_VISIBILITY.identifier)
+ if data.student_info.number_of_projects > 0:
+ visibilities.append(
+ document_model.ACCEPTED_STUDENT_VISIBILITY.identifier)
if data.is_org_admin:
- roles.append('org_admin')
+ visibilities.append(document_model.ORG_ADMIN_VISIBILITY.identifier)
if data.is_mentor:
- roles.append('mentor')
+ visibilities.append(document_model.MENTOR_VISIBILITY.identifier)
- num_roles = len(roles)
+ num_visibilities = len(visibilities)
- # When number of roles is 0, then the profile should belong to a host, so
- # we apply no filtering.
- if num_roles == 1:
- q.filter('dashboard_visibility', roles[0])
- elif num_roles > 1:
- q.filter('dashboard_visibility IN', roles)
+ # When number of visibilities is 0, then the profile should belong
+ # to a host, so we apply no filtering.
+ if num_visibilities == 1:
+ query.filter('dashboard_visibility', visibilities[0])
+ elif num_visibilities > 1:
+ query.filter('dashboard_visibility IN', visibilities)
- return q
+ return query
diff --git a/app/soc/models/document.py b/app/soc/models/document.py
index 2c4f5fc..d168678 100644
--- a/app/soc/models/document.py
+++ b/app/soc/models/document.py
@@ -23,6 +23,44 @@
import soc.models.work
+class DashboardVisibility(object):
+ """Represent different categories of visibilities for Document.
+
+ In other words, the main purpose of this class is to specify a group
+ of users for which a document tagged with a specific category will be
+ visible or listed.
+
+ This class should not be instantiated. Clients should use constants
+ which are defined here or in related modules.
+ """
+
+ def __init__(self, identifier, verbose_name):
+ """Constructs a new visibility category with the specified
+ identifier and verbose name.
+
+ This constructor is private to this module and related modules,
+ i.e. containing subclasses of Document model. It should not
+ be called by clients directly.
+
+ Args:
+ identifier: identifier of the category which will be stored
+ in the datastore.
+ verbose_name: verbose name of the category which will be displayed
+ to users.
+ """
+ self.identifier = identifier
+ self.verbose_name = verbose_name
+
+STUDENT_VISIBILITY = DashboardVisibility('student', 'Students')
+MENTOR_VISIBILITY = DashboardVisibility('mentor', 'Mentors')
+ORG_ADMIN_VISIBILITY = DashboardVisibility(
+ 'org_admin', 'Organization Admins')
+# TODO(daniel): the last one should be moved somewhere to a SoC specific
+# module, as it makes sense only for those programs
+ACCEPTED_STUDENT_VISIBILITY = DashboardVisibility(
+ 'accepted_student', 'Accepted Students')
+
+
class Document(soc.models.work.Work):
"""Model of a Document.
@@ -36,9 +74,13 @@
work.content: the rich-text contents of the Document
"""
- DOCUMENT_ACCESS = ['admin', 'restricted', 'member', 'user']
+ # list of all possible dashboard visibilities
+ DASHBOARD_VISIBILITIES = [
+ STUDENT_VISIBILITY, MENTOR_VISIBILITY, ORG_ADMIN_VISIBILITY,
+ ACCEPTED_STUDENT_VISIBILITY,
+ ]
- VISIBILITY = ['org_admin', 'mentor', 'student']
+ DOCUMENT_ACCESS = ['admin', 'restricted', 'member', 'user']
#: field storing the prefix of this document
prefix = db.StringProperty(default='user', required=True,
diff --git a/app/soc/modules/gci/views/document.py b/app/soc/modules/gci/views/document.py
index a923d1a..529b2b1 100644
--- a/app/soc/modules/gci/views/document.py
+++ b/app/soc/modules/gci/views/document.py
@@ -30,8 +30,10 @@
class GCIDocumentForm(forms.GCIModelForm, document.DocumentForm):
"""Django form for creating documents."""
- dashboard_visibility = forms.MultipleChoiceField(required=False,
- choices=[(v, v) for v in document_model.Document.VISIBILITY],
+ dashboard_visibility = forms.MultipleChoiceField(
+ required=False,
+ choices=[(c.identifier, c.verbose_name)
+ for c in document_model.Document.DASHBOARD_VISIBILITIES],
widget=forms.CheckboxSelectMultiple)
Meta = document.DocumentForm.Meta
diff --git a/app/soc/views/document.py b/app/soc/views/document.py
index 24b6828..6ac40db 100644
--- a/app/soc/views/document.py
+++ b/app/soc/views/document.py
@@ -25,8 +25,10 @@
class DocumentForm(forms.ModelForm):
"""Django form for creating documents."""
- dashboard_visibility = forms.MultipleChoiceField(required=False,
- choices=[(v, v) for v in document_model.Document.VISIBILITY],
+ dashboard_visibility = forms.MultipleChoiceField(
+ required=False,
+ choices=[(c.identifier, c.verbose_name)
+ for c in document_model.Document.DASHBOARD_VISIBILITIES],
widget=forms.CheckboxSelectMultiple)
def __init__(self, *args, **kwargs):