diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-07-18 06:04:15 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-07-18 06:04:15 -0400 |
commit | a72cbd27c8d1c75bccbf56d4b706a2069336fd0a (patch) | |
tree | 0c075a637c96a612b830ed1546b18bd92d55e75f | |
parent | 30ab686096a13f720b9229995bfe32cadce256c8 (diff) | |
download | askbot-a72cbd27c8d1c75bccbf56d4b706a2069336fd0a.tar.gz askbot-a72cbd27c8d1c75bccbf56d4b706a2069336fd0a.tar.bz2 askbot-a72cbd27c8d1c75bccbf56d4b706a2069336fd0a.zip |
allow posting question to specific group via the group page
-rw-r--r-- | askbot/forms.py | 1 | ||||
-rw-r--r-- | askbot/models/__init__.py | 2 | ||||
-rw-r--r-- | askbot/models/post.py | 19 | ||||
-rw-r--r-- | askbot/models/question.py | 24 | ||||
-rw-r--r-- | askbot/skins/default/templates/widgets/ask_button.html | 2 | ||||
-rw-r--r-- | askbot/skins/default/templates/widgets/ask_form.html | 1 | ||||
-rw-r--r-- | askbot/views/writers.py | 13 |
7 files changed, 48 insertions, 14 deletions
diff --git a/askbot/forms.py b/askbot/forms.py index ea3fd5cd..cc11da23 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -687,6 +687,7 @@ class AskForm(PostPrivatelyForm): text = QuestionEditorField() tags = TagNamesField() wiki = WikiField() + group_id = forms.IntegerField(required = False, widget = forms.HiddenInput) ask_anonymously = forms.BooleanField( label = _('ask anonymously'), help_text = _( diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 78aa26c1..ef980a37 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1471,6 +1471,7 @@ def user_post_question( wiki = False, is_anonymous = False, is_private = False, + group_id = None, timestamp = None, by_email = False, email_address = None @@ -1501,6 +1502,7 @@ def user_post_question( wiki = wiki, is_anonymous = is_anonymous, is_private = is_private, + group_id = group_id, by_email = by_email, email_address = email_address ) diff --git a/askbot/models/post.py b/askbot/models/post.py index 21723128..5b3d6ba4 100644 --- a/askbot/models/post.py +++ b/askbot/models/post.py @@ -479,6 +479,7 @@ class Post(models.Model): created = self.pk is None is_private = kwargs.pop('is_private', False) + group_id = kwargs.pop('group_id', None) #this save must precede saving the mention activity #as well as assigning groups to the post @@ -486,8 +487,8 @@ class Post(models.Model): super(self.__class__, self).save(**kwargs) if author.can_make_group_private_posts(): - if is_private: - self.make_private(author) + if is_private or group_id: + self.make_private(author, group_id = group_id) else: self.make_public(author) @@ -536,12 +537,18 @@ class Post(models.Model): def is_reject_reason(self): return self.post_type == 'reject_reason' - def make_private(self, user): + def make_private(self, user, group_id = None): """makes post private within user's groups""" groups = user.get_groups() - self.groups.add(*groups) - if self.is_question(): - self.thread.groups.add(*groups) + if group_id: + for group in groups: + if group.id == group_id: + groups = [group] + break + if groups: + self.groups.add(*groups) + if self.is_question(): + self.thread.groups.add(*groups) def make_public(self, user): """removes the privacy mark from users groups""" diff --git a/askbot/models/question.py b/askbot/models/question.py index acbfffe0..3c4c7fe8 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -90,6 +90,7 @@ class ThreadManager(BaseQuerySetManager): tagnames = None, is_anonymous = False, is_private = False, + group_id = None, by_email = False, email_address = None ): @@ -140,8 +141,8 @@ class ThreadManager(BaseQuerySetManager): email_address = email_address ) - if is_private:#add groups to thread and question - thread.make_private(author) + if is_private or group_id:#add groups to thread and question + thread.make_private(author, group_id = group_id) # INFO: Question has to be saved before update_tags() is called thread.update_tags(tagnames = tagnames, user = author, timestamp = added_at) @@ -784,10 +785,23 @@ class Thread(models.Model): return self.followed_by.filter(id = user.id).count() > 0 return False - def make_private(self, user): + def make_private(self, user, group_id = None): groups = list(user.get_groups()) - self.groups.add(*groups) - self._question_post().groups.add(*groups) + group_found = False + if group_id: + for group in groups: + if group.id == group_id: + groups = [group] + break + if groups: + self.groups.add(*groups) + self._question_post().groups.add(*groups) + else: + message = _( + 'Posted your question publicly because you ' + 'do not belong to the requested group' + ) + user.message_set.create(message = message) def is_private(self): return askbot_settings.GROUPS_ENABLED and self.groups.count() > 0 diff --git a/askbot/skins/default/templates/widgets/ask_button.html b/askbot/skins/default/templates/widgets/ask_button.html index a27f3b2c..f74b13df 100644 --- a/askbot/skins/default/templates/widgets/ask_button.html +++ b/askbot/skins/default/templates/widgets/ask_button.html @@ -4,6 +4,6 @@ {% endif %} <a id="askButton" - href="{{ search_state.full_ask_url() }}{% if group %}&group={{ group.id }}{% endif %}" + href="{{ search_state.full_ask_url() }}{% if group %}{% if '?' in search_state.full_ask_url() %}&{% else %}?{% endif %}group_id={{ group.id }}{% endif %}" >{% trans %}Ask Your Question{% endtrans %}</a> {% endif %} diff --git a/askbot/skins/default/templates/widgets/ask_form.html b/askbot/skins/default/templates/widgets/ask_form.html index 86f10782..38613a3c 100644 --- a/askbot/skins/default/templates/widgets/ask_form.html +++ b/askbot/skins/default/templates/widgets/ask_form.html @@ -31,6 +31,7 @@ editor_type = settings.EDITOR_TYPE ) }} + {{ form.group_id }} <div class="question-options"> {% if settings.WIKI_ON %} {{ macros.checkbox_in_div(form.wiki) }} diff --git a/askbot/views/writers.py b/askbot/views/writers.py index 2dee9c37..2791557e 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -219,6 +219,7 @@ def ask(request):#view used to ask a new question text = form.cleaned_data['text'] ask_anonymously = form.cleaned_data['ask_anonymously'] post_privately = form.cleaned_data['post_privately'] + group_id = form.cleaned_data.get('group_id', None) if request.user.is_authenticated(): try: @@ -229,7 +230,8 @@ def ask(request):#view used to ask a new question wiki = wiki, is_anonymous = ask_anonymously, is_private = post_privately, - timestamp = timestamp + timestamp = timestamp, + group_id = group_id ) return HttpResponseRedirect(question.get_absolute_url()) except exceptions.PermissionDenied, e: @@ -256,6 +258,7 @@ def ask(request):#view used to ask a new question if request.method == 'GET': form = forms.AskForm() + form.initial = { 'title': request.REQUEST.get('title', ''), 'text': request.REQUEST.get('text', ''), @@ -264,7 +267,13 @@ def ask(request):#view used to ask a new question 'ask_anonymously': request.REQUEST.get('ask_anonymousy', False), 'post_privately': request.REQUEST.get('post_privately', False) } - + if 'group_id' in request.REQUEST: + try: + group_id = int(request.GET.get('group_id', None)) + form.initial['group_id'] = group_id + except Exeption: + pass + data = { 'active_tab': 'ask', 'page_class': 'ask-page', |