Merge lp:~zematynnad/rnr-server/remove_migrations_only_one_rnr_settings into lp:rnr-server
- remove_migrations_only_one_rnr_settings
- Merge into trunk
Proposed by
Danny Tamez
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 134 | ||||
Proposed branch: | lp:~zematynnad/rnr-server/remove_migrations_only_one_rnr_settings | ||||
Merge into: | lp:rnr-server | ||||
Diff against target: |
260 lines (+169/-13) 5 files modified
src/reviewsapp/admin.py (+12/-1) src/reviewsapp/migrations/0003_fix_moderation_mode.py (+147/-0) src/reviewsapp/models/reviews.py (+7/-9) src/reviewsapp/tests/test_models.py (+2/-2) src/reviewsapp/tests/test_rnrclient.py (+1/-1) |
||||
To merge this branch: | bzr merge lp:~zematynnad/rnr-server/remove_migrations_only_one_rnr_settings | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Nelson (community) | Approve | ||
Review via email:
|
Commit message
Removed unnecessary migration and made it so only one rnr settings object would be created from the admin site.
Description of the change
Removed unnecessary migration and made it so only one rnr settings object would be created from the admin site.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/reviewsapp/admin.py' |
2 | --- src/reviewsapp/admin.py 2011-01-27 20:07:06 +0000 |
3 | +++ src/reviewsapp/admin.py 2011-02-24 17:58:10 +0000 |
4 | @@ -22,6 +22,7 @@ |
5 | __metaclass__ = type |
6 | |
7 | from django.contrib import admin |
8 | +from django.http import HttpResponse |
9 | |
10 | from reviewsapp.models import ( |
11 | Architecture, |
12 | @@ -33,10 +34,20 @@ |
13 | SoftwareItem, |
14 | ) |
15 | |
16 | +class RNRSettingsAdmin(admin.ModelAdmin): |
17 | + """Ensure that only one instance is ever created""" |
18 | + def add_view(self, request): |
19 | + if request.method== 'POST': |
20 | + if RNRSettings.objects.count() > 0: |
21 | + return HttpResponse('Only one RNR Settings object should be ' |
22 | + 'created.') |
23 | + return super(RNRSettingsAdmin, self).add_view(request) |
24 | + |
25 | + |
26 | admin.site.register(Architecture) |
27 | admin.site.register(Repository) |
28 | admin.site.register(Review) |
29 | admin.site.register(SoftwareItem) |
30 | admin.site.register(ReviewModeration) |
31 | admin.site.register(ReviewModerationFlag) |
32 | -admin.site.register(RNRSettings) |
33 | +admin.site.register(RNRSettings, RNRSettingsAdmin) |
34 | |
35 | === added file 'src/reviewsapp/migrations/0003_fix_moderation_mode.py' |
36 | --- src/reviewsapp/migrations/0003_fix_moderation_mode.py 1970-01-01 00:00:00 +0000 |
37 | +++ src/reviewsapp/migrations/0003_fix_moderation_mode.py 2011-02-24 17:58:10 +0000 |
38 | @@ -0,0 +1,147 @@ |
39 | + |
40 | +from south.db import db |
41 | +from django.db import models |
42 | +from reviewsapp.models import * |
43 | + |
44 | +class Migration: |
45 | + |
46 | + def forwards(self, orm): |
47 | + |
48 | + # Adding field 'RNRSettings.active_moderation' |
49 | + db.add_column('reviewsapp_rnrsettings', 'active_moderation', orm['reviewsapp.rnrsettings:active_moderation']) |
50 | + |
51 | + # Deleting field 'RNRSettings.moderation_mode' |
52 | + db.delete_column('reviewsapp_rnrsettings', 'moderation_mode') |
53 | + |
54 | + |
55 | + def backwards(self, orm): |
56 | + |
57 | + # Deleting field 'RNRSettings.active_moderation' |
58 | + db.delete_column('reviewsapp_rnrsettings', 'active_moderation') |
59 | + |
60 | + # Adding field 'RNRSettings.moderation_mode' |
61 | + db.add_column('reviewsapp_rnrsettings', 'moderation_mode', orm['reviewsapp.rnrsettings:moderation_mode']) |
62 | + |
63 | + |
64 | + models = { |
65 | + 'auth.group': { |
66 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
67 | + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), |
68 | + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) |
69 | + }, |
70 | + 'auth.permission': { |
71 | + 'Meta': {'unique_together': "(('content_type', 'codename'),)"}, |
72 | + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), |
73 | + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), |
74 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
75 | + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) |
76 | + }, |
77 | + 'auth.user': { |
78 | + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), |
79 | + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), |
80 | + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), |
81 | + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), |
82 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
83 | + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}), |
84 | + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), |
85 | + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), |
86 | + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), |
87 | + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), |
88 | + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), |
89 | + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), |
90 | + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) |
91 | + }, |
92 | + 'contenttypes.contenttype': { |
93 | + 'Meta': {'unique_together': "(('app_label', 'model'),)", 'db_table': "'django_content_type'"}, |
94 | + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), |
95 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
96 | + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), |
97 | + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) |
98 | + }, |
99 | + 'reviewsapp.architecture': { |
100 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
101 | + 'tag': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16'}) |
102 | + }, |
103 | + 'reviewsapp.consumer': { |
104 | + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), |
105 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
106 | + 'key': ('django.db.models.fields.CharField', [], {'max_length': '64'}), |
107 | + 'secret': ('django.db.models.fields.CharField', [], {'default': "'HeseoRNDdWTdeQNtqdnPNwRzxINMhK'", 'max_length': '255', 'blank': 'True'}), |
108 | + 'updated_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), |
109 | + 'user': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'oauth_consumer'", 'unique': 'True', 'to': "orm['auth.User']"}) |
110 | + }, |
111 | + 'reviewsapp.nonce': { |
112 | + 'consumer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.Consumer']"}), |
113 | + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), |
114 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
115 | + 'nonce': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), |
116 | + 'token': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.Token']"}) |
117 | + }, |
118 | + 'reviewsapp.repository': { |
119 | + 'distroseries': ('django.db.models.fields.SlugField', [], {'max_length': '25', 'db_index': 'True'}), |
120 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
121 | + 'origin': ('django.db.models.fields.SlugField', [], {'max_length': '100', 'db_index': 'True'}) |
122 | + }, |
123 | + 'reviewsapp.review': { |
124 | + 'architecture': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.Architecture']"}), |
125 | + 'date_created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2011, 2, 24, 14, 59, 59, 352224)'}), |
126 | + 'hide': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}), |
127 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
128 | + 'language': ('django.db.models.fields.SlugField', [], {'max_length': '10', 'db_index': 'True'}), |
129 | + 'rating': ('django.db.models.fields.IntegerField', [], {}), |
130 | + 'repository': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.Repository']"}), |
131 | + 'review_text': ('django.db.models.fields.CharField', [], {'max_length': '5000'}), |
132 | + 'reviewer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), |
133 | + 'softwareitem': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.SoftwareItem']"}), |
134 | + 'summary': ('django.db.models.fields.CharField', [], {'max_length': '80'}), |
135 | + 'usefulness_favorable': ('django.db.models.fields.IntegerField', [], {'default': '0'}), |
136 | + 'usefulness_percentage': ('django.db.models.fields.IntegerField', [], {'default': '0'}), |
137 | + 'usefulness_total': ('django.db.models.fields.IntegerField', [], {'default': '0'}), |
138 | + 'version': ('django.db.models.fields.CharField', [], {'max_length': '100'}) |
139 | + }, |
140 | + 'reviewsapp.reviewmoderation': { |
141 | + 'date_created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2011, 2, 24, 14, 59, 59, 662685)'}), |
142 | + 'date_moderated': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}), |
143 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
144 | + 'moderation_text': ('django.db.models.fields.TextField', [], {'blank': 'True'}), |
145 | + 'moderator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}), |
146 | + 'review': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.Review']"}), |
147 | + 'status': ('django.db.models.fields.SmallIntegerField', [], {'default': '0'}) |
148 | + }, |
149 | + 'reviewsapp.reviewmoderationflag': { |
150 | + 'date_created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2011, 2, 24, 14, 59, 59, 211844)'}), |
151 | + 'description': ('django.db.models.fields.TextField', [], {}), |
152 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
153 | + 'review_moderation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.ReviewModeration']"}), |
154 | + 'summary': ('django.db.models.fields.CharField', [], {'max_length': '200'}), |
155 | + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'}) |
156 | + }, |
157 | + 'reviewsapp.rnrsettings': { |
158 | + 'active_moderation': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}), |
159 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) |
160 | + }, |
161 | + 'reviewsapp.softwareitem': { |
162 | + 'app_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}), |
163 | + 'date_ratings_updated': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2011, 2, 24, 14, 59, 58, 683635)'}), |
164 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
165 | + 'package_name': ('django.db.models.fields.SlugField', [], {'max_length': '100', 'db_index': 'True'}), |
166 | + 'ratings_average': ('django.db.models.fields.DecimalField', [], {'default': '0', 'max_digits': '3', 'decimal_places': '2'}), |
167 | + 'ratings_total': ('django.db.models.fields.IntegerField', [], {'default': '0'}) |
168 | + }, |
169 | + 'reviewsapp.token': { |
170 | + 'consumer': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.Consumer']"}), |
171 | + 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), |
172 | + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), |
173 | + 'token': ('django.db.models.fields.CharField', [], {'default': "'BjpWWxDVhEjZUheuNHQvpNutHWvidsGAkxPwmUdCKkyaJosJJT'", 'max_length': '50', 'primary_key': 'True'}), |
174 | + 'token_secret': ('django.db.models.fields.CharField', [], {'default': "'bljqMMkxKVeExEjZPLSGMdyBLdCFVTYJwwYQbtttOuJWVJOyKD'", 'max_length': '50'}), |
175 | + 'updated_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}) |
176 | + }, |
177 | + 'reviewsapp.usefulness': { |
178 | + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), |
179 | + 'review': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['reviewsapp.Review']"}), |
180 | + 'useful': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True', 'blank': 'True'}), |
181 | + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) |
182 | + } |
183 | + } |
184 | + |
185 | + complete_apps = ['reviewsapp'] |
186 | |
187 | === modified file 'src/reviewsapp/models/reviews.py' |
188 | --- src/reviewsapp/models/reviews.py 2011-02-23 21:30:12 +0000 |
189 | +++ src/reviewsapp/models/reviews.py 2011-02-24 17:58:10 +0000 |
190 | @@ -331,30 +331,28 @@ |
191 | |
192 | |
193 | class RNRSettings(models.Model): |
194 | - PASSIVE_MODE = 0 |
195 | - ACTIVE_MODE = 1 |
196 | ACTIVE_MODE_FLAG_SUMMARY = 'Automatically Flagged' |
197 | ACTIVE_MODE_FLAG_DESCRIPTION = ('This review was automatically flagged ' |
198 | 'because the rnr server was operating ' |
199 | 'in active moderation mode') |
200 | CHOICES = ( |
201 | - (PASSIVE_MODE, 'Passive - automated approval'), |
202 | - (ACTIVE_MODE, 'Active - manual approval'), |
203 | + (False, 'Passive - automated approval'), |
204 | + (True, 'Active - manual approval'), |
205 | ) |
206 | |
207 | - moderation_mode = models.SmallIntegerField(choices=CHOICES, |
208 | - default=PASSIVE_MODE) |
209 | + active_moderation = models.BooleanField(default=False, choices=CHOICES) |
210 | |
211 | @classmethod |
212 | def is_active_mode(cls): |
213 | - mode = cls.PASSIVE_MODE |
214 | + active = False |
215 | settings = RNRSettings.objects.all() |
216 | if settings: |
217 | - mode = settings[0].moderation_mode |
218 | - return mode and mode.isdigit() and int(mode) == cls.ACTIVE_MODE |
219 | + active = settings[0].active_moderation |
220 | + return active |
221 | |
222 | class Meta: |
223 | app_label = 'reviewsapp' |
224 | + verbose_name_plural = 'RNR Settings' |
225 | |
226 | |
227 | # GroupPermissions can't go in fixtures because Permissions are stored as |
228 | |
229 | === modified file 'src/reviewsapp/tests/test_models.py' |
230 | --- src/reviewsapp/tests/test_models.py 2011-02-08 10:56:58 +0000 |
231 | +++ src/reviewsapp/tests/test_models.py 2011-02-24 17:58:10 +0000 |
232 | @@ -363,13 +363,13 @@ |
233 | class RNRSettingsTestCase(TestCaseWithFactory): |
234 | def test_is_active_mode_in_active_mode(self): |
235 | rnrsettings, created = RNRSettings.objects.get_or_create( |
236 | - moderation_mode=RNRSettings.ACTIVE_MODE) |
237 | + active_moderation=True) |
238 | |
239 | self.assertTrue(RNRSettings.is_active_mode()) |
240 | |
241 | def test_is_active_mode_in_passive_mode(self): |
242 | rnrsettings, created = RNRSettings.objects.get_or_create( |
243 | - moderation_mode=RNRSettings.PASSIVE_MODE) |
244 | + active_moderation=False) |
245 | |
246 | self.assertFalse(RNRSettings.is_active_mode()) |
247 | |
248 | |
249 | === modified file 'src/reviewsapp/tests/test_rnrclient.py' |
250 | --- src/reviewsapp/tests/test_rnrclient.py 2011-02-22 10:30:20 +0000 |
251 | +++ src/reviewsapp/tests/test_rnrclient.py 2011-02-24 17:58:10 +0000 |
252 | @@ -342,7 +342,7 @@ |
253 | def test_active_mode(self): |
254 | # Put the server in active mode |
255 | settings = RNRSettings() |
256 | - settings.moderation_mode = RNRSettings.ACTIVE_MODE |
257 | + settings.active_moderation = True |
258 | settings.save() |
259 | |
260 | review_options = dict(package_name='pacman', summary='Too difficult', |
Hi Danny,
Note: continuation of https:/ /code.launchpad .net/~zematynna d/rnr-server/ fix_active_ passive_ mode_686547/ +merge/ 51161
Thanks for addressing the two points there.
If you think it's worthwhile, one improvement that I think we could make to this branch would be to use form validation for the restriction of only one rnr setting:
http:// docs.djangoproj ect.com/ en/dev/ ref/contrib/ admin/# adding- custom- validation- to-the- admin
It'll be a bit cleaner than returning a raw http response and it's just as easy to test.