Merge lp:~daker/loco-team-portal/fix.960695.articles-app into lp:loco-team-portal

Proposed by Adnane Belmadiaf
Status: Merged
Approved by: Chris Johnston
Approved revision: 533
Merged at revision: 538
Proposed branch: lp:~daker/loco-team-portal/fix.960695.articles-app
Merge into: lp:loco-team-portal
Diff against target: 169 lines (+21/-15)
5 files modified
loco_directory/articles/admin.py (+2/-1)
loco_directory/articles/management/commands/refresh.py (+5/-4)
loco_directory/articles/models.py (+10/-7)
loco_directory/articles/tests.py (+3/-2)
pylint.rc (+1/-1)
To merge this branch: bzr merge lp:~daker/loco-team-portal/fix.960695.articles-app
Reviewer Review Type Date Requested Status
Chris Johnston Approve
Review via email: mp+108428@code.launchpad.net

Commit message

* Fixed the articles app coding style
* Disable R0903,R0904,R0914 checkers

To post a comment you must log in.
532. By Adnane Belmadiaf

* Fixed the articles app coding styles

533. By Adnane Belmadiaf

* Fixed the refresh command
* Remove unused import

Revision history for this message
Chris Johnston (cjohnston) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loco_directory/articles/admin.py'
2--- loco_directory/articles/admin.py 2011-06-01 22:19:20 +0000
3+++ loco_directory/articles/admin.py 2012-06-01 21:43:18 +0000
4@@ -1,13 +1,14 @@
5 from articles.models import Feed, Article
6 from django.contrib import admin
7
8+
9 class FeedAdmin(admin.ModelAdmin):
10 list_display = ('title', 'team', 'user', 'url', 'last_updated')
11 list_filter = ('team',)
12 admin.site.register(Feed, FeedAdmin)
13
14+
15 class ArticleAdmin(admin.ModelAdmin):
16 list_display = ('title', 'source', 'published', 'imported')
17 list_filter = ('source',)
18 admin.site.register(Article, ArticleAdmin)
19-
20
21=== modified file 'loco_directory/articles/management/commands/refresh.py'
22--- loco_directory/articles/management/commands/refresh.py 2011-06-01 22:19:20 +0000
23+++ loco_directory/articles/management/commands/refresh.py 2012-06-01 21:43:18 +0000
24@@ -4,25 +4,26 @@
25
26 import os
27 import datetime
28-import time
29
30 from django.core.management.base import NoArgsCommand
31
32 from articles.models import Feed
33
34 REFRESH_LOCK = '/var/lock/loco-directory/refresh'
35+
36+
37 class Command(NoArgsCommand):
38 help = "Updates all Feeds in the database."
39
40 def handle_noargs(self, **options):
41 verbosity = int(options.get('verbosity', 1))
42-
43+
44 # obtain lock
45 if not os.path.exists(os.path.dirname(REFRESH_LOCK)):
46 if verbosity >= 2:
47 print "Creating lock file directory"
48 os.mkdir(os.path.dirname(REFRESH_LOCK))
49-
50+
51 if os.path.exists(REFRESH_LOCK):
52 if verbosity >= 2:
53 print "Lock file exists, exiting"
54@@ -37,7 +38,7 @@
55 raise Exception("Failed to open lock file")
56 lock.write('%s\n' % os.getpid())
57 lock.close()
58-
59+
60 try:
61 if verbosity >= 2:
62 print "Processing feeds"
63
64=== modified file 'loco_directory/articles/models.py'
65--- loco_directory/articles/models.py 2011-09-01 16:44:24 +0000
66+++ loco_directory/articles/models.py 2012-06-01 21:43:18 +0000
67@@ -6,13 +6,13 @@
68 import urllib2
69
70 from django.db import models
71-from django.contrib.auth.models import User
72 from django.utils.html import strip_tags
73 from django.conf import settings
74
75 from teams.models import Team
76 from userprofiles.models import UserProfile
77
78+
79 def create_feed(user, url):
80 data = feedparser.parse(url)
81 feed = Feed(
82@@ -23,15 +23,17 @@
83 feed.save()
84 feed.update(data)
85
86+
87 def get_entry_id(entry, feed):
88 if hasattr(entry, 'id'):
89 return entry.id
90-
91+
92 if hasattr(entry, 'link'):
93 return entry.link
94-
95+
96 return '%s:%s' % (feed.id, hash(entry.title))
97-
98+
99+
100 class Feed(models.Model):
101 user = models.ForeignKey(UserProfile, blank=True, null=True)
102 team = models.ForeignKey(Team, blank=True, null=True)
103@@ -53,10 +55,10 @@
104 handlers = []
105 proxy = getattr(settings, 'HTTP_PROXY', None)
106 if proxy:
107- handlers.append(urllib2.ProxyHandler( {"http": proxy} ))
108+ handlers.append(urllib2.ProxyHandler({"http": proxy}))
109 data = feedparser.parse(self.url, modified=self.last_updated.utctimetuple(), handlers=handlers)
110 socket.setdefaulttimeout(old_timeout)
111-
112+
113 if not data or not hasattr(data, 'entries') or len(data.entries) == 0:
114 # No new entries for this feed
115 return
116@@ -103,6 +105,7 @@
117 obsolete_articles = existing_articles - returned_articles
118 Article.objects.filter(source=self, uid__in=obsolete_articles).delete()
119
120+
121 class Article(models.Model):
122 source = models.ForeignKey(Feed, null=True, blank=True)
123 uid = models.CharField(max_length=256)
124@@ -114,7 +117,7 @@
125 snippet = models.CharField(max_length=512, null=True, blank=True)
126
127 class Meta:
128- ordering = ['-imported', '-published',]
129+ ordering = ['-imported', '-published', ]
130
131 def __unicode__(self):
132 return u'%s (%s)' % (self.title, self.author)
133
134=== modified file 'loco_directory/articles/tests.py'
135--- loco_directory/articles/tests.py 2011-08-27 16:05:53 +0000
136+++ loco_directory/articles/tests.py 2012-06-01 21:43:18 +0000
137@@ -1,8 +1,8 @@
138 from django.test import TestCase
139-from django.test.client import Client
140
141 from articles.models import Feed, Article
142
143+
144 class ArticlesTests(TestCase):
145
146 def setUp(self):
147@@ -14,7 +14,8 @@
148 """Just make sure everything is set up correctly."""
149 self.assert_(True)
150 try:
151- import feedparser
152+ import feedparser # NOQA
153+ print feedparser.__version__
154 except:
155 self.assert_(False)
156
157
158=== modified file 'pylint.rc'
159--- pylint.rc 2012-05-26 13:57:29 +0000
160+++ pylint.rc 2012-06-01 21:43:18 +0000
161@@ -15,7 +15,7 @@
162 # W0613 Unused argument %r Used when a function or method argument is not used.
163 # W0702 No exception's type specified Used when an except clause doesn't specify exceptions type to catch.
164 # R0201 Method could be a function
165-disable=C0111,I0011,I0012,W0704,W0142,W0212,W0232,W0613,W0702,R0201
166+disable=C0111,I0011,I0012,W0704,W0142,W0212,W0232,W0613,W0702,R0201,R0903,R0904,R0914
167
168 [REPORTS]
169 output-format=parseable

Subscribers

People subscribed via source and target branches