This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a next step that wasn't implemented in the first implementation of bug 728877. This creates a new skills model. This inherits from a GroupBase model and so does Group. This allows for more reusable code.
- Loading branch information
Showing
16 changed files
with
425 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import jinja2 | ||
from jingo import register | ||
|
||
|
||
@register.function | ||
def stringify_groups(groups): | ||
"""Change a list of Group objects into a space-delimited string.""" | ||
""" | ||
Change a list of Group (or skills) objects into a space-delimited string. | ||
""" | ||
return u','.join([group.name for group in groups]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# encoding: utf-8 | ||
import datetime | ||
from south.db import db | ||
from south.v2 import SchemaMigration | ||
from django.db import models | ||
|
||
class Migration(SchemaMigration): | ||
|
||
def forwards(self, orm): | ||
|
||
# Adding model 'Skill' | ||
db.create_table('groups_skill', ( | ||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | ||
('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=50, db_index=True)), | ||
('auto_complete', self.gf('django.db.models.fields.BooleanField')(default=False, db_index=True)), | ||
('always_auto_complete', self.gf('django.db.models.fields.BooleanField')(default=False)), | ||
)) | ||
db.send_create_signal('groups', ['Skill']) | ||
|
||
|
||
def backwards(self, orm): | ||
|
||
# Deleting model 'Skill' | ||
db.delete_table('groups_skill') | ||
|
||
|
||
models = { | ||
'groups.group': { | ||
'Meta': {'object_name': 'Group', 'db_table': "'group'"}, | ||
'always_auto_complete': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'auto_complete': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}), | ||
'system': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), | ||
'url': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'}) | ||
}, | ||
'groups.skill': { | ||
'Meta': {'object_name': 'Skill'}, | ||
'always_auto_complete': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'auto_complete': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}) | ||
} | ||
} | ||
|
||
complete_apps = ['groups'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import json | ||
|
||
from django.contrib.auth.models import User | ||
|
||
from funfactory.urlresolvers import reverse | ||
from nose.tools import eq_ | ||
|
||
import common.tests | ||
from groups.cron import assign_autocomplete_to_groups | ||
from groups.models import AUTO_COMPLETE_COUNT, Skill | ||
|
||
|
||
class SkillzTest(common.tests.TestCase): | ||
def test_autocomplete_api(self): | ||
self.client.login(email=self.mozillian.email) | ||
|
||
r = self.client.get(reverse('skill_search'), dict(term='daft'), | ||
HTTP_X_REQUESTED_WITH='XMLHttpRequest') | ||
|
||
eq_(r['Content-Type'], 'application/json', 'api uses json header') | ||
assert not 'daft_punk' in json.loads(r.content) | ||
|
||
# Make enough users in a group to trigger the autocomplete | ||
robots = Skill.objects.create(name='true love') | ||
for i in range(0, AUTO_COMPLETE_COUNT + 1): | ||
email = 'always_angry%s@example.com' % (str(i)) | ||
user = User.objects.create_user(email.split('@')[0], email) | ||
user.is_active = True | ||
user.save() | ||
profile = user.get_profile() | ||
profile.skills.add(robots) | ||
|
||
assign_autocomplete_to_groups() | ||
r = self.client.get(reverse('skill_search'), dict(term='true'), | ||
HTTP_X_REQUESTED_WITH='XMLHttpRequest') | ||
|
||
assert 'true love' in json.loads(r.content) | ||
|
||
def test_pending_user_can_add_skills(self): | ||
"""Ensure pending users can add/edit skills.""" | ||
profile = self.pending.get_profile() | ||
assert not profile.skills.all(), 'User should have no skills.' | ||
|
||
self.client.login(email=self.pending.email) | ||
self.client.post(reverse('profile.edit'), | ||
dict(last_name='McAwesomepants', | ||
skills='Awesome foo Bar'), | ||
follow=True) | ||
|
||
assert profile.skills.all(), ( | ||
"Pending user should be able to edit skills.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.