Skip to content

Commit 7ff81e3

Browse files
committed
Merged tests for migrations file
2 parents 7cbca95 + daf1d9c commit 7ff81e3

19 files changed

+509
-53
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ install:
88

99
script:
1010
- python manage.py migrate
11+
- python manage.py test

biojs/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
try:
2727
from config import *
28-
DEBUG = False
28+
DEBUG = DEBUG
2929
except:
30-
DEBUG = True
30+
DEGUB = True
3131

3232
ALLOWED_HOSTS = ['*']
3333

main/management/commands/updatecomponents.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,33 @@ def handle(self, *args, **options):
105105

106106
if _component.github_url:
107107
print _component.github_url
108-
github_data = get_github_data(_component.github_url)
108+
try:
109+
github_data = get_github_data(_component.github_url)
110+
except:
111+
continue
109112
_component.stars = github_data['stargazers_count']
110113
_component.forks = github_data['forks']
111-
_component.watchers = github_data['watchers']
114+
# subscriber_count
115+
_component.watchers = github_data['subscribers_count']
112116
_component.icon_url = github_data['owner']['avatar_url']
113117
_component.open_issues = github_data['open_issues']
114118
try:
115119
_component.license = github_data['license']['name']
116120
except:
117121
pass
122+
try:
123+
str_date = github_data['created_at']
124+
req_date = datetime.strptime(str_date, "%Y-%m-%dT%H:%M:%SZ") #This object is timezone unaware
125+
aware_date = pytz.utc.localize(req_date) #This object is now timezone aware
126+
_component.created_time = aware_date
127+
except:
128+
pass
118129
_component.save()
119130
print str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET
120-
contributors_data = get_contributors_data(str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
131+
try:
132+
contributors_data = get_contributors_data(str(github_data['contributors_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
133+
except:
134+
continue
121135
commits = 0
122136
count = 0
123137
for contributor in contributors_data:
@@ -133,7 +147,10 @@ def handle(self, *args, **options):
133147
_contribution = Contribution.objects.create(component=_component, contributor=_contributor, contributions=contributor["contributions"])
134148
commits += _contribution.contributions
135149
count +=1
136-
_component.downloads = get_downloads(str(github_data['downloads_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
150+
try:
151+
_component.downloads = get_downloads(str(github_data['downloads_url']) + '?client_id=' + GITHUB_CLIENT_ID + '&client_secret=' + GITHUB_CLIENT_SECRET)
152+
except:
153+
pass
137154
_component.commits = commits
138155
_component.no_of_contributors = count
139156
_component.save()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.13 on 2018-06-09 08:55
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('main', '0008_auto_20180603_0800'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='component',
17+
name='created_time',
18+
field=models.DateTimeField(null=True),
19+
),
20+
]

main/models.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Component(models.Model):
2121
name = models.CharField(max_length=100)
2222
stars = models.IntegerField(default=0, null=True)
2323
downloads = models.BigIntegerField(default=0, null=True)
24-
created_time = models.DateTimeField(editable=False, null=True)
24+
created_time = models.DateTimeField(null=True)
2525
modified_time = models.DateTimeField(null=True)
2626
tags = models.ManyToManyField('Tag', null=True)
2727
icon_url = models.URLField(null=True, blank=True)
@@ -43,8 +43,6 @@ class Component(models.Model):
4343
license = models.CharField(max_length=50, null=True)
4444

4545
def save(self, *args, **kwargs):
46-
if not self.id:
47-
self.created_time = timezone.now()
4846
if not self.url_name:
4947
self.url_name = (str(self.name).replace(' ', '-')).replace('/', '-').replace('@','').lower()
5048
return super(Component, self).save(*args, **kwargs)

main/serializers.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,28 @@ class Meta:
4444

4545
class DetailComponentSerializer(serializers.ModelSerializer):
4646
tags = serializers.SerializerMethodField()
47+
github_url = serializers.SerializerMethodField()
48+
4749
def get_tags(self, obj):
4850
tags = []
4951
for t in obj.tags.all():
5052
tags.append(t.name)
5153
return tags
54+
55+
def get_github_url(self, obj):
56+
if obj.github_url:
57+
list_url = obj.github_url.split('/')
58+
return list_url[0] + '//github.com/' + list_url[4] + '/' + list_url[5].split('?')[0] # remove get request params(client_id and secret)
59+
else:
60+
return ''
61+
5262
class Meta:
5363
model = Component
5464
fields = (
5565
'name',
5666
'stars',
5767
'downloads',
68+
'created_time',
5869
'modified_time',
5970
'tags',
6071
'icon_url',
@@ -65,11 +76,9 @@ class Meta:
6576
'forks',
6677
'watchers',
6778
'no_of_contributors',
79+
'open_issues',
6880
'version',
6981
'author',
70-
'author_email',
71-
'npm_url',
72-
'homepage_url',
7382
'license',
7483
)
7584

main/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def all_components(request): # requested on_load() for querying
2727
})
2828

2929
def top_components(request):
30-
top_components = TopComponentSerializer(Component.objects.all().order_by('-downloads')[:10], many=True)
31-
print top_components
30+
# Download data is from Github and hence stars are used
31+
top_components = TopComponentSerializer(Component.objects.all().order_by('-stars')[:10], many=True)
3232
return JsonResponse({
3333
'top_components':top_components.data,
3434
})

static/admin/css/base.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,15 @@ p.mini {
187187
margin-top: -3px;
188188
}
189189

190-
.help, p.help, form p.help {
190+
.help, p.help, form p.help, div.help, form div.help, div.help li {
191191
font-size: 11px;
192192
color: #999;
193193
}
194194

195+
div.help ul {
196+
margin-bottom: 0;
197+
}
198+
195199
.help-tooltip {
196200
cursor: help;
197201
}
@@ -410,6 +414,9 @@ input, textarea, select, .form-row p, form .button {
410414
font-weight: normal;
411415
font-size: 13px;
412416
}
417+
.form-row div.help {
418+
padding: 2px 3px;
419+
}
413420

414421
textarea {
415422
vertical-align: top;
@@ -731,7 +738,7 @@ a.deletelink:focus, a.deletelink:hover {
731738

732739
.object-tools a.viewsitelink, .object-tools a.golink,.object-tools a.addlink {
733740
background-repeat: no-repeat;
734-
background-position: 93% center;
741+
background-position: right 7px center;
735742
padding-right: 26px;
736743
}
737744

static/admin/css/changelists.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@
166166
#changelist-filter a {
167167
display: block;
168168
color: #999;
169+
text-overflow: ellipsis;
170+
overflow-x: hidden;
169171
}
170172

171173
#changelist-filter li.selected {

static/admin/css/dashboard.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
ul.actionlist li {
2323
list-style-type: none;
24-
}
25-
26-
ul.actionlist li {
2724
overflow: hidden;
2825
text-overflow: ellipsis;
2926
-o-text-overflow: ellipsis;

0 commit comments

Comments
 (0)