Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #159 #225

Merged
merged 11 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ NGINX_CONF_LOCATION='/config/nginx/site-confs/default.conf' # leave unset for de
SECRET_KEY='secret'
DATABASE_PASSWORD='secret'
DATABASE_ROOT_PASSWORD="secret"
VAPID_PUBLIC_KEY="public-key"
VAPID_PRIVATE_KEY="private-key"
POST_OFFICE_EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend"
# if POST_OFFICE_EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend', set the following
EMAIL_USE_TLS='True'
Expand Down
63 changes: 0 additions & 63 deletions .github/workflows/django.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .github/workflows/image-builds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker images build
name: Docker images build and test
on:
push:
pull_request:
Expand All @@ -12,3 +12,7 @@ jobs:
- uses: actions/checkout@v4
- run: ./.github/scripts/prepare-ci.sh
- run: docker compose build
- run: docker compose up -d
- run: sleep 60 # Wait for the container to be up
- run: docker compose exec web python3 manage.py test
- run: docker compose down
58 changes: 52 additions & 6 deletions auctions/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Invoice,
Lot,
LotHistory,
User,
UserBan,
UserData,
UserInterestCategory,
Expand Down Expand Up @@ -191,12 +192,7 @@ def bid_on_lot(lot, user, amount):
auctiontos_winner = AuctionTOS.objects.filter(auction=lot.auction, user=user).first()
if auctiontos_winner:
lot.auctiontos_winner = auctiontos_winner
invoice, created = Invoice.objects.get_or_create(
auctiontos_user=lot.auctiontos_winner,
auction=lot.auction,
defaults={},
)
invoice.recalculate
lot.create_update_invoices
lot.winning_price = lot.buy_now_price
lot.buy_now_used = True
# this next line makes the lot end immediately after buy now is used
Expand Down Expand Up @@ -526,3 +522,53 @@ def error_message(self, event):
# Receive message from room group
def chat_message(self, event):
self.send(text_data=json.dumps(event))


class UserConsumer(WebsocketConsumer):
"""This is ready to use and corresponding code to connect added (commented out) to base.html
You can use userdata.send_websocket_message to message the user, like this:
result = {
"type": "toast",
"message": "Hello world!",
}
user.userdata.send_websocket_message(result)
It would make a good messaging system for some stuff like chat messages,
but at this time it does not seem like a good idea
"""

def connect(self):
try:
self.pk = self.scope["url_route"]["kwargs"]["user_pk"]
user_for = User.objects.filter(pk=self.pk).first()
self.user = self.scope["user"]
self.user_notification_channel = f"user_{self.pk}"
if not user_for or user_for != self.user:
self.close()
else:
self.accept()
# Add to the group after accepting the connection
async_to_sync(self.channel_layer.group_add)(self.user_notification_channel, self.channel_name)

# Send a message after accepting the connection
# async_to_sync(self.channel_layer.group_send)(
# self.user_notification_channel,
# {"type": "toast", "message": 'Welcome!', 'bg': 'success'},
# )
except Exception as e:
print(e)
self.close()

def disconnect(self, close_code):
# Leave room group
async_to_sync(self.channel_layer.group_discard)(self.user_notification_channel, self.channel_name)
print("disconnected")

# Receive message from WebSocket
def receive(self, text_data):
text_data_json = json.loads(text_data)
print(text_data_json)

def toast(self, event):
message = event["message"]
bg = event.get("bg", "info")
self.send(text_data=json.dumps({"type": "toast", "message": message, "bg": bg}))
16 changes: 14 additions & 2 deletions auctions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ class Meta:
"date_online_bidding_starts",
"allow_deleting_bids",
"auto_add_images",
"message_users_when_lots_sell",
]
widgets = {
"date_start": DateTimePickerInput(),
Expand Down Expand Up @@ -1581,6 +1582,8 @@ def __init__(self, *args, **kwargs):
].help_text = "This should be 1-24 hours before the end of your auction"
self.fields["allow_bidding_on_lots"].help_text = "Leave this checked or people won't be able to bid!"
self.fields["allow_bidding_on_lots"].widget = forms.HiddenInput()
self.fields["message_users_when_lots_sell"].widget = forms.HiddenInput()
self.fields["advanced_lot_adding"].widget = forms.HiddenInput()
# self.fields['pre_register_lot_entry_fee_discount'].widget=forms.HiddenInput()
self.fields["pre_register_lot_discount_percent"].widget = forms.HiddenInput()
# self.fields['set_lot_winners_url'].widget=forms.HiddenInput()
Expand Down Expand Up @@ -1777,17 +1780,21 @@ def __init__(self, *args, **kwargs):
"buy_now",
css_class="col-md-3",
),
# Div('set_lot_winners_url', css_class='col-md-3',),
Div(
"promote_this_auction",
"message_users_when_lots_sell",
css_class="col-md-3",
),
# Div('set_lot_winners_url', css_class='col-md-3',),
PrependedAppendedText(
"tax",
"",
"%",
wrapper_class="col-md-3",
),
Div(
"promote_this_auction",
css_class="col-md-3",
),
css_class="row",
),
Submit("submit", "Save", css_class="create-update-auction btn-success"),
Expand Down Expand Up @@ -2473,6 +2480,7 @@ class Meta:
"username_visible",
"share_lot_images",
"auto_add_images",
"push_notifications_when_lots_sell",
)

def __init__(self, user, *args, **kwargs):
Expand Down Expand Up @@ -2510,6 +2518,10 @@ def __init__(self, user, *args, **kwargs):
# Div('use_list_view',css_class='col-md-4',),
# Div('use_dark_theme',css_class='col-md-4',),
# Div('show_ads',css_class='col-md-3',),
Div(
"push_notifications_when_lots_sell",
css_class="col-md-6",
),
css_class="row",
),
HTML("<h4>Notifications</h4><br>"),
Expand Down
Loading
Loading