From 0c0e63f54529e5b38801f516f1feceeef4183d8f Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Thu, 31 Jan 2019 20:01:24 +0300 Subject: [PATCH] fix chat photo download --- aggregator/forms.py | 18 ++++++++---------- aggregator/views.py | 3 +++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/aggregator/forms.py b/aggregator/forms.py index 159145c..c8d4aee 100644 --- a/aggregator/forms.py +++ b/aggregator/forms.py @@ -17,16 +17,14 @@ class AggregationSourceForm(ModelForm): cleaned_data = super(AggregationSourceForm, self).clean() invite_link = cleaned_data.pop('invite_link') if invite_link: - app = get_client() - app.start() - try: - upd = app.join_chat(invite_link) - except ChannelPrivate: - raise ValidationError('I was banned in this chat') - app.stop() - chat = parse_mtproto_chat(app, upd.chats[0]) - cleaned_data['chat_id'] = chat.id - Chat.from_obj(chat, app) + with get_client() as app: + try: + upd = app.join_chat(invite_link) + except ChannelPrivate: + raise ValidationError('I was banned in this chat') + chat = parse_mtproto_chat(app, upd.chats[0]) + cleaned_data['chat_id'] = chat.id + Chat.from_obj(chat, app) return cleaned_data class Meta: diff --git a/aggregator/views.py b/aggregator/views.py index 6f89b71..1259492 100644 --- a/aggregator/views.py +++ b/aggregator/views.py @@ -58,3 +58,6 @@ class AggregationSourceDeleteView(LoginRequiredMixin, SingleObjectMixin, View): messages.success(self.request, 'Source "{}" was successfully deleted'.format(source.title)) source.delete() return redirect('cabinet:aggregator:index') + + +