Commit da6226fd65a825c770cf7a76d86c831522d52bf2
1 parent
0a011ec0
Exists in
master
and in
39 other branches
renaming models to resources. removing migrations
Showing
5 changed files
with
118 additions
and
138 deletions
Show diff stats
src/api/migrations/0001_initial.py
| @@ -1,20 +0,0 @@ | @@ -1,20 +0,0 @@ | ||
| 1 | -# -*- coding: utf-8 -*- | ||
| 2 | -import datetime | ||
| 3 | -from south.db import db | ||
| 4 | -from south.v2 import SchemaMigration | ||
| 5 | -from django.db import models | ||
| 6 | - | ||
| 7 | - | ||
| 8 | -class Migration(SchemaMigration): | ||
| 9 | - | ||
| 10 | - def forwards(self, orm): | ||
| 11 | - pass | ||
| 12 | - | ||
| 13 | - def backwards(self, orm): | ||
| 14 | - pass | ||
| 15 | - | ||
| 16 | - models = { | ||
| 17 | - | ||
| 18 | - } | ||
| 19 | - | ||
| 20 | - complete_apps = ['api'] | ||
| 21 | \ No newline at end of file | 0 | \ No newline at end of file |
src/api/migrations/__init__.py
src/api/models.py
| @@ -1,117 +0,0 @@ | @@ -1,117 +0,0 @@ | ||
| 1 | -# -*- coding: utf-8 -*- | ||
| 2 | - | ||
| 3 | -from tastypie import fields | ||
| 4 | -from tastypie.constants import ALL_WITH_RELATIONS, ALL | ||
| 5 | -from tastypie.resources import ModelResource | ||
| 6 | - | ||
| 7 | -from accounts.models import User | ||
| 8 | -from super_archives.models import Message, EmailAddress | ||
| 9 | -from proxy.models import Revision, Ticket, Wiki | ||
| 10 | - | ||
| 11 | - | ||
| 12 | -class UserResource(ModelResource): | ||
| 13 | - class Meta: | ||
| 14 | - queryset = User.objects.filter(is_active=True) | ||
| 15 | - resource_name = 'user' | ||
| 16 | - fields = ['username', 'institution', 'role', 'bio', 'first_name', | ||
| 17 | - 'last_name', 'email'] | ||
| 18 | - allowed_methods = ['get', ] | ||
| 19 | - filtering = { | ||
| 20 | - 'email': ('exact', ), | ||
| 21 | - 'username': ALL, | ||
| 22 | - 'institution': ALL, | ||
| 23 | - 'role': ALL, | ||
| 24 | - 'bio': ALL, | ||
| 25 | - } | ||
| 26 | - | ||
| 27 | - def dehydrate_email(self, bundle): | ||
| 28 | - return '' | ||
| 29 | - | ||
| 30 | - | ||
| 31 | -class EmailAddressResource(ModelResource): | ||
| 32 | - user = fields.ForeignKey(UserResource, 'user', full=False, null=True) | ||
| 33 | - | ||
| 34 | - class Meta: | ||
| 35 | - queryset = EmailAddress.objects.all() | ||
| 36 | - resource_name = 'emailaddress' | ||
| 37 | - excludes = ['md5', ] | ||
| 38 | - allowed_methods = ['get', ] | ||
| 39 | - filtering = { | ||
| 40 | - 'address': ('exact', ), | ||
| 41 | - 'user': ALL_WITH_RELATIONS, | ||
| 42 | - 'real_name': ALL, | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - def dehydrate_address(self, bundle): | ||
| 46 | - return '' | ||
| 47 | - | ||
| 48 | - | ||
| 49 | -class MessageResource(ModelResource): | ||
| 50 | - from_address = fields.ForeignKey(EmailAddressResource, 'from_address', | ||
| 51 | - full=False) | ||
| 52 | - | ||
| 53 | - class Meta: | ||
| 54 | - queryset = Message.objects.all() | ||
| 55 | - resource_name = 'message' | ||
| 56 | - excludes = ['spam', 'subject_clean', 'message_id'] | ||
| 57 | - filtering = { | ||
| 58 | - 'from_address': ALL_WITH_RELATIONS, | ||
| 59 | - 'subject': ALL, | ||
| 60 | - 'body': ALL, | ||
| 61 | - 'received_time': ALL, | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - | ||
| 65 | -class RevisionResource(ModelResource): | ||
| 66 | - class Meta: | ||
| 67 | - queryset = Revision.objects.all() | ||
| 68 | - resource_name = 'revision' | ||
| 69 | - excludes = ['collaborators', ] | ||
| 70 | - filtering = { | ||
| 71 | - 'key': ALL, | ||
| 72 | - 'rev': ALL, | ||
| 73 | - 'author': ALL, | ||
| 74 | - 'message': ALL, | ||
| 75 | - 'repository_name': ALL, | ||
| 76 | - 'created': ALL, | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - | ||
| 80 | -class TicketResource(ModelResource): | ||
| 81 | - class Meta: | ||
| 82 | - queryset = Ticket.objects.all() | ||
| 83 | - resource_name = 'ticket' | ||
| 84 | - excludes = ['collaborators', ] | ||
| 85 | - filtering = { | ||
| 86 | - 'id': ALL, | ||
| 87 | - 'summary': ALL, | ||
| 88 | - 'description': ALL, | ||
| 89 | - 'milestone': ALL, | ||
| 90 | - 'priority': ALL, | ||
| 91 | - 'component': ALL, | ||
| 92 | - 'version': ALL, | ||
| 93 | - 'severity': ALL, | ||
| 94 | - 'reporter': ALL, | ||
| 95 | - 'author': ALL, | ||
| 96 | - 'status': ALL, | ||
| 97 | - 'keywords': ALL, | ||
| 98 | - 'created': ALL, | ||
| 99 | - 'modified': ALL, | ||
| 100 | - 'modified_by': ALL, | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - | ||
| 104 | -class WikiResource(ModelResource): | ||
| 105 | - class Meta: | ||
| 106 | - queryset = Wiki.objects.all() | ||
| 107 | - resource_name = 'wiki' | ||
| 108 | - excludes = ['collaborators', ] | ||
| 109 | - filtering = { | ||
| 110 | - 'name': ALL, | ||
| 111 | - 'wiki_text': ALL, | ||
| 112 | - 'author': ALL, | ||
| 113 | - 'name': ALL, | ||
| 114 | - 'created': ALL, | ||
| 115 | - 'modified': ALL, | ||
| 116 | - 'modified_by': ALL, | ||
| 117 | - } |
| @@ -0,0 +1,117 @@ | @@ -0,0 +1,117 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | ||
| 2 | + | ||
| 3 | +from tastypie import fields | ||
| 4 | +from tastypie.constants import ALL_WITH_RELATIONS, ALL | ||
| 5 | +from tastypie.resources import ModelResource | ||
| 6 | + | ||
| 7 | +from accounts.models import User | ||
| 8 | +from super_archives.models import Message, EmailAddress | ||
| 9 | +from proxy.models import Revision, Ticket, Wiki | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +class UserResource(ModelResource): | ||
| 13 | + class Meta: | ||
| 14 | + queryset = User.objects.filter(is_active=True) | ||
| 15 | + resource_name = 'user' | ||
| 16 | + fields = ['username', 'institution', 'role', 'bio', 'first_name', | ||
| 17 | + 'last_name', 'email'] | ||
| 18 | + allowed_methods = ['get', ] | ||
| 19 | + filtering = { | ||
| 20 | + 'email': ('exact', ), | ||
| 21 | + 'username': ALL, | ||
| 22 | + 'institution': ALL, | ||
| 23 | + 'role': ALL, | ||
| 24 | + 'bio': ALL, | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + def dehydrate_email(self, bundle): | ||
| 28 | + return '' | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +class EmailAddressResource(ModelResource): | ||
| 32 | + user = fields.ForeignKey(UserResource, 'user', full=False, null=True) | ||
| 33 | + | ||
| 34 | + class Meta: | ||
| 35 | + queryset = EmailAddress.objects.all() | ||
| 36 | + resource_name = 'emailaddress' | ||
| 37 | + excludes = ['md5', ] | ||
| 38 | + allowed_methods = ['get', ] | ||
| 39 | + filtering = { | ||
| 40 | + 'address': ('exact', ), | ||
| 41 | + 'user': ALL_WITH_RELATIONS, | ||
| 42 | + 'real_name': ALL, | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + def dehydrate_address(self, bundle): | ||
| 46 | + return '' | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +class MessageResource(ModelResource): | ||
| 50 | + from_address = fields.ForeignKey(EmailAddressResource, 'from_address', | ||
| 51 | + full=False) | ||
| 52 | + | ||
| 53 | + class Meta: | ||
| 54 | + queryset = Message.objects.all() | ||
| 55 | + resource_name = 'message' | ||
| 56 | + excludes = ['spam', 'subject_clean', 'message_id'] | ||
| 57 | + filtering = { | ||
| 58 | + 'from_address': ALL_WITH_RELATIONS, | ||
| 59 | + 'subject': ALL, | ||
| 60 | + 'body': ALL, | ||
| 61 | + 'received_time': ALL, | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + | ||
| 65 | +class RevisionResource(ModelResource): | ||
| 66 | + class Meta: | ||
| 67 | + queryset = Revision.objects.all() | ||
| 68 | + resource_name = 'revision' | ||
| 69 | + excludes = ['collaborators', ] | ||
| 70 | + filtering = { | ||
| 71 | + 'key': ALL, | ||
| 72 | + 'rev': ALL, | ||
| 73 | + 'author': ALL, | ||
| 74 | + 'message': ALL, | ||
| 75 | + 'repository_name': ALL, | ||
| 76 | + 'created': ALL, | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + | ||
| 80 | +class TicketResource(ModelResource): | ||
| 81 | + class Meta: | ||
| 82 | + queryset = Ticket.objects.all() | ||
| 83 | + resource_name = 'ticket' | ||
| 84 | + excludes = ['collaborators', ] | ||
| 85 | + filtering = { | ||
| 86 | + 'id': ALL, | ||
| 87 | + 'summary': ALL, | ||
| 88 | + 'description': ALL, | ||
| 89 | + 'milestone': ALL, | ||
| 90 | + 'priority': ALL, | ||
| 91 | + 'component': ALL, | ||
| 92 | + 'version': ALL, | ||
| 93 | + 'severity': ALL, | ||
| 94 | + 'reporter': ALL, | ||
| 95 | + 'author': ALL, | ||
| 96 | + 'status': ALL, | ||
| 97 | + 'keywords': ALL, | ||
| 98 | + 'created': ALL, | ||
| 99 | + 'modified': ALL, | ||
| 100 | + 'modified_by': ALL, | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + | ||
| 104 | +class WikiResource(ModelResource): | ||
| 105 | + class Meta: | ||
| 106 | + queryset = Wiki.objects.all() | ||
| 107 | + resource_name = 'wiki' | ||
| 108 | + excludes = ['collaborators', ] | ||
| 109 | + filtering = { | ||
| 110 | + 'name': ALL, | ||
| 111 | + 'wiki_text': ALL, | ||
| 112 | + 'author': ALL, | ||
| 113 | + 'name': ALL, | ||
| 114 | + 'created': ALL, | ||
| 115 | + 'modified': ALL, | ||
| 116 | + 'modified_by': ALL, | ||
| 117 | + } |
src/api/urls.py
| @@ -4,7 +4,7 @@ from django.conf.urls import patterns, include, url | @@ -4,7 +4,7 @@ from django.conf.urls import patterns, include, url | ||
| 4 | 4 | ||
| 5 | from tastypie.api import Api | 5 | from tastypie.api import Api |
| 6 | 6 | ||
| 7 | -from .models import (UserResource, EmailAddressResource, MessageResource, | 7 | +from .resources import (UserResource, EmailAddressResource, MessageResource, |
| 8 | RevisionResource, TicketResource, WikiResource) | 8 | RevisionResource, TicketResource, WikiResource) |
| 9 | from .views import VoteView | 9 | from .views import VoteView |
| 10 | 10 |