class OtherInformationOfUsers(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) about = EditorMdField() cooggerup_confirmation = models.BooleanField( default=False, verbose_name= "Do you want to join in curation trails of the cooggerup bot with your account?" ) sponsor = models.BooleanField(default=False) cooggerup_percent = models.FloatField( default=0, verbose_name="Cooggerup bot upvote percent") vote_percent = models.FloatField(default=100) beneficiaries = models.IntegerField( default=0, verbose_name="Support Coogger ecosystem with beneficiaries") # reward db of coogger.up curation trail, reset per week total_votes = models.IntegerField(default=0, verbose_name="How many votes") total_vote_value = models.FloatField(default=0, verbose_name="total vote value") access_token = models.CharField(max_length=500, default="no_permission") @property def username(self): return self.user.username def save(self, *args, **kwargs): if self.access_token == "no_permission": self.access_token = self.get_new_access_token() super(OtherInformationOfUsers, self).save(*args, **kwargs) def get_new_access_token(self): "creates api_token and user save" sc_user = SteemConnectUser.objects.filter(user=self.user) if sc_user.exists(): return get_new_hash() return "no_permission"
class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) about = EditorMdField( help_text= "Write a long article about yourself, see; /u/@your_username/about/", verbose_name="About Yourself", blank=True, null=True, ) bio = models.CharField( help_text= "Write something short about yourself, this will appear in your profile.", max_length=260, blank=True, null=True, ) address = models.ManyToManyField(OtherAddressesOfUsers, blank=True) email_permission = models.BooleanField( help_text="Allow email notifications.", default=True) title = models.CharField( max_length=30, default="user", choices=make_choices(TITLES), verbose_name="title", help_text="Title", ) # company = TODO def __str__(self): return str(self.user)
class Category(models.Model): name = models.CharField(max_length=50) template = EditorMdField(blank=True, null=True) def save(self, *args, **kwargs): self.name = slugify(self.name) super(Category, self).save(*args, **kwargs) def __str__(self): return self.name
class Issue(AbstractThreadedComments, Common, View, Vote): user = models.ForeignKey(User, on_delete=models.CASCADE) permlink = models.SlugField(max_length=200) title = models.CharField( max_length=200, help_text="Be sure to choose the best title", null=True, blank=True, ) utopic = models.ForeignKey(UTopic, on_delete=models.CASCADE) body = EditorMdField( null=True, blank=True, help_text="Your problem | question | or anything else" ) status = models.CharField( default="open", choices=make_choices(ISSUE_CHOICES), max_length=55, help_text="Status", null=True, blank=True, ) issue_id = models.IntegerField(default=0) class Meta: ordering = ["-created"] unique_together = [["utopic", "permlink"]] def save(self, *args, **kwargs): self.permlink = slugify(self.title) super().save(*args, **kwargs) @property def get_absolute_url(self): return reverse( "detail-issue", kwargs=dict( username=str(self.utopic.user), utopic_permlink=self.utopic.permlink, permlink=self.permlink, ), ) @property def get_dor(self): # TODO this function same in content.py models times = "" for f, t in second_convert(dor(self.body)).items(): if t != 0: times += f" {t}{f} " if times == "": return "0" return times
class Commit(models.Model): # TODO hash can be a post tx_id hash = models.CharField(max_length=256, unique=True, default=get_new_hash) user = models.ForeignKey(User, on_delete=models.CASCADE) utopic = models.ForeignKey(UTopic, on_delete=models.CASCADE) content = models.ForeignKey(Content, on_delete=models.CASCADE) body = EditorMdField() msg = models.CharField(max_length=150, default="Initial commit") created = models.DateTimeField(default=now, verbose_name="Created") class Meta: ordering = ["-created"] def __str__(self): return f"<Commit(content='{self.content}', msg='{self.msg}')>"
class OtherInformationOfUsers(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) about = EditorMdField() cooggerup_confirmation = models.BooleanField( default=False, verbose_name= "Do you want to join in curation trails of the cooggerup bot with your account?" ) sponsor = models.BooleanField(default=False) cooggerup_percent = models.FloatField( default=0, verbose_name="Cooggerup bot upvote percent") vote_percent = models.FloatField(default=100) beneficiaries = models.FloatField( default=0, verbose_name="Support Coogger ecosystem with beneficiaries") # reward db of coogger.up curation trail, reset per week total_votes = models.IntegerField(default=0, verbose_name="How many votes") total_vote_value = models.FloatField(default=0, verbose_name="total vote value") @property def username(self): return self.user.username
class Commit(Common, View, Vote): hash = models.CharField(max_length=256, unique=True, default=get_new_hash) user = models.ForeignKey(User, on_delete=models.CASCADE) utopic = models.ForeignKey(UTopic, on_delete=models.CASCADE) content = models.ForeignKey(Content, on_delete=models.CASCADE) body = EditorMdField() msg = models.CharField(max_length=150, default="Initial commit") created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) reply_count = models.PositiveIntegerField(default=0) status = models.CharField(max_length=100, default="approved", choices=make_choices(COMMIT_STATUS_CHOICES)) previous_commit = models.ForeignKey("self", null=True, blank=True, on_delete=models.CASCADE) objects = CommitManager() class Meta: ordering = ["-created"] def __str__(self): return ( f"<Commit(user='******', content='{self.content}', msg='{self.msg}')>" ) @property def get_absolute_url(self): return reverse( "commit", kwargs=dict( username=str(self.user), topic_permlink=self.utopic.permlink, hash=self.hash, ), ) @property def title(self): return self.msg @property def get_previous_commit(self): # NOTE just find and get previous_commit queryset = self.__class__.objects.filter(utopic=self.utopic, content=self.content, status="approved") if self.status == "approved": # to commits page index = list(queryset).index(queryset.get(id=self.id)) try: return queryset[index + 1] except IndexError: return None elif self.status == "waiting": try: return queryset[0] except IndexError: return None @property def body_change(self): previous_body = self.previous_commit if previous_body == self.body or not previous_body: previous_body = "" else: previous_body = previous_body.body return HtmlDiff().make_file(previous_body.splitlines(), self.body.splitlines())
class Content(AbstractThreadedComments, Common, View, Vote): user = models.ForeignKey(User, on_delete=models.CASCADE) permlink = models.SlugField(max_length=200) title = models.CharField( max_length=200, help_text="Be sure to choose the best title", null=True, blank=True, ) body = EditorMdField( null=True, blank=True, verbose_name="", help_text="Your content | problem | question | or anything else", ) utopic = models.ForeignKey( UTopic, on_delete=models.CASCADE, verbose_name="Your topic", help_text="Please, write your topic about your contents.", ) language = models.CharField( max_length=30, choices=make_choices(LANGUAGES), help_text="The language of your content", ) category = models.ForeignKey(Category, on_delete=models.CASCADE, help_text="select content category") tags = models.CharField( max_length=200, verbose_name="Keywords", help_text="Write your tags using spaces, max:5", ) image_address = models.URLField(null=True, blank=True) status = models.CharField( default="ready", max_length=30, choices=make_choices(STATUS_CHOICES), verbose_name="article's status", help_text= "if your article isn't ready to publish yet, select 'not ready to publish'.", ) contributors = models.ManyToManyField(User, blank=True, related_name="content_contributors") contributors_count = models.PositiveIntegerField( default=0, verbose_name="Total contributors count") class Meta: ordering = ["-created"] unique_together = [["user", "permlink"]] def __str__(self): return str(self.get_absolute_url) @property def get_absolute_url(self): return reverse( "content-detail", kwargs=dict(username=str(self.user), permlink=self.permlink), ) @property def is_exists(self): return self.__class__.objects.filter(user=self.user, permlink=self.permlink).exists() def generate_permlink(self): self.permlink = slugify(self.title) obj, redirect_is_exists = check_redirect_exists( old_path=self.get_absolute_url) if self.is_exists or redirect_is_exists: import random return self.permlink + str(random.randrange(99999999)) else: return self.permlink @property def get_dor(self): times = "" for f, t in second_convert(dor(self.body)).items(): if t != 0: times += f" {t}{f} " if times == "": return "0" return times def next_or_previous(self, next=True): queryset = self.__class__.objects.filter(user=self.user, utopic=self.utopic) index = list(queryset).index(queryset.get(id=self.id)) if next: try: return queryset[index - 1] except (IndexError, AssertionError): return None else: try: return queryset[index + 1] except (IndexError): return None @property def next_post(self): try: return self.next_or_previous().get_absolute_url except AttributeError: return False @property def previous_post(self): try: return self.next_or_previous(next=False).get_absolute_url except AttributeError: return False @property def other_content_of_this_topic(self): "left of content detail page section" return self.__class__.objects.filter( user=self.user, utopic=self.utopic).order_by("created") def save(self, *args, **kwargs): # always update self.image_address = get_first_image(self.body) self.tags = ready_tags(self.tags) self.last_update = timezone.now() super().save(*args, **kwargs) @property def description(self): renderer = mistune.Renderer(escape=False, parse_block_html=True) markdown = mistune.Markdown(renderer=renderer) return (BeautifulSoup(markdown(self.body), "html.parser").text[0:200].replace("\n", " ")) @property def get_last_commit(self): return self.commit_set.first() @property def get_contributors(self): return self.contributors.all()
class Commit(Common, View, Vote): hash = models.CharField(max_length=256, unique=True, default=get_new_hash) user = models.ForeignKey(User, on_delete=models.CASCADE) utopic = models.ForeignKey(UTopic, on_delete=models.CASCADE) # is it necessary content = models.ForeignKey(Content, on_delete=models.CASCADE) body = EditorMdField() msg = models.CharField(max_length=150, default="Initial commit") created = models.DateTimeField(auto_now_add=True, verbose_name="Created") reply_count = models.PositiveIntegerField(default=0) class Meta: ordering = ["-created"] def __str__(self): return f"<Commit(content='{self.content}', msg='{self.msg}')>" @property def get_absolute_url(self): return reverse( "commit", kwargs=dict( username=str(self.user), topic_permlink=self.utopic.permlink, hash=self.hash, ), ) @property def title(self): return self.msg @property def previous_commit(self): filter_field = dict(user=self.user, utopic=self.utopic, content=self.content) n_or_p = NextOrPrevious(self.__class__, filter_field, self.id) return n_or_p.previous_query @property def body_change(self): previous_commit = self.previous_commit if not previous_commit: return self.body HtmlDiff._file_template = ( """<style type="text/css">%(styles)s</style>%(table)s""" ) HtmlDiff._table_template = """ <table class="diff"> <tbody>%(data_rows)s</tbody> </table> """ HtmlDiff._styles = """ table.diff {font-family:Courier; border:medium;} .diff_header {color:#99a3a4} td.diff_header {text-align:center} .diff tbody{display: block;} .diff_next {background-color:#c0c0c0;display:none} .diff_add {background-color:#aaffaa} .diff_chg {background-color:#ffff77} .diff_sub {background-color:#ffaaaa} .diff [nowrap]{word-break: break-word;white-space: normal;width: 50%;} """ return HtmlDiff().make_file( previous_commit.body.splitlines(), self.body.splitlines() )
class Content(AbstractThreadedComments, Common, View, Vote): user = models.ForeignKey(User, on_delete=models.CASCADE) permlink = models.SlugField(max_length=200) title = models.CharField( max_length=200, help_text="Be sure to choose the best title", null=True, blank=True, ) body = EditorMdField( null=True, blank=True, verbose_name="", help_text="Your content | problem | question | or anything else", ) utopic = models.ForeignKey( UTopic, on_delete=models.CASCADE, verbose_name="Your topic", help_text="Please, write your topic about your contents.", ) language = models.CharField( max_length=30, choices=make_choices(LANGUAGES), help_text="The language of your content", ) category = models.ForeignKey(Category, on_delete=models.CASCADE, help_text="select content category") tags = models.CharField( max_length=200, verbose_name="Keywords", help_text="Write your tags using spaces, max:5", ) image_address = models.URLField(null=True, blank=True) status = models.CharField( default="ready", max_length=30, choices=make_choices(STATUS_CHOICES), verbose_name="article's status", help_text= "if your article isn't ready to publish yet, select 'not ready to publish'.", ) class Meta: ordering = ["-created"] unique_together = [["user", "permlink"]] def __str__(self): return str(self.get_absolute_url) @property def get_absolute_url(self): return reverse( "content-detail", kwargs=dict(username=str(self.user), permlink=self.permlink), ) @property def get_dor(self): times = "" for f, t in second_convert(dor(self.body)).items(): if t != 0: times += f" {t}{f} " if times == "": return "0" return times def next_or_previous(self, next=True): filter_field = dict(user=self.user, utopic=self.utopic) n_or_p = NextOrPrevious(self.__class__, filter_field, self.id) if next: return n_or_p.next_query return n_or_p.previous_query @property def next_post(self): try: return self.next_or_previous().get_absolute_url except AttributeError: return False @property def previous_post(self): try: return self.next_or_previous(next=False).get_absolute_url except AttributeError: return False @property def other_content_of_this_topic(self): "left of content detail page section" return self.__class__.objects.filter( user=self.user, utopic=self.utopic).order_by("created") def save(self, *args, **kwargs): self.image_address = get_first_image(self.body) self.permlink = slugify(self.title) super().save(*args, **kwargs) @property def description(self): renderer = mistune.Renderer(escape=False, parse_block_html=True) markdown = mistune.Markdown(renderer=renderer) return (BeautifulSoup(markdown(self.body), "html.parser").text[0:200].replace("\n", " ")) @property def get_last_commit(self): return self.commit_set.first()
class Content(models.Model): community = models.ForeignKey(Community, on_delete=models.CASCADE) user = models.ForeignKey("auth.user", on_delete=models.CASCADE) title = models.CharField( max_length=100, verbose_name="Title", help_text="Be sure to choose the best title related to your content.") permlink = models.SlugField(max_length=200) content = EditorMdField() tag = models.CharField(max_length=200, verbose_name="keyword", help_text="Write your tags using spaces, max:4") language = models.CharField(max_length=30, choices=make_choices(languages), help_text=" The language of your content") category = models.CharField(max_length=30, choices=make_choices(all_categories), help_text="select content category") definition = models.CharField( max_length=400, verbose_name="definition of content", help_text="Briefly tell your readers about your content.") topic = models.CharField( max_length=30, verbose_name="content topic", help_text="Please, write your topic about your contents.") status = models.CharField(default="shared", max_length=30, choices=make_choices(status_choices), verbose_name="content's status") time = models.DateTimeField(default=timezone.now, verbose_name="date") dor = models.CharField(default=0, max_length=10) views = models.IntegerField(default=0, verbose_name="views") read = models.IntegerField(default=0, verbose_name="pageviews") lastmod = models.DateTimeField(default=timezone.now, verbose_name="last modified date") mod = models.ForeignKey("auth.user", on_delete=models.CASCADE, blank=True, null=True, related_name="moderator") cooggerup = models.BooleanField(default=False, verbose_name="was voting done") class Meta: ordering = ['-time'] @property def username(self): return self.user.username @property def modusername(self): return self.mod.username @property def community_name(self): return self.community.name @staticmethod def prepare_definition(text): renderer = mistune.Renderer(escape=False, parse_block_html=True) markdown = mistune.Markdown(renderer=renderer) soup = BeautifulSoup(markdown(text), "html.parser") img = soup.find("img") if img is None: return "<p>{}</p>".format(soup.text[0:200] + "...") src = img.get("src") try: alt = img.get("alt") except: alt = "" return "<img class='definition-img' src='{}' alt='{}'></img><p>{}</p>".format( src, alt, soup.text[0:200] + "...") def get_absolute_url(self): return "@" + self.user.username + "/" + self.permlink @staticmethod def durationofread(text): reading_speed = 20 # 1 saniyede 20 harf okunursa read_content = BeautifulSoup(text, 'html.parser').get_text().replace( " ", "") how_much_words = len(read_content) words_time = float((how_much_words / reading_speed) / 60) return str(words_time)[:3] def save(self, *args, **kwargs): # for admin.py self.definition = self.prepare_definition(self.content) super(Content, self).save(*args, **kwargs) def content_save(self, request, *args, **kwargs): # for me self.community = request.community_model self.tag = self.ready_tags() self.dor = self.durationofread(self.content + self.title) self.permlink = slugify(self.title.lower()) self.definition = self.prepare_definition(self.content) while True: # hem coogger'da hemde sistem'de olmaması gerek ki kayıt sırasında sorun çıkmasın. try: # TODO: buralarda sorun var aynı adres steemit de yokken coogger'da vardı ve döngüden çıkamadı. Content.objects.filter( user=self.user, permlink=self.permlink)[0] # db de varsa try: Post(post=self.get_absolute_url()).url # sistem'de varsa self.new_permlink( ) # change to self.permlink / link değişir except: pass except: try: Post(post=self.get_absolute_url()).url # sistem'de varsa self.new_permlink( ) # change to self.permlink / link değişir except: break steem_save = self.steemconnect_post(self.permlink, "save") if steem_save.status_code == 200: super(Content, self).save(*args, **kwargs) return steem_save def content_update(self, queryset, content): self.community = queryset[0].community self.user = queryset[0].user self.title = content.title self.tag = self.ready_tags(limit=5) self.topic = content.topic self.dor = self.durationofread(self.content + self.title) steem_post = self.steemconnect_post(queryset[0].permlink, "update") if steem_post.status_code == 200: queryset.update( definition=self.prepare_definition(content.content), topic=self.topic, title=self.title, content=self.content, category=content.category, language=content.language, tag=self.tag, status="changed", dor=self.dor, lastmod=timezone.now(), ) return steem_post def steemconnect_post(self, permlink, json_metadata): def_name = json_metadata if json_metadata == "save": self.content += "\n" + self.community.ms.format( self.get_absolute_url()) json_metadata = { "format": "markdown", "tags": self.tag.split(), "app": "coogger/1.3.9", "ecosystem": "coogger", "community": self.community.name, "topic": self.topic, "category": self.category, "language": self.language, "dor": self.dor, } comment = Comment( parent_permlink=self.community.name, author=str(self.user.username), permlink=permlink, title=self.title, body=self.content, json_metadata=json_metadata, ) if def_name == "save": beneficiaries_weight = OtherInformationOfUsers.objects.filter( user=self.user)[0].beneficiaries beneficiaries_weight = round(float(beneficiaries_weight), 3) if beneficiaries_weight >= 15: ben_weight = beneficiaries_weight * 100 - 1000 if self.community.name == "coogger": beneficiaries = [ { "account": "hakancelik", "weight": ben_weight + 1000 }, ] else: beneficiaries = [{ "account": "hakancelik", "weight": ben_weight + 500 }, { "account": self.community.name, "weight": 500 }] comment_options = CommentOptions(comment_class=comment, beneficiaries=beneficiaries) operation = comment_options.operation elif beneficiaries_weight < 15 and beneficiaries_weight > 0: ben_weight = beneficiaries_weight * 100 / 3 if self.community.name == "coogger": beneficiaries = [ { "account": "hakancelik", "weight": 3 * ben_weight }, ] else: beneficiaries = [{ "account": "hakancelik", "weight": 2 * ben_weight }, { "account": self.community.name, "weight": ben_weight }] comment_options = CommentOptions(comment_class=comment, beneficiaries=beneficiaries) operation = comment_options.operation else: operation = comment.operation else: operation = comment.operation steem_connect_user = SteemConnectUser.objects.filter(user=self.user) try: access_token = steem_connect_user[0].access_token return SteemConnect(token=access_token, data=operation).run except: sc_community_name = steem_connect_user[0].community_name secret = Community.objects.filter( name=sc_community_name)[0].app_secret access_token = steem_connect_user.set_new_access_token(secret) return SteemConnect(token=access_token, data=operation).run def ready_tags(self, limit=5): def clearly_tags(get_tag): clearly_tags = [] tags = "" for i in get_tag: if i not in clearly_tags: clearly_tags.append(i) for i in clearly_tags: if i == clearly_tags[-1]: tags += slugify(i.lower()) else: tags += slugify(i.lower()) + " " return tags get_tag = self.tag.split(" ")[:limit] get_tag.insert(0, self.community.name) return clearly_tags(get_tag) def new_permlink(self): rand = str(random.randrange(9999)) self.permlink += "-" + rand
class EditorTemplate(models.Model): category_name = models.CharField(max_length=100, unique=True, verbose_name="Category name") template = EditorMdField()
class Content(models.Model): user = models.ForeignKey("auth.user", on_delete=models.CASCADE) permlink = models.SlugField(max_length=200) title = models.CharField( max_length=200, verbose_name="Title", help_text="Be sure to choose the best title related to your content.") body = EditorMdField() topic = models.ForeignKey( Topic, on_delete=models.CASCADE, verbose_name="Your topic", help_text="Please, write your topic about your contents.") language = models.CharField(max_length=30, choices=make_choices(languages), help_text="The language of your content") category = models.ForeignKey(Category, on_delete=models.CASCADE, help_text="select content category") tags = models.CharField(max_length=200, verbose_name="Keywords", help_text="Write your tags using spaces, max:4") definition = models.CharField( max_length=400, verbose_name="Definition of content", ) status = models.CharField(default="approved", max_length=30, choices=make_choices(status_choices), verbose_name="content's status") views = models.IntegerField(default=0, verbose_name="Views") mod = models.ForeignKey("auth.user", on_delete=models.CASCADE, blank=True, null=True, related_name="moderator") cooggerup = models.BooleanField(default=False, verbose_name="Was voting done") created = models.DateTimeField(default=now, verbose_name="Created") last_update = models.DateTimeField(default=now, verbose_name="Last update") class Meta: ordering = ["-created"] def __str__(self): return f"@{self.user}/{self.permlink}" @property def username(self): return self.user.username @property def modusername(self): return self.mod.username @property def category_name(self): return self.category.name @property def topic_name(self): return self.topic.name @property def utopic(self): return UTopic.objects.filter(user=self.user, name=self.topic)[0] @property def dor(self): "duration of read" return round(float((self.body.__len__() / 28) / 60), 3) @property def get_absolute_url(self): return f"/@{self.user.username}/{self.permlink}" @property def next_post(self): obj = Content.objects.filter(user=self.user, topic=self.topic) content_id = obj.filter(permlink=self.permlink)[0].id index = 0 for i, content in zip(range(len(obj)), obj): if content.id == content_id: index = i break try: return obj[index - 1].get_absolute_url except (IndexError, AssertionError): return False @property def previous_post(self): obj = Content.objects.filter(user=self.user, topic=self.topic) content_id = obj.filter(permlink=self.permlink)[0].id index = 0 for i, content in zip(range(len(obj)), obj): if content.id == content_id: index = i break try: return obj[index + 1].get_absolute_url except IndexError: return False def marktohtml(self, marktext): renderer = Renderer(escape=False, parse_block_html=True) markdown = Markdown(renderer=renderer) return BeautifulSoup(markdown(marktext), "html.parser") def get_first_image(self, soup): context = dict(alt=False, src=False) img = soup.find("img") if img is None: return context context["src"] = img.get("src", None) context["alt"] = img.get("alt", None) return context def prepare_definition(self, text): soup = self.marktohtml(marktext=text) first_image = self.get_first_image(soup=soup) if first_image.get("src") is None: return f"<p>{soup.text[0:200]}...</p>" return f"<img class='definition-img' src='{first_image.get('src')}' alt='{first_image.get('alt')}'></img><p>{soup.text[:200]}...</p>" def save(self, *args, **kwargs): # for admin.py self.definition = self.prepare_definition(self.body) super(Content, self).save(*args, **kwargs) def content_save(self, request, *args, **kwargs): self.user = request.user self.topic = Topic.objects.filter(name=request.GET.get("topic"))[0] self.tags = self.ready_tags() self.permlink = slugify(self.title.lower( )) # TODO if permlink is not exists on steem share . self.definition = self.prepare_definition(self.body) steem_save = self.steemconnect_post(op_name="save") if steem_save.status_code == 200: super(Content, self).save(*args, **kwargs) utopic = UTopic.objects.filter(user=self.user, name=self.topic)[0] get_msg = request.POST.get("msg") if get_msg == "Initial commit": get_msg = f"{self.title} Published." Commit(user=self.user, utopic=utopic, content=self, body=self.body, msg=get_msg).save() return steem_save def content_update(self, request, old, new): self.user = old[0].user get_topic_name = request.GET.get("topic", None) if get_topic_name is None: get_topic_name = old[0].topic self.topic = Topic.objects.filter(name=get_topic_name)[0] self.body = new.body self.permlink = old[0].permlink self.title = new.title self.category = new.category self.language = new.language self.tags = self.ready_tags() commit_context = dict() if self.topic != old[0].topic: commit_context["from_topic"] = old[0].topic commit_context["to_topic"] = self.topic if self.title != old[0].title: commit_context["from_title"] = old[0].title commit_context["to_title"] = self.title if self.category != old[0].category: commit_context["from_category"] = old[0].category commit_context["to_category"] = self.category if self.language != old[0].language: commit_context["from_language"] = old[0].language commit_context["to_language"] = self.language if self.tags != old[0].tags: commit_context["from_tags"] = old[0].tags commit_context["to_tags"] = self.tags if self.body != old[0].body: commit_context["body"] = self.body # TODO old[0].body - self.body steem_post = self.steemconnect_post(op_name="update") if steem_post.status_code == 200: old.update( body=self.body, topic=self.topic, definition=self.prepare_definition(new.body), title=self.title, category=self.category, language=self.language, tags=self.tags, ) if commit_context != dict(): Commit( # tx_id = steem_post["result"]["id"], # ="1b99579041b558af27334c1db22ad51923d47ce2" # DOTO user=self.user, utopic=self.utopic, content=Content.objects.get(user=self.user, permlink=self.permlink), body=render_to_string("post/commit.html", commit_context), msg=request.POST.get("msg"), ).save() return steem_post def steemconnect_post(self, op_name): context = dict( image=self.get_first_image(soup=self.marktohtml(self.body)), username=self.username, permlink=self.permlink, ) comment = Comment( parent_author="", parent_permlink="coogger", author=str(self.user.username), permlink=self.permlink, title=self.title, body=render_to_string("post/steem-post-note.html", context), json_metadata=dict(format="markdown", tags=self.tags.split(), app="coogger/1.4.1", ecosystem=dict( version="1.4.1", body=self.body, )), ) if op_name == "save": if self.get_user_beneficiaries != []: comment_options = CommentOptions( parent_comment=comment, beneficiaries=self.get_user_beneficiaries) operation = comment_options.operation else: operation = comment.operation elif op_name == "update": operation = comment.operation steem_connect_user = SteemConnectUser.objects.filter(user=self.user) try: access_token = steem_connect_user[0].access_token return SteemConnect(token=access_token, data=operation).run except: access_token = steem_connect_user.update_access_token( settings.APP_SECRET) return SteemConnect(token=access_token, data=operation).run @property def get_user_beneficiaries(self): beneficiaries = [] user_benefic = OtherInformationOfUsers.objects.filter( user=self.user)[0].beneficiaries if user_benefic != 0: beneficiaries.append( dict(account="coogger", weight=user_benefic * 100)) return beneficiaries def ready_tags(self, limit=5): def clearly_tags(get_tag): clearly_tags = [] tags = "" for i in get_tag: if i not in clearly_tags: clearly_tags.append(i) for i in clearly_tags: if i == clearly_tags[-1]: tags += slugify(i.lower()) else: tags += slugify(i.lower()) + " " return tags get_tag = self.tags.split(" ")[:limit] get_tag.insert(0, "coogger") return clearly_tags(get_tag)