1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
from datetime import datetime, timedelta
from pytz import utc
from django.contrib.sitemaps import Sitemap
from django.core.urlresolvers import reverse
from main.models import Package
from news.models import News
from packages.utils import get_group_info, get_split_packages_info
from releng.models import Release
from todolists.models import Todolist
class PackagesSitemap(Sitemap):
def items(self):
return Package.objects.normal().only(
'pkgname', 'last_update', 'files_last_update',
'repo__name', 'repo__testing', 'repo__staging',
'arch__name').order_by()
def lastmod(self, obj):
return obj.last_update
def changefreq(self, obj):
if obj.repo.testing or obj.repo.staging:
return "daily"
return "weekly"
def priority(self, obj):
if obj.repo.testing:
return "0.4"
if obj.repo.staging:
return "0.1"
return "0.5"
class PackageFilesSitemap(PackagesSitemap):
changefreq = "weekly"
priority = "0.1"
# we fixed a bug on the package files page on this day, force modification
lastmod_min = datetime(2015, 4, 12).replace(tzinfo=utc)
def location(self, obj):
return PackagesSitemap.location(self, obj) + 'files/'
def lastmod(self, obj):
update = obj.files_last_update
if update is None:
return None
return max(update, self.lastmod_min)
class PackageGroupsSitemap(Sitemap):
changefreq = "weekly"
priority = "0.4"
def items(self):
return get_group_info()
def lastmod(self, obj):
return obj['last_update']
def location(self, obj):
return '/groups/%s/%s/' % (obj['arch'], obj['name'])
class SplitPackagesSitemap(Sitemap):
changefreq = "weekly"
priority = "0.3"
def items(self):
return get_split_packages_info()
def lastmod(self, obj):
return obj['last_update']
def location(self, obj):
return '/packages/%s/%s/%s/' % (
obj['repo'].name.lower(), obj['arch'], obj['pkgbase'])
class NewsSitemap(Sitemap):
def __init__(self):
now = datetime.utcnow().replace(tzinfo=utc)
self.one_day_ago = now - timedelta(days=1)
self.one_week_ago = now - timedelta(days=7)
def items(self):
return News.objects.all().defer('content', 'guid', 'title').order_by()
def lastmod(self, obj):
return obj.last_modified
def priority(self, obj):
if obj.last_modified > self.one_week_ago:
return "0.9"
return "0.8"
def changefreq(self, obj):
if obj.last_modified > self.one_day_ago:
return 'daily'
if obj.last_modified > self.one_week_ago:
return 'weekly'
return 'yearly'
class RecentNewsSitemap(NewsSitemap):
def items(self):
now = datetime.utcnow().replace(tzinfo=utc)
cutoff = now - timedelta(days=30)
return super(RecentNewsSitemap, self).items().filter(postdate__gte=cutoff)
class ReleasesSitemap(Sitemap):
changefreq = "monthly"
def items(self):
return Release.objects.all().defer('info', 'torrent_data').order_by()
def lastmod(self, obj):
return obj.last_modified
def priority(self, obj):
if obj.available:
return "0.6"
return "0.2"
class TodolistSitemap(Sitemap):
priority = "0.4"
def __init__(self):
now = datetime.utcnow().replace(tzinfo=utc)
self.two_weeks_ago = now - timedelta(days=14)
def items(self):
return Todolist.objects.all().defer('raw').order_by()
def lastmod(self, obj):
return obj.last_modified
def changefreq(self, obj):
if obj.last_modified > self.two_weeks_ago:
return 'weekly'
return 'monthly'
class BaseSitemap(Sitemap):
DEFAULT_PRIORITY = 0.7
base_viewnames = (
('index', 1.0, 'hourly'),
('packages-search', 0.8, 'hourly'),
('page-download', 0.8, 'monthly'),
('page-keys', 0.8, 'weekly'),
('news-list', 0.7, 'weekly'),
('groups-list', 0.5, 'weekly'),
('mirror-status', 0.4, 'hourly'),
'page-about',
'page-art',
'page-svn',
'page-donate',
'feeds-list',
'mirror-list',
'mirror-status',
'mirrorlist',
'packages-differences',
('releng-test-overview', 0.3, 'monthly'),
'releng-release-list',
'visualize-index',
)
def items(self):
return self.base_viewnames
def location(self, obj):
name = obj
if isinstance(obj, tuple):
name = obj[0]
return reverse(name)
def priority(self, obj):
if isinstance(obj, tuple):
return obj[1]
return self.DEFAULT_PRIORITY
def changefreq(self, obj):
if isinstance(obj, tuple):
return obj[2]
return 'monthly'
# vim: set ts=4 sw=4 et:
|