def run(): from forum.models import Category forum_category_1 = Category() forum_category_1.name = u'Radio' forum_category_1.sort_order = 0 forum_category_1.save() from forum.models import Forum forum_forum_1 = Forum() forum_forum_1.title = u'Radio forum' forum_forum_1.slug = u'radio-forum' forum_forum_1.parent = None forum_forum_1.description = u'Stuff about the radio.' forum_forum_1.threads = 0 forum_forum_1.posts = 0 forum_forum_1.category = forum_category_1 forum_forum_1.anonymous = False forum_forum_1.sort_order = 0 forum_forum_1.save() from forum.models import Thread from forum.models import Post from forum.models import Subscription from forum.models import LastRead
def mkcategory(title="Test Category"): """Helper function for making categories.""" c = Category() c.title_plain, c.title_html = title, title c.save() return c
def mkcategory(title="Test Category"): """Helper function for making categories.""" c = Category() c.title_plain, c.title_html = title, title c.save() return c
def import_categories(self): print "* Importing categories" rows = self._query("select * from smf_categories") for row in rows: category = Category( id=row['ID_CAT'], name=row['name'], order=row['catOrder']) disable_auto_now(category) category.save()
def add(request): """Add a new category.""" title_plain = False if request.method == 'POST': # Form has been submitted title_plain = request.POST['title'] title_html = prettify_title(title_plain) if len(title_plain) > MAX_CATEGORY_TITLE_LENGTH: messages.error(request, long_title_error % MAX_CATEGORY_TITLE_LENGTH) else: c = Category(title_plain=title_plain, title_html=title_html) c.save() return HttpResponseRedirect("/") return render(request, 'add.html', {'full_url' : request.build_absolute_uri(), 'current_site': Site.objects.get_current(), 'title' : title_plain})
def new_category(request): if request.method == 'POST': form = CategoryForm(request.POST) if form.is_valid(): categoryName = form.cleaned_data['category'] category = Category(name=categoryName, slug='') utilities.unique_slugify(category, categoryName) category.save() return HttpResponseRedirect(reverse('index')) else: form = CategoryForm() context = {'form': form} return render(request, 'new/new_category.html', context)
def save(self, *args, **kwargs): try: Topic.objects.filter(id=self.forum_id.id).update( title=self.title, description=self.description) except: topic = Topic.objects.create(title=self.title, description=self.description, created_by=self.author, category=Category(pk=3)) self.forum_id = Topic(pk=topic.id) super().save(*args, **kwargs)
def main(): print('Login: '******'', flush=True) login = stdin.readline() password = getpass('Password: '******'Fetching categroies') response = session.get(FORUM_BASE_URL, params=FORUM_BASE_PARAMS) json_string = '\n'.join(response.text.split('\n')[1:]) categories_data = json.loads(json_string) for category_data in categories_data['node']['children']: # Parent categories try: category = Category.objects.get(title=category_data['name']) except Category.DoesNotExist: category = Category(title=category_data['name']) category.save() # print(category_data['name']) print('Fetching subcategory') response = session.get(FORUM_SUB_CAT_URL, params=FORUM_SUB_CAT_PARAMS(category_data['path'])) json_string = '\n'.join(response.text.split('\n')[1:]) sub_cat_data = json.loads(json_string) leech_category(session, category, category_data) for sub_cat in sub_cat_data[category_data['path']]: # Sub categories try: sub_category = Category.objects.get(title=sub_cat['name'], sub_category=category) except Category.DoesNotExist: sub_category = Category(title=sub_cat['name'], sub_category=category) sub_category.save() # print('\t', sub_cat['name']) leech_category(session, sub_category, sub_cat)
def on_module_post_save(sender, **kwargs): """Automatically creates: - a forum category for a new module - a forum subcategory for a new activity """ if sender is Module: try: Category.objects.get(title=kwargs['instance'].name) except Category.DoesNotExist: forum_categroy = Category(title=kwargs['instance'].name) forum_categroy.save() elif sender is Activity and kwargs['instance'].type == Activity.PROJECT: module_name = kwargs['instance'].module.name try : module_category = Category.objects.get(title=module_name) except Category.DoesNotExist: return try: Category.objects.get(title=kwargs['instance'].name) except Category.DoesNotExist: forum_categroy = Category( title=kwargs['instance'].name, sub_category=module_category ) forum_categroy.save()