mirror of
https://github.com/ae-utbm/sith.git
synced 2026-07-31 10:45:10 +00:00
bump ruff to 0.16
This commit is contained in:
@@ -61,9 +61,8 @@ Un fichier de migration ressemble à ça :
|
||||
```python
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
# liste des autres migrations à appliquer avant celle-ci
|
||||
]
|
||||
@@ -117,14 +116,16 @@ Par exemple :
|
||||
```python
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def forwards_func(apps, schema_editor):
|
||||
print("Appplication de la migration")
|
||||
|
||||
|
||||
def reverse_func(apps, schema_editor):
|
||||
print("Annulation de la migration")
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
@@ -164,6 +165,7 @@ On écrirait donc, dans l'application `pedagogy` :
|
||||
from django.db import models
|
||||
from core.models import User
|
||||
|
||||
|
||||
class UserUe(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
ue = models.CharField(max_length=10)
|
||||
@@ -174,6 +176,7 @@ Et nous aurions le fichier de migration suivant :
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
@@ -289,6 +292,7 @@ La commande vous donnera ceci :
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
replaces = [("pedagogy", "0004_userue"), ("pedagogy", "0005_alter_userue_ue")]
|
||||
|
||||
|
||||
@@ -191,7 +191,6 @@ for user in richest.annotate(amount=F("customer__amount"))[:100]:
|
||||
|
||||
On aurait même pu réorganiser ça :
|
||||
```python
|
||||
|
||||
from core.models import User
|
||||
from django.db.models import F
|
||||
|
||||
@@ -239,10 +238,7 @@ nous écrivons donc instinctivement :
|
||||
from counter.models import Counter
|
||||
|
||||
foyer = Counter.objects.get(name="Foyer")
|
||||
total_amount = sum(
|
||||
sale.amount * sale.unit_price
|
||||
for sale in foyer.sellings.all()
|
||||
)
|
||||
total_amount = sum(sale.amount * sale.unit_price for sale in foyer.sellings.all())
|
||||
```
|
||||
|
||||
On pourrait penser qu'il n'y a pas de problème.
|
||||
|
||||
@@ -27,12 +27,11 @@ SITH_SUBSCRIPTIONS = {
|
||||
"cursus-alternant": {"name": _("Alternating cursus"), "price": 30, "duration": 6},
|
||||
"membre-honoraire": {"name": _("Honorary member"), "price": 0, "duration": 666},
|
||||
"un-jour": {"name": _("One day"), "price": 0, "duration": 0.00555333},
|
||||
|
||||
# On rajoute ici notre cotisation
|
||||
# Elle se nomme "Un mois"
|
||||
# Coûte 6€
|
||||
# Dure 1 mois (on raisonne en semestre, ici, c'est 1/6 de semestre)
|
||||
"un-mois": {"name": _("One month"), "price": 6, "duration": 0.166}
|
||||
"un-mois": {"name": _("One month"), "price": 6, "duration": 0.166},
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ Si le mot est dans le code Python :
|
||||
```python
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
help_text=_("Hello")
|
||||
help_text = _("Hello")
|
||||
```
|
||||
|
||||
Si le mot apparaît dans le template Jinja :
|
||||
|
||||
@@ -26,6 +26,7 @@ from django.templatetags.static import static
|
||||
|
||||
# Sélectionnez le fichier de bannière pour le weekmail de l'automne 2018
|
||||
|
||||
|
||||
def get_banner(self):
|
||||
return "http://" + settings.SITH_URL + static("com/img/weekmail_bannerA18.jpg")
|
||||
```
|
||||
|
||||
@@ -147,14 +147,15 @@ Voici quelques exemples :
|
||||
env = Env()
|
||||
env.read_env()
|
||||
|
||||
|
||||
async def main():
|
||||
async with aiohttp.ClientSession(
|
||||
base_url="https://ae.utbm.fr/api/",
|
||||
headers={"X-APIKey": env.str("API_KEY")}
|
||||
base_url="https://ae.utbm.fr/api/", headers={"X-APIKey": env.str("API_KEY")}
|
||||
) as session:
|
||||
async with session.get("club/1") as res:
|
||||
print(await res.json())
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
```
|
||||
|
||||
|
||||
@@ -161,8 +161,8 @@ qui seront alors injectés.
|
||||
```python
|
||||
from django.views.generic import CreateView, UpdateView, TemplateView
|
||||
from core.views.mixins import FragmentMixin
|
||||
|
||||
|
||||
|
||||
|
||||
class FooCreateFragment(FragmentMixin, CreateView):
|
||||
model = Foo
|
||||
fields = ["foo", "bar"]
|
||||
@@ -182,7 +182,7 @@ qui seront alors injectés.
|
||||
def get_context_data(**kwargs):
|
||||
return super().get_context_data(**kwargs) | {
|
||||
"create_fragment": FooCreateFragment.as_fragment()(),
|
||||
"update_fragment": FooUpdateFragment.as_fragment()(foo_id=1)
|
||||
"update_fragment": FooUpdateFragment.as_fragment()(foo_id=1),
|
||||
}
|
||||
```
|
||||
|
||||
@@ -288,7 +288,7 @@ class FooCreateFragment(FragmentMixin, CreateView):
|
||||
|
||||
def render_fragment(self, request, **kwargs):
|
||||
if "foo" in kwargs:
|
||||
kwargs["foo"] += 2
|
||||
kwargs["foo"] += 2
|
||||
return super().render_fragment(request, **kwargs)
|
||||
```
|
||||
|
||||
@@ -319,11 +319,9 @@ from core.views.mixins import UseFragmentsMixin
|
||||
class FooCompositeFormView(UseFragmentsMixin, TemplateView):
|
||||
fragments = {
|
||||
"create_fragment": FooCreateFragment,
|
||||
"update_fragment": FooUpdateFragment
|
||||
}
|
||||
fragment_data = {
|
||||
"update_fragment": {"foo": 4}
|
||||
"update_fragment": FooUpdateFragment,
|
||||
}
|
||||
fragment_data = {"update_fragment": {"foo": 4}}
|
||||
template_name = "app/foo.jinja"
|
||||
```
|
||||
|
||||
@@ -342,9 +340,7 @@ from core.views.mixins import UseFragmentsMixin
|
||||
|
||||
|
||||
class FooCompositeFormView(UseFragmentsMixin, TemplateView):
|
||||
fragments = {
|
||||
"create_fragment": FooCreateFragment
|
||||
}
|
||||
fragments = {"create_fragment": FooCreateFragment}
|
||||
template_name = "app/foo.jinja"
|
||||
|
||||
def get_fragment_context_data(self):
|
||||
|
||||
+14
-12
@@ -123,6 +123,7 @@ Par exemple, prenons le modèle suivant :
|
||||
```python
|
||||
from django.db import models
|
||||
|
||||
|
||||
class News(models.Model):
|
||||
# ...
|
||||
|
||||
@@ -192,20 +193,21 @@ Pour les vues sous forme de fonction, il y a le décorateur
|
||||
|
||||
```python
|
||||
from com.models import News
|
||||
|
||||
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.views import View
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
|
||||
|
||||
|
||||
class NewsModerateView(PermissionRequiredMixin, SingleObjectMixin, View):
|
||||
model = News
|
||||
pk_url_kwarg = "news_id"
|
||||
permission_required = "com.moderate_news"
|
||||
# On peut aussi fournir plusieurs permissions, par exemple :
|
||||
# permission_required = ["com.moderate_news", "com.delete_news"]
|
||||
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
# Si nous sommes ici, nous pouvons être certains que l'utilisateur
|
||||
# a la permission requise
|
||||
@@ -219,12 +221,13 @@ Pour les vues sous forme de fonction, il y a le décorateur
|
||||
|
||||
```python
|
||||
from com.models import News
|
||||
|
||||
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
|
||||
|
||||
@permission_required("com.moderate_news")
|
||||
@require_POST
|
||||
def moderate_news(request, news_id: int):
|
||||
@@ -263,6 +266,7 @@ from core.auth.mixins import PermissionOrAuthorRequiredMixin
|
||||
|
||||
from django.views.generic import UpdateView
|
||||
|
||||
|
||||
class NewsUpdateView(PermissionOrAuthorRequiredMixin, UpdateView):
|
||||
model = News
|
||||
pk_url_kwarg = "news_id"
|
||||
@@ -324,8 +328,8 @@ Voici un exemple d'implémentation de ce système :
|
||||
|
||||
from core.models import User, Group
|
||||
|
||||
class Article(models.Model):
|
||||
|
||||
class Article(models.Model):
|
||||
title = models.CharField(_("title"), max_length=100)
|
||||
content = models.TextField(_("content"))
|
||||
|
||||
@@ -370,6 +374,7 @@ Voici un exemple d'implémentation de ce système :
|
||||
|
||||
from core.models import User, Group
|
||||
|
||||
|
||||
class Article(models.Model):
|
||||
title = models.CharField(_("title"), max_length=100)
|
||||
content = models.TextField(_("content"))
|
||||
@@ -378,7 +383,7 @@ Voici un exemple d'implémentation de ce système :
|
||||
owner_group = models.ForeignKey( # (1)!
|
||||
Group, related_name="owned_articles", default=settings.SITH_GROUP_ROOT_ID
|
||||
)
|
||||
|
||||
|
||||
# relation many-to-many
|
||||
edit_groups = models.ManyToManyField( # (2)!
|
||||
Group,
|
||||
@@ -386,7 +391,7 @@ Voici un exemple d'implémentation de ce système :
|
||||
verbose_name=_("edit groups"),
|
||||
blank=True,
|
||||
)
|
||||
|
||||
|
||||
# relation many-to-many
|
||||
view_groups = models.ManyToManyField( # (3)!
|
||||
Group,
|
||||
@@ -529,10 +534,7 @@ class NewsQuerySet(models.QuerySet): # (1)!
|
||||
return self
|
||||
# sinon, on retourne les nouvelles modérées ou dont l'utilisateur
|
||||
# est l'auteur
|
||||
return self.filter(
|
||||
models.Q(is_moderated=True)
|
||||
| models.Q(author=user)
|
||||
)
|
||||
return self.filter(models.Q(is_moderated=True) | models.Q(author=user))
|
||||
|
||||
|
||||
class News(models.Model):
|
||||
|
||||
Reference in New Issue
Block a user