|
To my mind that regex would be okay. It's the thousands of characters, wall-of-text abominations that I object to. I know, that's an example of poor use of regex, but it's the kind of thing you find. Inexperienced folks start using it, and all of a sudden it becomes their favorite toy.
A toy that's all sharp edges...
Software Zen: delete this;
|
|
|
|
|
I won't argue with that.
Real programmers use butterflies
|
|
|
|
|
I feel like if I were in charge of development practices at a given shop and regex were used as documentation as i suggested strict limits would be placed on its use
For starters [^-]().+*?| is all you get. That keeps it simple, portable, and non-backtracking. You can easily generate flow diagrams from it.
And it keeps people from getting ... "creative"
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: it keeps people from getting ... "creative" KISS: Keep It Stupid, Stupid.
Software Zen: delete this;
|
|
|
|
|
we use regex expressions in production code all the time. almost always validation.
phone numbers, emails, web addresses, and other pattern specialized validation.
never had any issues.
performance has never been an issue and accuracy has never been an issue. most of the uses require zero maintenance after implementation.
|
|
|
|
|
I like it.
Compared to indexOf, substr etc. it prevents me from dealing with IndexOutOfBound exceptions. I use it often for validation or parsing.
I also use it for configuration: Providing a single text field containing a regex, e.g. for selecting files to process, it gives a lot of flexibility at runtime (yes, it requires some knowledge by the administrator, but it can solve a lot of (unforeseen) requirements without changing the application).
However, you shouldn't solve *every* problem using regex.
|
|
|
|
|
I make what could be regarded as "heroic effort" to avoid using regex whenever possible. However, I used it in a recent application because it was the most expedient way to do what I needed.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Expedience is how it gets you. Next thing you know, you're hooked.
Real programmers use butterflies
|
|
|
|
|
I’ve resisted being hooked on its expedience since it’s inception. The way I see it, I will be able to easily make it to retirement (three years) without getting hooked on it.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I don't know that I'll live long enough to retire from coding, though i may retire from doing it professionally. I've always loved it. I suspect I always will.
Real programmers use butterflies
|
|
|
|
|
"Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." - Jamie Zawinski
|
|
|
|
|
They're not that bad, Sander. Where's your sense of adventure?
Real programmers use butterflies
|
|
|
|
|
It can be quite intimidating at first. I found that Regex 101[^] is a great tool for learning to use regex, and I still use it to validate my regex for projects that I am working on.
Regards,
Thomas Stockwell
|
|
|
|
|
not afraid, but when you only need to make some regex once a year or less, It generally takes a bit to remember the all rules correctly to get the desired results. long regex's can be very cryptic, so I generally tend to break it down with lots of notes about each section for the future me that might have to modify it.
|
|
|
|
|
So i have a project called star social project this project is similar to a socail media that you can post and create group but this project you can only post when you are in a group. So i get an error message that is not familiar to me which is on the title, i tried to search on google and get some result but when i implement it to my project it does not work. So why im getting this error is because i'm trying to create a comment section and when i click the add comment that's when i get the error message. So i'm here to ask someone to help me because i'm not really familiar on this error and i'm just learning django for about 2 months now.
models.py
##########################
## POSTS MODELS.PY FILE ##
##########################
from django.contrib.auth import get_user_model
from django.db import models
from groups.models import Group
from misaka import html
from django.urls import reverse
from django.utils import timezone
User = get_user_model()
class Post(models.Model):
user = models.ForeignKey(User, related_name='posts', on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now=True)
message = models.TextField()
message_html = models.TextField(editable=False)
group = models.ForeignKey(Group, related_name='posts', null=True, blank=True, on_delete=models.CASCADE)
def __str__(self):
return self.message
def save(self, *args, **kwargs):
self.message_html = html(self.message)
super().save(*args, **kwargs)
def get_absolute_url(self):
return reverse(
'posts:single',
kwargs={
'username': self.user.username,
'pk': self.pk
}
)
class Meta:
ordering = ['-created_at']
class Comment(models.Model):
post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE)
username = models.CharField(max_length=50)
text = models.TextField()
created = models.DateTimeField(auto_now_add=True)
approved = models.BooleanField(default=False)
def __str__(self):
return self.text
def approved(self):
self.approved = True
self.save()
views.py
class AddComment(LoginRequiredMixin, generic.CreateView):
model = Comment
fields = ('username', 'text')
def form_valid(self, form):
post = get_object_or_404(Post, pk=self.kwargs.get('pk'))
self.object = form.save(commit=False)
self.object.post = post
self.object.save()
return super().form_valid(form)
urls.py
########################
## POSTS URLS.PY FILE ##
########################
from django.urls import path
from posts import views
app_name = 'posts'
urlpatterns = [
path('', views.PostList.as_view(), name='all'),
path('by/<username>/', views.UserPost.as_view(), name='for_user'),
path('by/<username>/<int:pk>/', views.PostDetail.as_view(), name='single'),
path('new/', views.CreatePost.as_view(), name='create'),
path('delete/<int:pk>/', views.DeletePost.as_view(), name='delete'),
path('post/comment/', views.AddComment.as_view(), name='add_comment'),
]
comment_form.html
{% extends 'posts/post_base.html' %}
{% load bootstrap4 %}
{% block prepost %}
<h4>Add New Comment</h4>
<form id="commentForm" action="{% url 'posts:add_comment' %}" method="POST">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-large btn-primary">Add Comment</button>
{% endbuttons %}
</form>
{% endblock %}
_post.html
<div class="media">
<h3 class="mr-5"><a href="{% url 'posts:for_user' username=post.user.username %}">@{{ post.user.username }}</a></h3>
<div class="media-body">
{{ post.user.username }}
<h5>{{ post.message_html|safe }}
<time class="time"><a href="{% url 'posts:single' username=post.user.username pk=post.pk %}">{{ post.created_at }}</a></time>
{% if post.group %}
in <a href="#">{{ post.group.name }}</a>
{% endif %}
</h5>
<hr>
{% if user.is_authenticated %}
<a class="btn btn-primary btn-comment" href="{% url 'posts:add_comment' %}">Add Comment</a>
{% endif %}
<div class="container">
{% for comment in comment_list %}
<br>
{{ comment.created }}
<p>{{ comment.text|safe|linebreaks }}</p>
<p>Posted By: {{ comment.username }}</p>
{% endfor %}
</div>
<div class="media-footer">
{% if user.is_authenticated and post.user == user and not hide_delete %}
<a class="btn btn-simple" href="{% url 'posts:delete' pk=post.pk %}" title="delete">Delete</a>
{% endif %}
</div>
</div>
</div>
|
|
|
|
|
Read the red text in the upper-right corner of the page.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Wrong place to post this, try here: Ask a Question[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
A for Asymptomatic
B for Blood Test
C for Corona
D for Dispensing
E for Epidemic
F for Flattening the Curve
G for "Go Corona Go"
H for Handwash
I for Incubation Period
J for Jobless
K for Kit (Immunity Kit)
L for Lockdown
M for Mask
N for Negative Report
O for Online
P for Pandemic
Q for Quarantine
R for Respirator
S for Sanitizer
T for Tracing
U for Unlock
V for Vaccine
W for Work From Home
X for ?
Y for Yellow Zone
Z for Zoom Call
(Again from WhatsApp)
modified 2-Jan-21 21:25pm.
|
|
|
|
|
Amarnath S wrote: X for ?
"X for "XXXXing virus!"
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
X for xenophobia - fear of the unknown, which we've all been experiencing to some degree or other
|
|
|
|
|
A certain site beginning with x and ending in videos for when you are bored perhaps?
|
|
|
|
|
X is for X-ray to look at the damage in yer lungs.
|
|
|
|
|
1920 x 1080
Last year was 800 x 640
|
|
|
|
|
I've upgraded my resolution from 40 columns to 80 columns.
|
|
|
|
|
I went from 1920 x 1200 to 7680 x 2160.
It might get to 11520 x 2160 by the end of the year, IF nVidia ever makes enough RTX3000 cards to fill demand.
|
|
|
|