Skip to content

Commit

Permalink
Quelques amelioration selon landscape
Browse files Browse the repository at this point in the history
  • Loading branch information
Eskimon committed May 15, 2015
1 parent df53e04 commit 49cf001
Show file tree
Hide file tree
Showing 19 changed files with 103 additions and 92 deletions.
6 changes: 5 additions & 1 deletion .landscape.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ ignore-paths:
ignore-patterns:
- manage.py
uses:
- django
- django
pylint:
disable:
- too-many-ancestors
- too-many-lines
8 changes: 4 additions & 4 deletions zds/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def get_fields(self):
if expands:
fields = self._update_expand_fields(fields, expands)

format = request.META.get('HTTP_X_DATA_FORMAT') or 'Markdown'
xdata_format = request.META.get('HTTP_X_DATA_FORMAT') or 'Markdown'
if hasattr(self.Meta, 'formats'):
fields = self._update_format_fields(fields, format)
fields = self._update_format_fields(fields, xdata_format)

return fields

Expand Down Expand Up @@ -55,15 +55,15 @@ def _update_expand_fields(self, fields, expands):

return fields

def _update_format_fields(self, fields, format='Markdown'):
def _update_format_fields(self, fields, xdata_format='Markdown'):
assert hasattr(self.Meta, 'formats'), (
'Class {serializer_class} missing "Meta.formats" attribute'.format(
serializer_class=self.__class__.__name__
)
)

for current in self.Meta.formats:
if current != format:
if current != xdata_format:
fields.pop(self.Meta.formats[current])

return fields
6 changes: 3 additions & 3 deletions zds/gallery/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _prepare(cls, create, **kwargs):
user = kwargs.pop('user', None)
gallery = kwargs.pop('gallery', None)
if user is not None and gallery is not None:
ug = super(UserGalleryFactory, cls)._prepare(create, user=user, gallery=gallery, **kwargs)
user_gal = super(UserGalleryFactory, cls)._prepare(create, user=user, gallery=gallery, **kwargs)
else:
ug = None
return ug
user_gal = None
return user_gal
4 changes: 2 additions & 2 deletions zds/gallery/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def __init__(self, *args, **kwargs):
def clean(self):
cleaned_data = super(ArchiveImageForm, self).clean()

file = cleaned_data.get('file')
extension = file.name.split('.')[-1]
zip_file = cleaned_data.get('file')
extension = zip_file.name.split('.')[-1]

if extension != "zip":
self._errors['file'] = self.error_class(
Expand Down
42 changes: 23 additions & 19 deletions zds/gallery/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@


urlpatterns = patterns('',
# Add and edit a gallery
url(r'^nouveau/$', NewGallery.as_view(), name='gallery-new'),
url(r'^modifier/$', 'zds.gallery.views.modify_gallery'),

# Image operations
url(r'^image/ajouter/(?P<pk_gallery>\d+)/$', NewImage.as_view(), name='gallery-image-new'),
url(r'^image/supprimer/$', DeleteImages.as_view(), name='gallery-image-delete'),
url(r'^image/editer/(?P<pk_gallery>\d+)/(?P<pk>\d+)/$', EditImage.as_view(), name='gallery-image-edit'),
url(r'^image/importer/(?P<pk_gallery>\d+)/$', ImportImages.as_view(), name='gallery-image-import'),

# View a gallery
url(r'^(?P<pk>\d+)/(?P<slug>.+)/$', GalleryDetails.as_view(), name='gallery-details'),

# edit a gallery
url(r'^editer/(?P<pk>\d+)/(?P<slug>.+)/$', EditGallery.as_view(), name='gallery-edit'),

# Index
url(r'^$', ListGallery.as_view(), name='gallery-list'),
)
# Add and edit a gallery
url(r'^nouveau/$', NewGallery.as_view(), name='gallery-new'),
url(r'^modifier/$', 'zds.gallery.views.modify_gallery'),

# Image operations
url(r'^image/ajouter/(?P<pk_gallery>\d+)/$', NewImage.as_view(),
name='gallery-image-new'),
url(r'^image/supprimer/$', DeleteImages.as_view(),
name='gallery-image-delete'),
url(r'^image/editer/(?P<pk_gallery>\d+)/(?P<pk>\d+)/$', EditImage.as_view(),
name='gallery-image-edit'),
url(r'^image/importer/(?P<pk_gallery>\d+)/$', ImportImages.as_view(),
name='gallery-image-import'),

# View a gallery
url(r'^(?P<pk>\d+)/(?P<slug>.+)/$', GalleryDetails.as_view(), name='gallery-details'),

# edit a gallery
url(r'^editer/(?P<pk>\d+)/(?P<slug>.+)/$', EditGallery.as_view(), name='gallery-edit'),

# Index
url(r'^$', ListGallery.as_view(), name='gallery-list'),
)
10 changes: 5 additions & 5 deletions zds/gallery/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ def modify_gallery(request):
return redirect(gallery.get_absolute_url())
if user.profile.is_private():
return redirect(gallery.get_absolute_url())
ug = UserGallery()
ug.user = user
ug.gallery = gallery
ug.mode = request.POST["mode"]
ug.save()
user_gal = UserGallery()
user_gal.user = user
user_gal.gallery = gallery
user_gal.mode = request.POST["mode"]
user_gal.save()
else:
return render(request, "gallery/gallery/details.html", {
"gallery": gallery,
Expand Down
2 changes: 1 addition & 1 deletion zds/member/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib import admin

from models import Profile, Ban, TokenRegister, TokenForgotPassword, KarmaNote
from zds.member.models import Profile, Ban, TokenRegister, TokenForgotPassword, KarmaNote


class ProfileAdmin(admin.ModelAdmin):
Expand Down
2 changes: 1 addition & 1 deletion zds/member/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
url(r'^(?P<pk>[0-9]+)/lecture-seule/$', MemberDetailReadingOnly.as_view(),
name='api-member-read-only'),
url(r'^(?P<pk>[0-9]+)/ban/$', MemberDetailBan.as_view(), name='api-member-ban'),
)
)
2 changes: 1 addition & 1 deletion zds/munin/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-:
from django.conf.urls import patterns, url

import views
from zds.munin import views

urlpatterns = patterns(
'',
Expand Down
8 changes: 4 additions & 4 deletions zds/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def home(request):
articles.append(data)

try:
with open(os.path.join(BASE_DIR, 'quotes.txt'), 'r') as fh:
quote = random.choice(fh.readlines())
with open(os.path.join(BASE_DIR, 'quotes.txt'), 'r') as quotes_file:
quote = random.choice(quotes_file.readlines())
except IOError:
quote = settings.ZDS_APP['site']['slogan']

Expand Down Expand Up @@ -150,10 +150,10 @@ def alerts(request):
if not request.user.has_perm('forum.change_post'):
raise PermissionDenied

alerts = Alert.objects.all().order_by('-pubdate')
all_alerts = Alert.objects.all().order_by('-pubdate')

return render(request, 'pages/alerts.html', {
'alerts': alerts,
'alerts': all_alerts,
})


Expand Down
10 changes: 5 additions & 5 deletions zds/utils/articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def export_article(article):

def get_blob(tree, chemin):

for bl in tree.blobs:
if os.path.abspath(bl.path) == os.path.abspath(chemin):
data = bl.data_stream.read()
for blob in tree.blobs:
if os.path.abspath(blob.path) == os.path.abspath(chemin):
data = blob.data_stream.read()
return data.decode('utf-8')
if len(tree.trees) > 0:
for tr in tree.trees:
result = get_blob(tr, chemin)
for a_tree in tree.trees:
result = get_blob(a_tree, chemin)
if result is not None:
return result
return None
Expand Down
4 changes: 2 additions & 2 deletions zds/utils/context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def get_git_version():
repo = Repo(settings.BASE_DIR)
branch = repo.active_branch
commit = repo.head.commit.hexsha
v = u'{0}/{1}'.format(branch, commit[:7])
return {'name': v, 'url': u'{}/tree/{}'.format(settings.ZDS_APP['site']['repository'], commit)}
version = u'{0}/{1}'.format(branch, commit[:7])
return {'name': version, 'url': u'{}/tree/{}'.format(settings.ZDS_APP['site']['repository'], commit)}
except (KeyError, TypeError):
return {'name': '', 'url': ''}

Expand Down
8 changes: 4 additions & 4 deletions zds/utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HelpWritingFactory(factory.DjangoModelFactory):

@classmethod
def _prepare(cls, create, **kwargs):
a = super(HelpWritingFactory, cls)._prepare(create, **kwargs)
the_help = super(HelpWritingFactory, cls)._prepare(create, **kwargs)
image_path = kwargs.pop('image_path', None)
fixture_image_path = kwargs.pop('fixture_image_path', None)

Expand All @@ -26,10 +26,10 @@ def _prepare(cls, create, **kwargs):

if image_path is not None:
copyfile(image_path, join(MEDIA_ROOT, basename(image_path)))
a.image = basename(image_path)
a.save()
the_help.image = basename(image_path)
the_help.save()

return a
return the_help

@classmethod
def _create(cls, target_class, *args, **kwargs):
Expand Down
3 changes: 3 additions & 0 deletions zds/utils/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, *args, **kwargs):
data_ajax_input='preview-message'),
HTML("</div>"),
HTML("</div>"),
*args, **kwargs
)


Expand All @@ -46,6 +47,7 @@ def __init__(self, *args, **kwargs):
css_class='btn-grey'),
),
),
*args, **kwargs
)


Expand All @@ -54,4 +56,5 @@ class CommonLayoutModalText(Layout):
def __init__(self, *args, **kwargs):
super(CommonLayoutModalText, self).__init__(
Field('text'),
*args, **kwargs
)
6 changes: 3 additions & 3 deletions zds/utils/management/commands/load_factory_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def handle(self, *args, **options):
for fixture in fixture_list:
splitted = str(fixture["factory"]).split(".")
module_part = ".".join(splitted[:-1])
m = __import__(module_part)
module = __import__(module_part)
for comp in splitted[1:-1]:
m = getattr(m, comp)
module = getattr(module, comp)

obj = getattr(m, splitted[-1])(**fixture["fields"])
obj = getattr(module, splitted[-1])(**fixture["fields"])
print(obj)
8 changes: 4 additions & 4 deletions zds/utils/management/commands/pdf_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def handle(self, *args, **options):
ids = []

for arg in args:
ps = arg.split("=")
if len(ps) < 2:
param = arg.split("=")
if len(param) < 2:
continue
else:
if ps[0] in ["id", "ids"]:
ids = ps[1].split(",")
if param[0] in ["id", "ids"]:
ids = param[1].split(",")

pandoc_debug_str = ""
if settings.PANDOC_LOG_STATE:
Expand Down
10 changes: 5 additions & 5 deletions zds/utils/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ def build_list_with_previous_item(self, queryset):
This function returns the list paginated with this previous item.
"""
original_list = queryset.all()
list = []
items_list = []
# If necessary, add the last item in the previous page.
if self.page.number != 1:
last_page = self.paginator.page(self.page.number - 1).object_list
last_item = (last_page)[len(last_page) - 1]
list.append(last_item)
items_list.append(last_item)
# Adds all items of the list paginated.
for item in original_list:
list.append(item)
return list
items_list.append(item)
return items_list


def paginator_range(current, stop, start=1):
assert (current <= stop)
assert(current <= stop)

# Basic case when no folding
if stop - start <= ZDS_APP['paginator']['folding_limit']:
Expand Down
52 changes: 26 additions & 26 deletions zds/utils/templatetags/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@


@register.filter('profile')
def profile(user):
def profile(the_user):
try:
profile = user.profile
the_profile = the_user.profile
except Profile.DoesNotExist:
profile = None
return profile
the_profile = None
return the_profile


@register.filter('user')
def user(pk):
def user(the_pk):
try:
user = User.objects.get(pk=pk)
except:
user = None
return user
the_user = User.objects.get(pk=the_pk)
except User.DoesNotExist:
the_user = None
return the_user


@register.filter('state')
def state(user):
def state(the_user):
try:
profile = user.profile
if not profile.user.is_active:
state = 'DOWN'
elif not profile.can_read_now():
state = 'BAN'
elif not profile.can_write_now():
state = 'LS'
elif user.has_perm('forum.change_post'):
state = 'STAFF'
the_profile = the_user.profile
if not the_profile.user.is_active:
the_state = 'DOWN'
elif not the_profile.can_read_now():
the_state = 'BAN'
elif not the_profile.can_write_now():
the_state = 'LS'
elif the_user.has_perm('forum.change_post'):
the_state = 'STAFF'
else:
state = None
the_state = None
except Profile.DoesNotExist:
state = None
return state
the_state = None
return the_state


@register.filter('liked')
def liked(user, comment_pk):
return CommentLike.objects.filter(comments__pk=comment_pk, user=user).exists()
def liked(the_user, comment_pk):
return CommentLike.objects.filter(comments__pk=comment_pk, user=the_user).exists()


@register.filter('disliked')
def disliked(user, comment_pk):
return CommentDislike.objects.filter(comments__pk=comment_pk, user=user).exists()
def disliked(the_user, comment_pk):
return CommentDislike.objects.filter(comments__pk=comment_pk, user=the_user).exists()
4 changes: 2 additions & 2 deletions zds/utils/templatetags/repo_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def diff_text(text1, text2="", title1="", title2=""):
txt1 = text1.splitlines(1)
txt2 = text2.splitlines(1)

d = HtmlDiff(tabsize=4, wrapcolumn=80)
result = d.make_file(txt1, txt2, title1, title2, context=True)
diff = HtmlDiff(tabsize=4, wrapcolumn=80)
result = diff.make_file(txt1, txt2, title1, title2, context=True)

return result

0 comments on commit 49cf001

Please sign in to comment.