def process_request(self, request): if not re.match( "/social/user/update/$", request.path) and not re.match( "/logout/$", request.path): if (request.user.is_authenticated and request.user.user_type == "JS" and request.user.registered_from == "Social" and not request.user.mobile): return redirect("/social/user/update/", permanent=False) if request.path == "/recruiter/": return redirect("/post-job/", permanent=False) detail_page = re.match( "^/(?P<job_title_slug>[a-z0-9-.,*?]+)-(?P<job_id>([0-9])+)/$", request.path) blog_page = re.match("^/blog/(?P<blog_slug>[-\w]+)/$", request.path) if not detail_page and not blog_page: redirect_data = cache.get("redirect_data") if not redirect_data: db = mongoconnection() redirect_data = list(db.redirect_data.find()) cache.set("redirect_data", redirect_data, 60 * 60 * 24) keys = [data["name"] for data in redirect_data] if any(match in request.path for match in keys): rep = {} for data in redirect_data: rep[data["name"]] = data["slug"] url = request.path rep = dict((re.escape(k), v) for k, v in rep.items()) pattern = re.compile("|".join(rep.keys())) url = pattern.sub(lambda m: rep[re.escape(m.group(0))], url) return redirect(url, permanent=True) if request.path == request.path.lower(): return None return redirect(request.path.lower(), permanent=True)
def get_unread_messages(message_to, message_from, job_id): db = mongoconnection() messages = db.messages.count({'message_to': message_to.id, 'is_read': False}) if message_from: messages = db.messages.count({'message_to': message_to.id, 'is_read': False, 'message_from': message_from.id, 'job_id': None}) if job_id: messages = db.messages.count({'message_to': message_to.id, 'is_read': False, 'message_from': message_from.id, 'job_id': job_id}) return messages
def get_unread_messages(message_to, message_from, job_id): db = mongoconnection() messages = db.messages.count({ "message_to": message_to.id, "is_read": False }) if message_from: messages = db.messages.count({ "message_to": message_to.id, "is_read": False, "message_from": message_from.id, "job_id": None, }) if job_id: messages = db.messages.count({ "message_to": message_to.id, "is_read": False, "message_from": message_from.id, "job_id": job_id, }) return messages
City, Skill, Language, Qualification, Industry, FunctionalArea, User, MailTemplate, Company, JobPost, Question, ) from mpcomp.views import mongoconnection from bson import ObjectId db = mongoconnection() def validation_name(self, model): form_cleaned_data = self.cleaned_data if model == "Country": if Country.objects.filter(name__iexact=form_cleaned_data["name"]).exclude( id=self.instance.id ): raise forms.ValidationError(model + " name Should be unique") if model == "State": if State.objects.filter(name__iexact=form_cleaned_data["name"]).exclude( id=self.instance.id ): raise forms.ValidationError(model + " name Should be unique")