-
Notifications
You must be signed in to change notification settings - Fork 6
Feature/megafon #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
freddylimpens
wants to merge
18
commits into
develop
Choose a base branch
from
feature/megafon
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/megafon #44
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
737b55c
Start Megafon feature
atiberghien 86d430e
Merge branch 'develop' into feature/megafon
atiberghien ec3c8f4
Fix custom end-point method
atiberghien 764612b
Add post method and permissions
atiberghien 8f93533
Add fields in post model
atiberghien 5356be3
Add parent to resource
atiberghien 5498af0
Merge branch 'develop' into feature/megafon
atiberghien 5c90317
Remove author field
atiberghien 5884a35
Implements best linked profiles method
atiberghien 15b9136
Merge branch 'develop' into feature/megafon
atiberghien 79f6c37
Merge branch 'develop' into feature/megafon
atiberghien 6d25b49
Add id filtering on Post
atiberghien 9971032
Add end-point to fetch the root post
atiberghien 7383955
Merge branch 'develop' into feature/megafon
atiberghien e4ac944
ProjectProgress icon can be nullable
atiberghien 9c128ea
Add date_joined to UserResource
atiberghien 0af155b
Do not create profile for admin
atiberghien 1aff9c9
Merge branch 'develop' into feature/megafon
atiberghien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Empty file.
This file contains hidden or 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,5 @@ | ||
from django.contrib import admin | ||
from mptt.admin import MPTTModelAdmin | ||
from .models import Post | ||
|
||
admin.site.register(Post, MPTTModelAdmin) |
This file contains hidden or 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,81 @@ | ||
from django.conf.urls import * | ||
|
||
from tastypie.resources import ModelResource | ||
from tastypie import fields | ||
|
||
from .models import Post | ||
from accounts.models import Profile | ||
|
||
from graffiti.api import TaggedItemResource | ||
from dataserver.authentication import AnonymousApiKeyAuthentication | ||
from tastypie.authorization import DjangoAuthorization | ||
from tastypie.constants import ALL_WITH_RELATIONS | ||
from tastypie.utils import trailing_slash | ||
|
||
from accounts.api import ProfileResource | ||
|
||
|
||
class PostResource(ModelResource): | ||
|
||
""" A post resource """ | ||
|
||
tags = fields.ToManyField(TaggedItemResource, 'tagged_items', full=True, null=True) | ||
parent = fields.OneToOneField("megafon.api.PostResource", 'parent', null=True) | ||
|
||
|
||
class Meta: | ||
queryset = Post.objects.all() | ||
resource_name = 'megafon/post' | ||
allowed_methods = ['get', 'post'] | ||
always_return_data = True | ||
authentication = AnonymousApiKeyAuthentication() | ||
authorization = DjangoAuthorization() | ||
|
||
filtering = { | ||
"slug": ('exact',), | ||
"id": ('exact',), | ||
"level" : ('exact', ), | ||
"answers_count" : ('exact', ), | ||
} | ||
ordering = ['updated_on', 'answers_count'] | ||
|
||
def prepend_urls(self): | ||
return [ | ||
url(r"^(?P<resource_name>%s)/questions%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_questions'), name="api_get_questions"), | ||
url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/answers%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_answers'), name="api_get_answers"), | ||
url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/root%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_root'), name="api_get_root"), | ||
] | ||
|
||
def get_questions(self, request, **kwargs): | ||
kwargs['level'] = 0 | ||
return self.get_list(request, **kwargs) | ||
|
||
|
||
def get_answers(self, request, **kwargs): | ||
self.method_check(request, allowed=['get']) | ||
self.is_authenticated(request) | ||
self.throttle_check(request) | ||
|
||
post = self.get_object_list(request).get(id=kwargs['pk']) | ||
answers = post.get_children().order_by('-updated_on') | ||
|
||
bundles = [] | ||
for obj in answers: | ||
bundle = self.build_bundle(obj=obj, request=request) | ||
bundles.append(self.full_dehydrate(bundle, for_list=True)) | ||
|
||
return self.create_response(request, {'objects' : bundles}) | ||
|
||
def get_root(self, request, **kwargs): | ||
self.method_check(request, allowed=['get']) | ||
self.is_authenticated(request) | ||
self.throttle_check(request) | ||
|
||
try : | ||
post = self.get_object_list(request).get(id=kwargs['pk']).get_root() | ||
bundle = self.build_bundle(obj=post, request=request) | ||
return self.create_response(request, self.full_dehydrate(bundle)) | ||
except: | ||
pass | ||
|
||
return self.create_response(request, {}) |
This file contains hidden or 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,93 @@ | ||
# -*- coding: utf-8 -*- | ||
from south.utils import datetime_utils as 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 'Post' | ||
db.create_table(u'megafon_post', ( | ||
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | ||
('title', self.gf('django.db.models.fields.CharField')(max_length='200', blank=True)), | ||
('posted_on', self.gf('django.db.models.fields.DateField')(auto_now_add=True, blank=True)), | ||
('author', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['accounts.Profile'])), | ||
('text', self.gf('django.db.models.fields.TextField')()), | ||
('slug', self.gf('autoslug.fields.AutoSlugField')(unique_with=('id',), max_length=50, populate_from=None)), | ||
('parent', self.gf('mptt.fields.TreeForeignKey')(blank=True, related_name='answers', null=True, to=orm['megafon.Post'])), | ||
(u'lft', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)), | ||
(u'rght', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)), | ||
(u'tree_id', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)), | ||
(u'level', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)), | ||
)) | ||
db.send_create_signal(u'megafon', ['Post']) | ||
|
||
|
||
def backwards(self, orm): | ||
# Deleting model 'Post' | ||
db.delete_table(u'megafon_post') | ||
|
||
|
||
models = { | ||
u'accounts.profile': { | ||
'Meta': {'object_name': 'Profile'}, | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'mugshot': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'blank': 'True'}), | ||
'privacy': ('django.db.models.fields.CharField', [], {'default': "'registered'", 'max_length': '15'}), | ||
'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'profile'", 'unique': 'True', 'to': u"orm['auth.User']"}) | ||
}, | ||
u'auth.group': { | ||
'Meta': {'object_name': 'Group'}, | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), | ||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) | ||
}, | ||
u'auth.permission': { | ||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, | ||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | ||
}, | ||
u'auth.user': { | ||
'Meta': {'object_name': 'User'}, | ||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), | ||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), | ||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}), | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | ||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), | ||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), | ||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}), | ||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) | ||
}, | ||
u'contenttypes.contenttype': { | ||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, | ||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) | ||
}, | ||
u'megafon.post': { | ||
'Meta': {'object_name': 'Post'}, | ||
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['accounts.Profile']"}), | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
u'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
u'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
'parent': ('mptt.fields.TreeForeignKey', [], {'blank': 'True', 'related_name': "'answers'", 'null': 'True', 'to': u"orm['megafon.Post']"}), | ||
'posted_on': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}), | ||
u'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
'slug': ('autoslug.fields.AutoSlugField', [], {'unique_with': "('id',)", 'max_length': '50', 'populate_from': 'None'}), | ||
'text': ('django.db.models.fields.TextField', [], {}), | ||
'title': ('django.db.models.fields.CharField', [], {'max_length': "'200'", 'blank': 'True'}), | ||
u'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) | ||
} | ||
} | ||
|
||
complete_apps = ['megafon'] |
98 changes: 98 additions & 0 deletions
98
...migrations/0002_auto__add_field_post_updated_on__add_field_post_answers_count__chg_fie.py
This file contains hidden or 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,98 @@ | ||
# -*- coding: utf-8 -*- | ||
from south.utils import datetime_utils as datetime | ||
from south.db import db | ||
from south.v2 import SchemaMigration | ||
from django.db import models | ||
|
||
|
||
class Migration(SchemaMigration): | ||
|
||
def forwards(self, orm): | ||
# Adding field 'Post.updated_on' | ||
db.add_column(u'megafon_post', 'updated_on', | ||
self.gf('django.db.models.fields.DateTimeField')(auto_now=True, auto_now_add=True, default=datetime.datetime(2015, 5, 28, 0, 0), blank=True), | ||
keep_default=False) | ||
|
||
# Adding field 'Post.answers_count' | ||
db.add_column(u'megafon_post', 'answers_count', | ||
self.gf('django.db.models.fields.PositiveIntegerField')(default=0), | ||
keep_default=False) | ||
|
||
|
||
# Changing field 'Post.posted_on' | ||
db.alter_column(u'megafon_post', 'posted_on', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True)) | ||
|
||
def backwards(self, orm): | ||
# Deleting field 'Post.updated_on' | ||
db.delete_column(u'megafon_post', 'updated_on') | ||
|
||
# Deleting field 'Post.answers_count' | ||
db.delete_column(u'megafon_post', 'answers_count') | ||
|
||
|
||
# Changing field 'Post.posted_on' | ||
db.alter_column(u'megafon_post', 'posted_on', self.gf('django.db.models.fields.DateField')(auto_now_add=True)) | ||
|
||
models = { | ||
u'accounts.profile': { | ||
'Meta': {'object_name': 'Profile'}, | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'mugshot': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'blank': 'True'}), | ||
'privacy': ('django.db.models.fields.CharField', [], {'default': "'registered'", 'max_length': '15'}), | ||
'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'profile'", 'unique': 'True', 'to': u"orm['auth.User']"}) | ||
}, | ||
u'auth.group': { | ||
'Meta': {'object_name': 'Group'}, | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), | ||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) | ||
}, | ||
u'auth.permission': { | ||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, | ||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | ||
}, | ||
u'auth.user': { | ||
'Meta': {'object_name': 'User'}, | ||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), | ||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), | ||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}), | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | ||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), | ||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), | ||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}), | ||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) | ||
}, | ||
u'contenttypes.contenttype': { | ||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, | ||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) | ||
}, | ||
u'megafon.post': { | ||
'Meta': {'object_name': 'Post'}, | ||
'answers_count': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), | ||
'author': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['accounts.Profile']"}), | ||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
u'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
u'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
'parent': ('mptt.fields.TreeForeignKey', [], {'blank': 'True', 'related_name': "'answers'", 'null': 'True', 'to': u"orm['megafon.Post']"}), | ||
'posted_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), | ||
u'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
'slug': ('autoslug.fields.AutoSlugField', [], {'unique_with': "('id',)", 'max_length': '50', 'populate_from': 'None'}), | ||
'text': ('django.db.models.fields.TextField', [], {}), | ||
'title': ('django.db.models.fields.CharField', [], {'max_length': "'200'", 'blank': 'True'}), | ||
u'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
'updated_on': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'auto_now_add': 'True', 'blank': 'True'}) | ||
} | ||
} | ||
|
||
complete_apps = ['megafon'] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ça me semble OK, mais je me demande juste ce qui rend cet ajout nécessaire ?